CN113467896A - Cluster service current limiting method and device, computing equipment and storage medium - Google Patents

Cluster service current limiting method and device, computing equipment and storage medium Download PDF

Info

Publication number
CN113467896A
CN113467896A CN202110857201.3A CN202110857201A CN113467896A CN 113467896 A CN113467896 A CN 113467896A CN 202110857201 A CN202110857201 A CN 202110857201A CN 113467896 A CN113467896 A CN 113467896A
Authority
CN
China
Prior art keywords
address
lua script
current
limiting
timestamp
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110857201.3A
Other languages
Chinese (zh)
Inventor
马金燚
唐凯
蒋力
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Mobile Communications Group Co Ltd
MIGU Digital Media Co Ltd
MIGU Culture Technology Co Ltd
Original Assignee
China Mobile Communications Group Co Ltd
MIGU Digital Media Co Ltd
MIGU Culture Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China Mobile Communications Group Co Ltd, MIGU Digital Media Co Ltd, MIGU Culture Technology Co Ltd filed Critical China Mobile Communications Group Co Ltd
Priority to CN202110857201.3A priority Critical patent/CN113467896A/en
Publication of CN113467896A publication Critical patent/CN113467896A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2255Hash tables
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24552Database cache management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44568Immediately runnable code
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5083Techniques for rebalancing the load in a distributed system

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Computational Linguistics (AREA)
  • Memory System Of A Hierarchy Structure (AREA)

Abstract

The invention discloses a current limiting method, a current limiting device, computing equipment and a storage medium of cluster service, wherein an IP address corresponding to a user request and a timestamp corresponding to the initiation moment of the user request are obtained; inquiring the maximum access amount corresponding to the preset IP address; reading the Lua script, and setting parameters of the Lua script according to the IP address, the timestamp and the maximum access amount; and executing the Lua script, and performing current limiting processing on the IP address according to an execution result. The invention sets and executes the Lua script in the Redis database, so that the operation and calculation are carried out in the Lua script, and based on the stronger atomicity of the Lua script and the single-thread characteristic of the Redis database, the concurrent operation under multiple threads is avoided, the serial execution of the user request is ensured, the distributed lock in the prior art is not needed, and the waste of time and resources is avoided.

Description

Cluster service current limiting method and device, computing equipment and storage medium
Technical Field
The invention relates to the technical field of communication, in particular to a current limiting method and device of a cluster service, a computing device and a storage medium.
Background
The cluster service is highly concurrent aiming at IP flow limitation, in a cluster deployment environment, under the condition of highly concurrent requests, the request times within a certain time are limited aiming at different IPs, the server pressure is prevented from being overlarge, a database is prevented from being crashed, and the normal operation of the service is ensured at the cost of losing a part of requests.
The prior art central current limiting algorithm includes: a counter algorithm, a leaky bucket algorithm, a token bucket algorithm, and the like; the counter algorithm is generally used for recording the time and the number of requests of each IP request in a cache frame such as Redis, and the principle is to record a request timestamp and a counter, namely within a certain time, the counter +1 is used for judging whether the maximum (Max) access amount is exceeded or not when each request is made, if the maximum (Max) access amount is exceeded, the request is rejected, and if the maximum (Max) access amount is not exceeded, the service is entered, and the request continues.
However, the above solution in the prior art usually has a data error problem in a cluster high concurrency environment, for example, if multiple threads enter an interface at the same time and read the number of requests in Redis at the same time, the number of the read counters of the multiple threads is consistent, then it is determined whether the number of requests exceeds the maximum access amount, if none of the read counters exceeds the maximum access amount, the values of the counters in the Redis database are updated, but the last executed update thread overrides the execution result of the previous update thread. In order to solve the above problems, in the prior art, only a single thread enters operation under a high concurrency condition controlled by a distributed lock, that is, the distributed lock is acquired before entering a request interface, the request interface performs request judgment if the distributed lock can be acquired, and waiting is performed if the distributed lock cannot be acquired, but the distributed lock consumes time and resources, and once a certain lock cannot be released in time, deadlock is caused, and a great influence is further caused on a service.
Disclosure of Invention
In view of the above, the present invention is proposed to provide a method, an apparatus, a computing device and a storage medium for limiting current of a cluster service that overcome or at least partially solve the above problems.
According to an aspect of the present invention, there is provided a method for limiting a current of a cluster service, including:
acquiring an IP address corresponding to a user request and a timestamp corresponding to the user request initiating moment;
inquiring the preset maximum access amount corresponding to the IP address;
reading a Lua script, and setting parameters of the Lua script according to the IP address, the timestamp and the maximum access amount;
and executing the Lua script, and performing current limiting processing on the IP address according to an execution result.
According to another aspect of the present invention, there is provided a current limiting apparatus for a cluster service, including:
the information query module is used for acquiring an IP address corresponding to a user request and a timestamp corresponding to the user request initiating moment; inquiring the preset maximum access amount corresponding to the IP address;
the parameter setting module is used for reading a Lua script and setting the parameters of the Lua script according to the IP address, the timestamp and the maximum access amount;
and the execution module is used for executing the Lua script and carrying out current limiting processing on the IP address according to an execution result.
According to yet another aspect of the present invention, there is provided a computing device comprising: the system comprises a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface complete mutual communication through the communication bus;
the memory is used for storing at least one executable instruction, and the executable instruction enables the processor to execute the operation corresponding to the current limiting method of the cluster service.
According to still another aspect of the present invention, there is provided a computer storage medium having at least one executable instruction stored therein, the executable instruction causing a processor to perform operations corresponding to the above-mentioned current limiting method for a cluster service.
According to the current limiting method, the current limiting device, the computing equipment and the storage medium of the cluster service, an IP address corresponding to a user request and a timestamp corresponding to the initiation moment of the user request are obtained; inquiring the maximum access amount corresponding to the preset IP address; reading the Lua script, and setting parameters of the Lua script according to the IP address, the timestamp and the maximum access amount; and executing the Lua script, and performing current limiting processing on the IP address according to an execution result. The invention sets and executes the Lua script in the Redis database, so that the operation and calculation are carried out in the Lua script, and based on the stronger atomicity of the Lua script and the single-thread characteristic of the Redis database, the concurrent operation under multiple threads is avoided, the serial execution of the user request is ensured, the distributed lock in the prior art is not needed, and the waste of time and resources is avoided.
The foregoing description is only an overview of the technical solutions of the present invention, and the embodiments of the present invention are described below in order to make the technical means of the present invention more clearly understood and to make the above and other objects, features, and advantages of the present invention more clearly understandable.
Drawings
Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiments. The drawings are only for purposes of illustrating the preferred embodiments and are not to be construed as limiting the invention. Also, like reference numerals are used to refer to like parts throughout the drawings. In the drawings:
fig. 1 is a flowchart illustrating a method for limiting a current of a cluster service according to an embodiment of the present invention;
fig. 2 is a schematic diagram illustrating an implementation process of a current limiting method for a cluster service according to an embodiment of the present invention;
fig. 3 is a schematic structural diagram illustrating a current limiting apparatus for a cluster service according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of a computing device provided in an embodiment of the present invention.
Detailed Description
Exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the invention are shown in the drawings, it should be understood that the invention can be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the invention to those skilled in the art.
Fig. 1 shows a flowchart of an embodiment of a current limiting method for cluster services according to the present invention, and as shown in fig. 1, the method includes the following steps:
step S110: and acquiring an IP address corresponding to the user request and a timestamp corresponding to the user request initiating moment.
In an optional manner, step S110 further includes: in a cluster node of a cluster server, extracting an IP address corresponding to a user request from a request header of the user request; and acquiring a time stamp corresponding to the initiation moment of the user request through a system function.
Fig. 2 is a schematic diagram of an implementation process of a current limiting method for a cluster service provided in this embodiment, as shown in fig. 2, in this step, a cluster server is configured with a plurality of cluster nodes (cluster nodes 1-6), when a user sends a plurality of requests through http, the plurality of user requests enter a load balancing server, for example, a nginx server, the load balancing server forwards and distributes the plurality of user requests to the plurality of cluster nodes of the cluster server, extracts an IP address corresponding to the user request from a request header of the user request, and may obtain a timestamp [ argv1] corresponding to an initiation time of the user request through a System function provided by the System, where the timestamp is a millisecond-level timestamp.
In this embodiment, the number of requests for the IP address in a unit time may be recorded and managed by using the current-limiting cache data, where the IP address corresponding to the user request is used as the data key [ key1] of the current-limiting cache data, and the data value (value) of the current-limiting cache data is the hash request data.
Step S120: and inquiring the maximum access amount corresponding to the preset IP address.
In an optional manner, step S120 further includes: inquiring the maximum access amount corresponding to the preset IP address from the cache preferentially; and if the maximum access amount corresponding to the IP address is not inquired from the cache, inquiring the maximum access amount corresponding to the IP address from the database, and storing the inquired maximum access amount into the cache for the next inquiry from the cache. In this embodiment, the database may be a Redis database.
In this step, the maximum access amount [ argv2] in a unit time when the IP address preset for the IP address is taken as an accessed object is queried in a cache or a Redis database according to the IP address corresponding to the user request acquired in step S110, where a person skilled in the art may set the unit time according to actual needs, and the unit time may be one second or the like.
Because the user request is under the high concurrency condition, in order to reduce the IO operation of the database, the maximum access amount can be preferentially obtained from the cache, if the maximum access amount is not obtained from the cache, the maximum access amount [ argv2] in unit time preset by the IP address user is inquired from the database, and the maximum access amount [ argv2] is put into the cache for being inquired from the cache next time; in order to further reduce the pressure of the database, the cache invalidation time can be set to be one minute and the like, when the numerical value of the maximum access amount in unit time preset by a certain user is found to be too large or too small, the user can be timely notified to modify or automatically modify the maximum access amount in unit time in the database for adjustment, and the maximum access amount in unit time after modification is inquired from the database as the latest data after cache invalidation.
Step S130: reading the Lua script, and setting the parameters of the Lua script according to the IP address, the timestamp and the maximum access amount.
In this step, the specific content "Luas" in the Lua script is read by obtaining the absolute path of the Lua script file, parameters of the Lua script are set according to the user IP address [ key1], the timestamp [ argv1] corresponding to the user request initiation time and the maximum access amount [ argv2] in the unit time obtained in the above steps S110 and S120, and the user IP address [ key1], the timestamp [ argv1] corresponding to the user request initiation time and the maximum access amount [ argv2] in the unit time are respectively added to the key set and the argvs set in the entry parameter set (List set) of the Lua script.
It should be noted that, in order to further reduce database IO operations, the Lua script file may be saved in a cache, and for the cache expiration time of the Lua script file, a person skilled in the art may set the cache expiration time according to actual needs, for example, the cache expiration time of the Lua script file may be set to 24 hours.
Step S140: and executing the Lua script, and performing current limiting processing on the IP address according to an execution result.
In this step, the Jedis client of the Redis database executes the Lua script through the eval function, the Lua script has a small volume and a high running speed, and each execution is executed as an atomic transaction, in this embodiment, the Lua script is embedded into the eval function to be executed, so as to implement the function of rejecting or passing the access request corresponding to the IP address, and the execution process is as follows: the method comprises the steps that the scenario content Luas, the key set and the argvs set of the Lua script are respectively used as three parameters of the eval function to set and execute the eval function, the Lua script can sequentially acquire the parameters through the step S110 and the step S120, the Lua script is executed as a Redis command through the eval function, and the atomic operation of the Lua script is guaranteed based on the single-thread characteristic of the Redis database. As shown in fig. 2, each cluster node executes a Lua script through an eval function, that is, the Lua script is read _ Lua1, read _ Lua2, read _ Lua3, read _ Lua4, read _ Lua5, read _ Lua6, and the like in the graph, further, the Lua script is taken as a Redis command and is placed into a cache, and the cache of the Redis database executes the Lua scripts in sequence according to the sequence.
In an optional manner, step S140 further includes: inquiring whether the database has current-limiting cache data using the IP address in the parameter of the Lua script as a data key; if the current-limiting cache data with the IP address as the data key does not exist, setting the number of requests in unit time to be 1, constructing the current-limiting cache data by using the IP address, the timestamp in the parameter of the Lua script and the number of requests in unit time, storing the current-limiting cache data into a database, returning a response of successful execution, and processing according to a user request; if the current-limiting cache data with the IP address as the data key exists, judging whether the time interval between the timestamp in the current-limiting cache data and the timestamp in the parameter of the Lua script is greater than unit time or not; if the time interval is greater than the unit time, setting the number of requests in the unit time to be 1, updating the current-limiting cache data by utilizing the timestamp in the parameter of the Lua script and the number of requests in the unit time, returning a response of successful execution, and processing according to the user request; and if the time interval is less than or equal to the unit time, adding 1 to the number of requests in the unit time in the current-limiting cache data, and determining an execution result according to a comparison result of the processed number of requests in the unit time and the maximum access amount in the parameter of the Lua script.
In an optional mode, a data key of the current-limiting cache data is an IP address, and a data value corresponding to the data key of the current-limiting cache data is hash request data obtained by combining a timestamp and the number of requests in unit time; and taking the data key of the hash request data as a time stamp, and taking the data value corresponding to the data key of the hash request data as the request times in unit time.
Table 1 is a current-limiting cache data storage table in a database, as shown in table 1, where each row represents hash request data formed under one user request, and a key is a timestamp; value is the number of requests per unit time.
Current-limiting cache data column (row) Data key (key) Data value (value)
1 1605173486172 44
2 1605173489863 3
3 1605173494233 1
4 1605173496299 1
5 1605173499230 1
Table 1 current limiting buffer data storage table in database
In an optional manner, determining the execution result according to the comparison result between the processed number of requests per unit time and the maximum access amount in the parameter of the Lua script further includes: judging whether the number of the processed requests in unit time is greater than the maximum access amount in the parameters of the Lua script or not; if the access quantity is less than or equal to the maximum access quantity, updating the current-limiting cache data by utilizing the timestamp in the parameter of the Lua script and the number of processed requests in unit time, returning a response of successful execution, and processing according to the user request; if the access amount is larger than the maximum access amount, returning a response of failed execution and rejecting the user request to limit the flow aiming at the IP address.
In an optional manner, the method further comprises: and setting a buffering time for the current-limiting buffering data.
Specifically, in step S140, four cases may occur in the execution of the Lua script, the first case being: inquiring whether the database has current-limiting cache data using the IP address in the Lua script parameter as a data key according to the IP address [ key1 ]; if the current-limiting cache data with the IP address as the data key does not exist, the IP address is used for initiating a user request for the first time, the number of requests in unit time is set to be 1, the current-limiting cache data is constructed and stored in a database by utilizing the IP address, a timestamp in the parameter of the Lua script and the number of requests in unit time, cache failure time is set (generally, 24 hours can be set), a response of successful execution is returned, and the user request is processed according to the user request continuously after the current-limiting processing.
The second case is: when the database has the current-limiting cache data with the IP address in the parameter of the Lua script as the data key, acquiring the timestamp of the last user request initiating time according to the current-limiting cache data, judging whether the time interval between the timestamp in the current-limiting cache data and the timestamp [ argv1] in the parameter of the Lua script exceeds unit time (for example, one second), if the time interval exceeds the unit time, recounting, setting the number of requests in the unit time to 1, updating the current-limiting cache data by using the timestamp [ argv1] in the parameter of the Lua script and the number of requests in the unit time to 1, setting the cache failure time, returning a response of successful execution, wherein the user request passes through current-limiting processing, and continues to be processed according to the user request.
The third case is: if the time interval between the timestamp in the current-limiting cache data and the timestamp [ argv1] in the parameter of the Lua script does not exceed unit time (for example, one second), that is, the time interval between the current user request initiation time and the last user request initiation time is within the unit time, obtaining the request times in the unit time in the current-limiting cache data, adding 1 to the request times, judging whether the request times exceed the maximum access amount [ argv2] in the unit time preset by the IP address, if the request times are smaller than or equal to the maximum access amount [ argv2], updating the current-limiting cache data by using the timestamp [ argv1] in the parameter of the Lua script and the updated request times (i.e., after adding 1), setting cache failure time, returning a response of successful execution, wherein the user request is subjected to current-limiting processing, and continues to be processed according to the user request.
The fourth case is: if the maximum access amount [ argv2] in the unit time preset by the IP address is exceeded, namely the request number limit is exceeded, a response of failed execution is returned, and the user request is rejected to limit the flow of the IP address, so that the effect of limiting the flow of the IP address is achieved.
By adopting the method of the embodiment, under the condition of high concurrency of cluster environment, the Lua script is set and executed in the Redis database, so that the operation and calculation are carried out in the Lua script, and the Redis database integrates the operations of reading, writing, judging, calculating and the like into one atomic operation based on the stronger atomicity of the Lua script and the single-thread characteristic of the Redis database; the concurrent operation under the multithreading is avoided, the serial execution of the user request is ensured, a distributed lock in the prior art is not needed, and the problem of data confusion under the condition of high concurrency is avoided; meanwhile, the IO operation of the database is reduced and the pressure of the database is avoided by setting the cache in the Redis database; and the operation read-write operation of the invention is in Redis, and the normal response speed of the interface is hardly influenced.
Fig. 3 is a schematic structural diagram illustrating an embodiment of a current limiting apparatus for cluster services according to the present invention. As shown in fig. 3, the apparatus includes: an information query module 310, a parameter setting module 320, and an execution module 330.
An information query module 310, configured to obtain an IP address corresponding to a user request and a timestamp corresponding to a user request initiation time; and inquiring the maximum access amount corresponding to the preset IP address.
In an alternative manner, information query module 310 is further configured to: in a cluster node of a cluster server, extracting an IP address corresponding to a user request from a request header of the user request; and acquiring a time stamp corresponding to the initiation moment of the user request through a system function.
In an alternative manner, information query module 310 is further configured to: inquiring the maximum access amount corresponding to the preset IP address from the cache preferentially; and if the maximum access amount corresponding to the IP address is not inquired from the cache, inquiring the maximum access amount corresponding to the IP address from the database, and storing the inquired maximum access amount into the cache for the next inquiry from the cache.
And the parameter setting module 320 is used for reading the Lua script and setting the parameters of the Lua script according to the IP address, the timestamp and the maximum access amount.
And the execution module 330 is configured to execute the Lua script and perform current limiting processing on the IP address according to an execution result.
In an optional manner, the execution module 330 is further configured to: inquiring whether the database has current-limiting cache data using the IP address in the parameter of the Lua script as a data key; if the current-limiting cache data with the IP address as the data key does not exist, setting the number of requests in unit time to be 1, constructing the current-limiting cache data by using the IP address, the timestamp in the parameter of the Lua script and the number of requests in unit time, storing the current-limiting cache data into a database, returning a response of successful execution, and processing according to a user request; if the current-limiting cache data with the IP address as the data key exists, judging whether the time interval between the timestamp in the current-limiting cache data and the timestamp in the parameter of the Lua script is greater than unit time or not; if the time interval is greater than the unit time, setting the number of requests in the unit time to be 1, updating the current-limiting cache data by utilizing the timestamp in the parameter of the Lua script and the number of requests in the unit time, returning a response of successful execution, and processing according to the user request; and if the time interval is less than or equal to the unit time, adding 1 to the number of requests in the unit time in the current-limiting cache data, and determining an execution result according to a comparison result of the processed number of requests in the unit time and the maximum access amount in the parameter of the Lua script.
In an optional mode, a data key of the current-limiting cache data is an IP address, and a data value corresponding to the data key of the current-limiting cache data is hash request data obtained by combining a timestamp and the number of requests in unit time; and taking the data key of the hash request data as a time stamp, and taking the data value corresponding to the data key of the hash request data as the request times in unit time.
In an optional manner, the execution module 330 is further configured to: judging whether the number of the processed requests in unit time is greater than the maximum access amount in the parameters of the Lua script or not; if the access quantity is less than or equal to the maximum access quantity, updating the current-limiting cache data by utilizing the timestamp in the parameter of the Lua script and the number of processed requests in unit time, returning a response of successful execution, and processing according to the user request; if the access amount is larger than the maximum access amount, returning a response of failed execution and rejecting the user request to limit the flow aiming at the IP address.
In an optional manner, the execution module 330 is further configured to: and setting a buffering time for the current-limiting buffering data.
By adopting the device of the embodiment, under the condition of high concurrency in a cluster environment, the Lua script is set and executed in the Redis database, so that the operation and calculation are carried out in the Lua script, and based on the stronger atomicity of the Lua script and the single thread characteristic of the Redis database, the Redis database integrates the operations of reading, writing, judging, calculating and the like into one integral atomic operation, thereby avoiding the concurrent operation under multiple threads, ensuring the serial execution of user requests, avoiding the distributed lock in the prior art and avoiding the problem of data confusion under the condition of high concurrency.
The embodiment of the invention provides a nonvolatile computer storage medium, wherein at least one executable instruction is stored in the computer storage medium, and the computer executable instruction can execute a current limiting method of cluster service in any method embodiment.
The executable instructions may be specifically configured to cause the processor to:
acquiring an IP address corresponding to a user request and a timestamp corresponding to the user request initiating moment;
inquiring the maximum access amount corresponding to the preset IP address;
reading the Lua script, and setting parameters of the Lua script according to the IP address, the timestamp and the maximum access amount;
and executing the Lua script, and performing current limiting processing on the IP address according to an execution result.
Fig. 4 is a schematic structural diagram of an embodiment of a computing device according to the present invention, and the specific embodiment of the present invention does not limit the specific implementation of the computing device.
As shown in fig. 4, the computing device may include:
a processor (processor), a Communications Interface (Communications Interface), a memory (memory), and a Communications bus.
Wherein: the processor, the communication interface, and the memory communicate with each other via a communication bus. A communication interface for communicating with network elements of other devices, such as clients or other servers. The processor is configured to execute a program, and may specifically execute relevant steps in the above described method for limiting a flow of a cluster service.
In particular, the program may include program code comprising computer operating instructions.
The processor may be a central processing unit CPU or an application Specific Integrated circuit asic or one or more Integrated circuits configured to implement embodiments of the present invention. The server comprises one or more processors, which can be the same type of processor, such as one or more CPUs; or may be different types of processors such as one or more CPUs and one or more ASICs.
And the memory is used for storing programs. The memory may comprise high-speed RAM memory, and may also include non-volatile memory (non-volatile memory), such as at least one disk memory.
The program may specifically be adapted to cause a processor to perform the following operations:
acquiring an IP address corresponding to a user request and a timestamp corresponding to the user request initiating moment;
inquiring the maximum access amount corresponding to the preset IP address;
reading the Lua script, and setting parameters of the Lua script according to the IP address, the timestamp and the maximum access amount;
and executing the Lua script, and performing current limiting processing on the IP address according to an execution result.
The algorithms or displays presented herein are not inherently related to any particular computer, virtual system, or other apparatus. Various general purpose systems may also be used with the teachings herein. The required structure for constructing such a system will be apparent from the description above. In addition, embodiments of the present invention are not directed to any particular programming language. It is appreciated that a variety of programming languages may be used to implement the teachings of the present invention as described herein, and any descriptions of specific languages are provided above to disclose the best mode of the invention.
In the description provided herein, numerous specific details are set forth. It is understood, however, that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures and techniques have not been shown in detail in order not to obscure an understanding of this description.
Similarly, it should be appreciated that in the foregoing description of exemplary embodiments of the invention, various features of the embodiments of the invention are sometimes grouped together in a single embodiment, figure, or description thereof for the purpose of streamlining the invention and aiding in the understanding of one or more of the various inventive aspects. However, the disclosed method should not be interpreted as reflecting an intention that: that the invention as claimed requires more features than are expressly recited in each claim. Rather, as the following claims reflect, inventive aspects lie in less than all features of a single foregoing disclosed embodiment. Thus, the claims following the detailed description are hereby expressly incorporated into this detailed description, with each claim standing on its own as a separate embodiment of this invention.
Those skilled in the art will appreciate that the modules in the device in an embodiment may be adaptively changed and disposed in one or more devices different from the embodiment. The modules or units or components of the embodiments may be combined into one module or unit or component, and furthermore they may be divided into a plurality of sub-modules or sub-units or sub-components. All of the features disclosed in this specification (including any accompanying claims, abstract and drawings), and all of the processes or elements of any method or apparatus so disclosed, may be combined in any combination, except combinations where at least some of such features and/or processes or elements are mutually exclusive. Each feature disclosed in this specification (including any accompanying claims, abstract and drawings) may be replaced by alternative features serving the same, equivalent or similar purpose, unless expressly stated otherwise.
Furthermore, those skilled in the art will appreciate that while some embodiments herein include some features included in other embodiments, rather than other features, combinations of features of different embodiments are meant to be within the scope of the invention and form different embodiments. For example, in the following claims, any of the claimed embodiments may be used in any combination.
The various component embodiments of the invention may be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. Those skilled in the art will appreciate that a microprocessor or Digital Signal Processor (DSP) may be used in practice to implement some or all of the functionality of some or all of the components according to embodiments of the present invention. The present invention may also be embodied as apparatus or device programs (e.g., computer programs and computer program products) for performing a portion or all of the methods described herein. Such programs implementing the present invention may be stored on computer-readable media or may be in the form of one or more signals. Such a signal may be downloaded from an internet website or provided on a carrier signal or in any other form.
It should be noted that the above-mentioned embodiments illustrate rather than limit the invention, and that those skilled in the art will be able to design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The word "comprising" does not exclude the presence of elements or steps not listed in a claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The invention may be implemented by means of hardware comprising several distinct elements, and by means of a suitably programmed computer. In the unit claims enumerating several means, several of these means may be embodied by one and the same item of hardware. The usage of the words first, second and third, etcetera do not indicate any ordering. These words may be interpreted as names. The steps in the above embodiments should not be construed as limiting the order of execution unless specified otherwise.

Claims (10)

1. A method for limiting current of a cluster service, comprising:
acquiring an IP address corresponding to a user request and a timestamp corresponding to the user request initiating moment;
inquiring the preset maximum access amount corresponding to the IP address;
reading a Lua script, and setting parameters of the Lua script according to the IP address, the timestamp and the maximum access amount;
and executing the Lua script, and performing current limiting processing on the IP address according to an execution result.
2. The method of claim 1, wherein the obtaining the IP address corresponding to the user request and the timestamp corresponding to the user request initiation time further comprises:
in a cluster node of a cluster server, extracting an IP address corresponding to the user request from a request header of the user request;
and acquiring a timestamp corresponding to the user request initiating moment through a system function.
3. The method of claim 1, wherein the querying the preset maximum access amount corresponding to the IP address further comprises:
inquiring the preset maximum access amount corresponding to the IP address from a cache preferentially; and if the maximum access amount corresponding to the IP address is not inquired from the cache, inquiring the maximum access amount corresponding to the IP address from a database, and storing the inquired maximum access amount into the cache for inquiring from the cache next time.
4. The method according to any one of claims 1-3, wherein the executing the Lua script and the throttling the IP address according to the execution result further comprises:
inquiring whether current-limiting cache data using the IP address in the parameter of the Lua script as a data key exists in a database;
if the current-limiting cache data taking the IP address as the data key does not exist, setting the number of requests in unit time to be 1, constructing the current-limiting cache data and storing the current-limiting cache data into a database by utilizing the IP address, the timestamp in the parameter of the Lua script and the number of requests in unit time, returning a response of successful execution, and processing according to the user request;
if the current-limiting cache data with the IP address as the data key exists, judging whether the time interval between the timestamp in the current-limiting cache data and the timestamp in the parameter of the Lua script is greater than unit time or not;
if the time interval is greater than the unit time, setting the number of requests in the unit time to be 1, updating the current-limiting cache data by utilizing the timestamp in the parameter of the Lua script and the number of requests in the unit time, returning a response of successful execution, and processing according to the user request;
and if the time interval is less than or equal to the unit time, adding 1 to the number of requests in the unit time in the current-limiting cache data, and determining an execution result according to a comparison result of the processed number of requests in the unit time and the maximum access amount in the Lua script parameters.
5. The method according to claim 4, wherein the data key of the current-limiting cache data is an IP address, and the data value corresponding to the data key of the current-limiting cache data is hash request data obtained by combining a timestamp and the number of requests in a unit time; and the data key of the hash request data is the timestamp, and the data value corresponding to the data key of the hash request data is the request times in unit time.
6. The method of claim 4, wherein the determining the execution result according to the comparison result of the processed number of requests per unit time and the maximum access amount in the parameter of the Lua script further comprises:
judging whether the number of the processed requests in unit time is greater than the maximum access amount in the parameter of the Lua script or not;
if the current limit cache data is less than or equal to the maximum access amount, updating the current limit cache data by utilizing the timestamp in the parameter of the Lua script and the number of processed requests in unit time, returning a response of successful execution, and processing according to the user request;
and if the access amount is larger than the maximum access amount, returning a response of failed execution, and rejecting the user request to limit the flow aiming at the IP address.
7. The method according to any one of claims 4-6, further comprising:
and setting a buffering time for the current-limiting buffering data.
8. A current limiting apparatus for a cluster service, comprising:
the information query module is used for acquiring an IP address corresponding to a user request and a timestamp corresponding to the user request initiating moment; inquiring the preset maximum access amount corresponding to the IP address;
the parameter setting module is used for reading a Lua script and setting the parameters of the Lua script according to the IP address, the timestamp and the maximum access amount;
and the execution module is used for executing the Lua script and carrying out current limiting processing on the IP address according to an execution result.
9. A computing device, comprising: the system comprises a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface complete mutual communication through the communication bus;
the memory is used for storing at least one executable instruction, and the executable instruction causes the processor to execute the operation corresponding to the current limiting method of the cluster service according to any one of claims 1-7.
10. A computer storage medium having at least one executable instruction stored thereon, the executable instruction causing a processor to perform operations corresponding to a method of throttling a group service according to any one of claims 1 to 7.
CN202110857201.3A 2021-07-28 2021-07-28 Cluster service current limiting method and device, computing equipment and storage medium Pending CN113467896A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110857201.3A CN113467896A (en) 2021-07-28 2021-07-28 Cluster service current limiting method and device, computing equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110857201.3A CN113467896A (en) 2021-07-28 2021-07-28 Cluster service current limiting method and device, computing equipment and storage medium

Publications (1)

Publication Number Publication Date
CN113467896A true CN113467896A (en) 2021-10-01

Family

ID=77882917

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110857201.3A Pending CN113467896A (en) 2021-07-28 2021-07-28 Cluster service current limiting method and device, computing equipment and storage medium

Country Status (1)

Country Link
CN (1) CN113467896A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114339637A (en) * 2021-12-30 2022-04-12 上海大汉三通通信股份有限公司 Short message splicing method, device, equipment and storage medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114339637A (en) * 2021-12-30 2022-04-12 上海大汉三通通信股份有限公司 Short message splicing method, device, equipment and storage medium

Similar Documents

Publication Publication Date Title
CN107391628B (en) Data synchronization method and device
JP6724039B2 (en) Processing database transactions in distributed computing systems
WO2020181810A1 (en) Data processing method and apparatus applied to multi-level caching in cluster
US20140059163A1 (en) Distributed request processing
US20120084317A1 (en) Complex event processing apparatus and complex event processing method
US11080261B2 (en) Hybrid concurrency control
US8108725B2 (en) History-based conflict resolution
CN108459913B (en) Data parallel processing method and device and server
US9104486B2 (en) Apparatuses, systems, and methods for distributed workload serialization
CN112235396B (en) Content processing link adjustment method, content processing link adjustment device, computer equipment and storage medium
CN112416972A (en) Real-time data stream processing method, device, equipment and readable storage medium
US20140059162A1 (en) Distributed information synchronization
US11228598B2 (en) Offline mode user authorization device and method
CN113467896A (en) Cluster service current limiting method and device, computing equipment and storage medium
CN110866011A (en) Data table synchronization method and device, computer equipment and storage medium
CN113703929B (en) Task scheduling method, system, computing device and storage medium
CN113326146A (en) Message processing method and device, electronic equipment and storage medium
CN108062224B (en) Data reading and writing method and device based on file handle and computing equipment
US11657034B2 (en) Data consistency in master data integration
CN108804214B (en) Asynchronous task scheduling method and device and electronic equipment
CN106878369B (en) Service processing method and device
CN111459931A (en) Data duplication checking method and data duplication checking device
CN117056363B (en) Data caching method, system, equipment and storage medium
CN111737298B (en) Cache data management and control method and device based on distributed storage
CN112905602B (en) Data comparison method, computing device and computer storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination