A method and apparatus for task throttling

CN115840601BActive Publication Date: 2026-09-15BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202211505778.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-11-28
Publication Date
2026-09-15
Estimated Expiration
2042-11-28

AI Technical Summary

Technical Problem

此种方式对于代码的编写要求较高,且对于不同的任务需要单独编写,增加了开发负担,同时代码重复冗余,不便于后期的升级和修改

Benefits of technology

[0018] An embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein the program, when executed by a processor, implements a task rate limiting method according to an embodiment of the present invention.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115840601B_ABST
    Figure CN115840601B_ABST
Patent Text Reader

Abstract

This invention discloses a method and apparatus for task rate limiting, relating to the field of computer technology. One specific embodiment of the method includes: acquiring a task to be processed and rate limiting parameters corresponding to the task; generating one or more rate limiter tokens corresponding to the rate limiting parameters; and sending messages corresponding to the task to be processed using the one or more rate limiter tokens, thereby limiting the rate of the task to be processed based on the number of rate limiter tokens. This embodiment, by acquiring the rate limiting parameters corresponding to the task to be processed, generating one or more rate limiter tokens corresponding to the rate limiting parameters, and sending messages corresponding to the task to be processed according to the rate limiter tokens, limits the message sending rate in the task to be processed through the use of rate limiter tokens. It eliminates the need for separate code writing for each task; users only need to input different rate limiting parameters when different tasks are executed to achieve different rate limiting for different tasks.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to a method and apparatus for limiting task speed. Background Technology

[0002] In existing technologies, when it is necessary to limit the data transmission rate in certain specific scenarios (such as flash sales), the main approach is to add rate-limiting code to the task code to limit the rate of specific tasks. This method requires high coding skills, and different tasks need to be written separately, which increases the development burden. At the same time, the code is repetitive and redundant, making it inconvenient for later upgrades and modifications. Summary of the Invention

[0003] In view of this, embodiments of the present invention provide a method and apparatus for task rate limiting. By obtaining rate limiting parameters corresponding to the task to be processed, generating one or more rate limiter tokens corresponding to the rate limiting parameters, and sending the message corresponding to the task to be processed according to the rate limiter tokens, the sending rate of messages in the task to be processed is limited by using the rate limiter tokens. No separate code needs to be written for each task; users only need to input different rate limiting parameters when different tasks are executed to achieve the purpose of different rate limiting for different tasks.

[0004] To achieve the above objectives, according to one aspect of the present invention, a method for task rate limiting is provided.

[0005] An embodiment of the present invention provides a method for task rate limiting, comprising: obtaining a task to be processed and a rate limiting parameter corresponding to the task to be processed; generating one or more rate limiter tokens corresponding to the rate limiting parameter; and using the one or more rate limiter tokens to send messages corresponding to the task to be processed, so as to rate limit the task to be processed based on the number of rate limiter tokens.

[0006] Optionally, the method is applied to the Flink processing engine, and obtaining the rate limiting parameter corresponding to the task to be processed includes: calling the execution graph corresponding to the task to be processed from the Flink processing engine, and parsing the rate limiting parameter from the execution graph.

[0007] Optionally, before calling the execution graph corresponding to the task to be processed from the Flink processing engine, the method further includes: determining the flow graph corresponding to the task to be processed, and one or more operators corresponding to the flow graph; adding preset rate limiting parameters to the operator attributes of the operator, and generating an execution graph including the rate limiting parameters.

[0008] Optionally, adding the preset speed limit parameter to the operator attribute of the operator to generate an execution graph including the speed limit parameter includes: receiving the speed limit parameter input by the user through a user interface; determining one or more operator chains in the flow graph; adding the speed limit parameter to the operator attribute of the last operator in the operator chain to generate a new operator chain; and generating the execution graph based on the new operator chain.

[0009] Optionally, adding the rate limiting parameter to the operator attribute of the last operator in the operator chain to generate a new operator chain includes: determining the hash value of each operator in the flow graph; storing the hash value and the rate limiting parameter in the flow graph to generate a new operator chain based on the correspondence between the hash value and the rate limiting parameter.

[0010] Optionally, sending messages corresponding to the pending task using the one or more speed limiter tokens includes: initializing and generating one or more speed limiters for the pending task according to the correspondence; determining whether there are any unused speed limiter tokens in the current period; if so, using any unused speed limiter token to call any of the one or more speed limiters to send one of the messages; if not, pausing the execution of the pending task until a new speed limiter token is generated in the next period.

[0011] Optionally, generating one or more speed limiter tokens corresponding to the speed limit parameter includes: generating one or more speed limiter tokens corresponding to the speed limit parameter according to a preset period, provided that the value of the speed limit parameter does not exceed a preset range; the number of speed limiter tokens is equal to the value.

[0012] Optionally, determining one or more operator chains in the flow graph includes: determining the connection relationships between the various operators in the flow graph; and determining one or more operator chains in the flow graph based on whether the connection relationships satisfy association conditions.

[0013] To achieve the above objectives, according to another aspect of the present invention, a task speed limiting device is provided.

[0014] An embodiment of the present invention provides a task rate limiting device comprising: an acquisition module for acquiring a task to be processed and a rate limiting parameter corresponding to the task to be processed; a generation module for generating one or more rate limiter tokens corresponding to the rate limiting parameter; and a rate limiting module for sending messages corresponding to the task to be processed using the one or more rate limiter tokens, so as to rate limit the task to be processed based on the number of rate limiter tokens.

[0015] To achieve the above objectives, according to another aspect of the present invention, an electronic device for task speed limiting is provided.

[0016] An electronic device for task rate limiting according to an embodiment of the present invention includes: one or more processors; and a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement a task rate limiting method according to an embodiment of the present invention.

[0017] To achieve the above objectives, according to another aspect of the present invention, a computer-readable storage medium is provided.

[0018] An embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein the program, when executed by a processor, implements a task rate limiting method according to an embodiment of the present invention.

[0019] One embodiment of the above invention has the following advantages or beneficial effects: by obtaining the rate-limiting parameters corresponding to the task to be processed, generating one or more rate-limiting tokens corresponding to the rate-limiting parameters, and sending the message corresponding to the task to be processed according to the rate-limiting tokens, the sending rate of messages in the task to be processed is limited by using the rate-limiting tokens. There is no need to write separate code for each task; users only need to input different rate-limiting parameters when different tasks are executed to achieve the purpose of different rate limits for different tasks.

[0020] The further effects of the aforementioned unconventional alternative methods will be explained below in conjunction with specific implementation methods. Attached Figure Description

[0021] The accompanying drawings are provided to better understand the invention and are not intended to unduly limit the scope of the invention. Wherein: Figure 1 This is a flowchart illustrating a task rate limiting method according to an embodiment of the present invention; Figure 2 This is a schematic flowchart illustrating the generation of an execution graph including speed limit parameters according to an embodiment of the present invention. Figure 3 This is a schematic diagram illustrating the specific process of generating an execution graph including speed limit parameters according to an embodiment of the present invention; Figure 4 This is a schematic diagram of the process for determining the operator chain according to an embodiment of the present invention; Figure 5 This is a flowchart illustrating the process of determining a new operator chain based on a speed limit parameter according to an embodiment of the present invention. Figure 6 This is a schematic diagram of the process of calling the speed limiter using a speed limiter token according to an embodiment of the present invention; Figure 7This is a schematic diagram of the processing flow of the Flink processing engine for multiple tasks to be processed according to an embodiment of the present invention; Figure 8 This is a schematic diagram of the main modules of the task speed limiting device according to an embodiment of the present invention; Figure 9 This is an exemplary system architecture diagram in which embodiments of the present invention can be applied; Figure 10 This is a schematic diagram of the structure of a computer system suitable for implementing terminal devices or servers of the present invention. Detailed Implementation

[0022] The following description, in conjunction with the accompanying drawings, illustrates exemplary embodiments of the present invention, including various details to aid understanding. These details should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the invention. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.

[0023] It should be noted that, unless otherwise specified, the embodiments of the present invention and the technical features thereof can be combined with each other.

[0024] It should be noted that the acquisition, storage, and application of user personal information involved in the technical solution disclosed herein comply with the provisions of relevant laws and regulations and do not violate public order and good morals.

[0025] Figure 1 This is a schematic diagram of the main steps of a task rate limiting method according to an embodiment of the present invention.

[0026] like Figure 1 As shown, the task rate limiting method of this invention mainly includes the following steps: Step S101: Obtain the task to be processed and the speed limit parameters corresponding to the task to be processed; Step S102: Generate one or more speed limiter tokens corresponding to the speed limit parameters; Step S103: Use one or more rate limiter tokens to send messages corresponding to the tasks to be processed, so as to rate limit the tasks to be processed according to the number of rate limiter tokens.

[0027] The rate limiting parameter is preset in the attributes of the task to be processed, so the corresponding rate limiting parameter can be obtained after the task to be processed is obtained. In an optional embodiment, when the method is applied to the Flink processing engine, step S101 may further include: calling the execution graph corresponding to the task to be processed from the Flink processing engine, and parsing the rate limiting parameter from the execution graph.

[0028] In the Flink processing engine, when a task is received, a multi-layered task graph is automatically generated based on the task package. The first layer is the flow graph, which is the initial graph generated based on the code written by the user through the Stream API, used to represent the program's topology. The last layer is the execution graph, where task nodes can process tasks according to the execution graph. Therefore, the rate limiting parameters parsed from the execution graph can be used to directly process the task.

[0029] It should be noted that in existing Flink processing engines, the multi-level task graph automatically generated from the task package does not include rate limiting parameters. Therefore, preset rate limiting parameters need to be added during the generation of the multi-level task graph in order to obtain the rate limiting parameters in the subsequent parsing process. In an optional embodiment, before obtaining the rate limiting parameters corresponding to the task to be processed in step S101, such as... Figure 2 As shown, it includes: Step S201: Determine the flow graph corresponding to the task to be processed, and one or more operators corresponding to the flow graph; Step S202: Add the preset speed limit parameters to the operator attributes of the operator to generate an execution graph that includes the speed limit parameters.

[0030] Through the above process, preset rate-limiting parameters can be added to the operator attributes, allowing the task rate to be limited based on the operator attributes during task execution. In a further optional embodiment, the specific process in step S202 is as follows: Figure 3 As shown, it includes: Step S301: Receive speed limit parameters input by the user through the user interface; Step S302: Determine one or more operator chains in the flow graph; Step S303: Add the speed limiting parameter to the operator attribute of the last operator in the operator chain to generate a new operator chain; Step S304: Generate an execution graph based on the new operator chain.

[0031] For step S301, an input window can be displayed through a user interface, allowing the user to input rate limiting parameters. Specifically, the user can directly input the specific value of the rate limiting parameter. Through the above process, the user-input rate limiting parameter can be added to the operator attribute of the last operator in the operator chain, so as to limit the data transmission speed in the last step of task execution, thereby achieving the purpose of rate limiting.

[0032] For step S302, there are various connection relationships between multiple operators in the flow graph, but not all connection relationships can form an operator chain. Therefore, in an optional embodiment, step S302 is as follows: Figure 4As shown, it further includes: Step S401: Determine the connection relationships between the operators in the flow graph; Step S402: Determine one or more operator chains in the flow graph based on whether the connection relationship satisfies the association condition.

[0033] In this context, a dependency relationship refers to a situation where a downstream operator's subtask depends on only one subtask of an upstream operator. That is, only multiple operators that satisfy a single dependency relationship can form an operator chain. By identifying one or more operator chains in the flow graph and modifying the attributes of the operators within these chains, the overhead of data serialization, deserialization, and data transfer between nodes in the Flink processing engine is reduced, thus improving task processing efficiency.

[0034] In practical applications, operators and operator chains are usually stored in the form of JSON strings. Therefore, in an optional embodiment, the process of generating a new operator chain in step S303 is as follows: Figure 5 As shown, it includes: Step S501: Determine the hash value of each operator in the flow graph; Step S502: Store the hash value and rate limiting parameter in the flow graph to generate a new operator chain based on the correspondence between the hash value and the rate limiting parameter.

[0035] The hash value of an operator can represent the position of the operator in the flow graph. By storing the correspondence between the hash values ​​of each operator and the rate limit in the task flow graph, it is possible to distinguish which operator corresponds to which rate limit value during operator initialization and runtime. This allows different tasks to be processed according to the different rate limit values ​​of the operators corresponding to the tasks when multiple tasks are processed at the same time.

[0036] Through the above process, after a user uploads a task to be processed, the input rate-limiting parameters can be added to the operator attributes of the corresponding operator for that task, generating an execution graph containing the rate-limiting parameters. Then, during task processing, the execution graph is parsed to obtain the rate-limiting parameters. This eliminates the need to write the rate-limiting parameters into the code of each task; rate limiting for different tasks can be achieved solely through the user interface, realizing code-free rate limiting and effectively reducing the development burden.

[0037] After obtaining the speed limit parameter, a speed limiter token corresponding to the speed limit parameter can be generated. In an optional embodiment, step S102 includes: if the value corresponding to the speed limit parameter does not exceed a preset range, generating one or more speed limiter tokens corresponding to the value according to a preset period based on the value of the speed limit parameter; wherein the number of speed limiter tokens is equal to the value. For example, when the user inputs a speed limit parameter value of 100 and the preset period is set to 1 second, speed limiter tokens will be generated at a rate of 100 per second, i.e., 100 speed limiter tokens are generated per second. Due to the different traffic limits of various servers and local area networks, it is necessary to limit the value of the speed limit parameter input by the user to avoid the situation where the value input by the user is too large, i.e., the server cannot generate the corresponding number of speed limiter tokens within the preset period according to the value input by the user. For example, in a flash sale scenario, if item A is sold out quickly and the inventory of item A is only 100, then the speed limit parameter can be set to a maximum of 100, i.e., until all items are sold out within the preset period, no more item A can be provided.

[0038] Specifically, after generating the corresponding number of speed limiter tokens, the speed limiter can be invoked using the speed limiter tokens to process the task, as described in step S103. Figure 6 As shown, it specifically includes: Step S601: Generate one or more speed limiters for the task to be processed according to the corresponding relationship; Step S602: Determine if there are any unused speed limiter tokens in the current cycle; If so, proceed to step S603: invoke any one of the one or more speed limiters using any unused speed limiter token to send a message; If not, proceed to step S604: suspend the execution of pending tasks until a new speed limiter token is generated in the next cycle.

[0039] It should be noted that one pending task can correspond to one or more messages, each rate limiter token can only send one message, and each rate limiter token can only be used once. Within each preset period, a corresponding number of rate limiter tokens are generated according to the rate limit parameter value. If all tokens are used, the task execution is paused and can only resume after new rate limiter tokens are generated in the next preset period. Unused rate limiter tokens cannot be used in the next preset period. At the end of each preset period, all rate limiter tokens are deleted to ensure uniform rate limiting within each preset period.

[0040] According to an embodiment of the present invention, the task rate limiting method obtains the rate limiting parameters corresponding to the task to be processed, generates one or more rate limiter tokens corresponding to the rate limiting parameters, and sends the message corresponding to the task to be processed according to the rate limiter tokens. In other words, the sending rate of messages in the task to be processed is limited by using the rate limiter tokens. No separate code needs to be written for each task; users only need to input different rate limiting parameters when different tasks are executed to achieve the purpose of different rate limiting for different tasks.

[0041] Figure 7 This is a flowchart illustrating the processing flow of the Flink processing engine for multiple tasks in this embodiment of the invention. Figure 7 As shown, there are two tasks to be processed, Task A and Task B. Task A has an operator chain with two operators, Operator 1 and Operator 2. Task B has operator chains with operators, Operator 3, Operator 4, and Operator 5. By adding the rate-limiting parameter to the operator attribute of the last operator in the operator chain (i.e., adding the rate-limiting parameter to the operator attribute of Operator 2 in Task A and the operator attribute of Operator 5 in Task B), an execution graph StreamEdge including the rate-limiting parameter is generated to rate-limit Task A and Task B respectively. After executing Task A and Task B, Task C continues to be executed. It should be noted that Task C corresponds to both Task A and Task B, which does not satisfy the relationship that the subtasks of the downstream operator depend on only one subtask of the upstream operator. Therefore, an operator chain cannot be formed, and no rate-limiting is applied to the operators in Task C.

[0042] Figure 8 This is a schematic diagram of the main modules of a task speed limiting device according to an embodiment of the present invention.

[0043] like Figure 8 As shown, the task speed limiting device 800 of this embodiment includes: The acquisition module 801 is used to acquire the task to be processed and the speed limit parameters corresponding to the task to be processed; Generation module 802 is used to generate one or more speed limiter tokens corresponding to the speed limit parameters; The rate limiting module 803 is used to send messages corresponding to the task to be processed using one or more rate limiter tokens, so as to limit the rate of the task to be processed by the number of rate limiter tokens.

[0044] In an optional embodiment of the present invention, the device 800 is disposed in the Flink processing engine, and the acquisition module 801 is further configured to call the execution graph corresponding to the task to be processed from the Flink processing engine, and parse the rate limiting parameter from the execution graph.

[0045] In an optional embodiment of the present invention, the device further includes a configuration module for determining the flow graph corresponding to the task to be processed, and one or more operators corresponding to the flow graph; adding preset rate limiting parameters to the operator attributes of the operator, and generating an execution graph including the rate limiting parameters.

[0046] In an optional embodiment of the present invention, the configuration module is further configured to: receive a rate limiting parameter input by a user through a user interface; determine one or more operator chains in the flow graph; add the rate limiting parameter to the operator attribute of the last operator in the operator chain to generate a new operator chain; and generate the execution graph based on the new operator chain.

[0047] In an optional embodiment of the present invention, the configuration module is further configured to: determine the hash value of each operator in the flow graph; store the hash value and the rate limiting parameter in the flow graph to generate a new operator chain according to the correspondence between the hash value and the rate limiting parameter.

[0048] In an optional embodiment of the present invention, the speed limiting module 803 is further configured to: initialize and generate one or more speed limiters for the task to be processed according to the correspondence; determine whether there is an unused speed limiter token in the current period; if so, use any unused speed limiter token to call any of the one or more speed limiters to send a message; if not, suspend the execution of the task to be processed until a new speed limiter token is generated in the next period.

[0049] In an optional embodiment of the present invention, the generation module 802 is further configured to, when the value corresponding to the speed limit parameter does not exceed a preset range, generate one or more speed limiter tokens corresponding to the value according to a preset period based on the value of the speed limit parameter; the number of speed limiter tokens is equal to the value.

[0050] In an optional embodiment of the present invention, the configuration module is further configured to determine the connection relationship between each operator in the flow graph; and determine one or more operator chains in the flow graph based on whether the connection relationship satisfies the association condition.

[0051] The task rate limiting device according to an embodiment of the present invention obtains the rate limiting parameters corresponding to the task to be processed, generates one or more rate limiter tokens corresponding to the rate limiting parameters, and sends the message corresponding to the task to be processed according to the rate limiter tokens. That is, the sending rate of messages in the task to be processed is limited by the use of the rate limiter tokens. No separate code needs to be written for each task; users only need to input different rate limiting parameters when different tasks are executed to achieve the purpose of different rate limiting for different tasks.

[0052] Figure 9 An exemplary system architecture 900 is shown that can be applied to the task rate limiting method or the task rate limiting apparatus of the present invention.

[0053] like Figure 9 As shown, system architecture 900 may include terminal devices 901, 902, and 903, network 904, and server 905. Network 904 is used as a medium to provide a communication link between terminal devices 901, 902, and 903 and server 905. Network 904 may include various connection types, such as wired or wireless communication links or fiber optic cables, etc.

[0054] Users can use terminal devices 901, 902, and 903 to interact with server 905 via network 904 to receive or send data. Various communication client applications can be installed on terminal devices 901, 902, and 903, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, and social media platforms.

[0055] Terminal devices 901, 902, and 903 can be various electronic devices with displays that support web browsing, including but not limited to smartphones, tablets, laptops, and desktop computers.

[0056] Server 905 can be a server that provides various services, such as a background management server that processes pending tasks or rate limiting parameters sent by users using terminal devices 901, 902, and 903. The background management server can analyze and process the received pending tasks or rate limiting parameters and feed back the processing results (such as the processing results of pending tasks) to the terminal devices.

[0057] It should be noted that the task rate limiting method provided in this embodiment of the invention is generally executed by server 905, and correspondingly, the task rate limiting device is generally set in server 905.

[0058] It should be understood that Figure 9 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.

[0059] The following is for reference. Figure 10 It shows a schematic diagram of the structure of a computer system 1000 suitable for implementing a terminal device of the present invention. Figure 10 The terminal device shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of the present invention.

[0060] like Figure 10 As shown, the computer system 1000 includes a central processing unit (CPU) 1001, which can perform various appropriate actions and processes based on programs stored in read-only memory (ROM) 1002 or programs loaded from storage section 1008 into random access memory (RAM) 1003. The RAM 1003 also stores various programs and data required for the operation of the system 1000. The CPU 1001, ROM 1002, and RAM 1003 are interconnected via a bus 1004. An input / output (I / O) first interface 1005 is also connected to the bus 1004.

[0061] The following components are connected to the I / O first interface 1005: an input section 1006 including a keyboard, mouse, etc.; an output section 1007 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 1008 including a hard disk, etc.; and a communication section 1009 including a network first interface card such as a LAN card, modem, etc. The communication section 1009 performs communication processing via a network such as the Internet. A drive 1010 is also connected to the I / O first interface 1005 as needed. A removable medium 1011, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on the drive 1010 as needed so that computer programs read from it can be installed into the storage section 1008 as needed.

[0062] In particular, according to the embodiments disclosed in this invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this invention include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 1009, and / or installed from removable medium 1011. When the computer program is executed by central processing unit (CPU) 1001, it performs the functions defined above in the system of this invention.

[0063] It should be noted that the computer-readable medium shown in this invention can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this invention, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this invention, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.

[0064] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0065] The modules described in the embodiments of the present invention can be implemented in software or hardware. The described modules can also be housed in a processor; for example, a processor may be described as including an acquisition module, a generation module, and a rate-limiting module. The names of these modules do not necessarily limit the module itself; for example, the acquisition module may also be described as "a module for acquiring a task to be processed and a rate-limiting parameter corresponding to the task to be processed."

[0066] In another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiments; or it may exist independently and not assembled into the device. The computer-readable medium carries one or more programs that, when executed by the device, cause the device to: acquire a task to be processed and a rate limiting parameter corresponding to the task to be processed; generate one or more rate limiter tokens corresponding to the rate limiting parameter; and send messages corresponding to the task to be processed using the one or more rate limiter tokens, respectively, to rate limit the task to be processed based on the number of rate limiter tokens.

[0067] According to the technical solution of this invention, by obtaining the rate-limiting parameters corresponding to the task to be processed, generating one or more rate-limiting tokens corresponding to the rate-limiting parameters, and sending the message corresponding to the task to be processed according to the rate-limiting tokens, the sending rate of messages in the task to be processed is limited by using the rate-limiting tokens. There is no need to write separate code for each task; users only need to input different rate-limiting parameters when different tasks are executed to achieve the purpose of different rate limits for different tasks.

[0068] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.

Claims

1. A method for limiting task speed, characterized in that, include: Obtain the task to be processed and the speed limit parameters corresponding to the task to be processed; Generate one or more speed limiter tokens corresponding to the speed limit parameters; The message corresponding to the task to be processed is sent using one or more speed limiter tokens, so as to limit the speed of the task to be processed according to the number of speed limiter tokens. The step of obtaining the speed limit parameter corresponding to the task to be processed includes: Determine the flow graph corresponding to the task to be processed, and one or more operators corresponding to the flow graph; Add the preset speed limit parameter to the operator attribute of the operator to generate an execution graph that includes the speed limit parameter; The execution graph corresponding to the task to be processed is invoked, and the rate limit parameter is parsed from the execution graph.

2. The method according to claim 1, characterized in that, The method is applied to the Flink processing engine, which calls the execution graph corresponding to the task to be processed from the Flink processing engine, and parses the rate limiting parameters from the execution graph.

3. The method according to claim 1, characterized in that, The step of adding the preset speed limit parameter to the operator attribute of the operator to generate an execution graph including the speed limit parameter includes: Receive speed limit parameters input by the user through the user interface; Determine one or more operator chains in the flow graph; The speed limit parameter is added to the operator attribute of the last operator in the operator chain to generate a new operator chain; The execution graph is generated based on the new operator chain.

4. The method according to claim 3, characterized in that, The step of adding the speed limiting parameter to the operator attribute of the last operator in the operator chain to generate a new operator chain includes: Determine the hash value of each operator in the flow graph; The hash value and the rate limiting parameter are stored in the flow graph to generate a new operator chain based on the correspondence between the hash value and the rate limiting parameter.

5. The method according to claim 4, characterized in that, The step of sending messages corresponding to the tasks to be processed using the one or more speed limiter tokens includes: Based on the aforementioned correspondence, one or more speed limiters are initialized and generated for the task to be processed. Determine if there are any unused speed limiter tokens in the current period; If so, invoke any of the one or more speed limiters using any unused speed limiter token to send one of the aforementioned messages; If not, suspend the pending task until a new speed limiter token is generated in the next cycle.

6. The method according to claim 1, characterized in that, The generation of one or more speed limiter tokens corresponding to the speed limit parameters includes: If the value corresponding to the speed limit parameter does not exceed a preset range, one or more speed limiter tokens corresponding to the value are generated according to a preset period based on the value of the speed limit parameter; the number of speed limiter tokens is equal to the value.

7. The method according to claim 3, characterized in that, Determining one or more operator chains in the flow graph includes: Determine the connection relationships between the operators in the flow graph; Based on whether the connection relationship satisfies the association condition, one or more operator chains in the flow graph are determined.

8. A device for limiting the speed of a task, characterized in that, include: The acquisition module is used to acquire the task to be processed and the speed limit parameters corresponding to the task to be processed; The generation module is used to generate one or more speed limiter tokens corresponding to the speed limit parameters; The rate limiting module is used to send messages corresponding to the task to be processed using one or more rate limiter tokens, so as to limit the rate of the task to be processed by the number of rate limiter tokens. The acquisition module is also used for: Determine the flow graph corresponding to the task to be processed, and one or more operators corresponding to the flow graph; Add the preset speed limit parameter to the operator attribute of the operator to generate an execution graph that includes the speed limit parameter; The execution graph corresponding to the task to be processed is invoked, and the rate limit parameter is parsed from the execution graph.

9. An electronic device for task speed limiting, characterized in that, include: One or more processors; Storage device for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any one of claims 1-7.

10. A computer-readable medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1-7.

Citation Information

Patent Citations

  • Flow limiting method for message middleware and message middleware

    CN114584519A