Traffic control method, device, equipment and storage medium for service call
By detecting the usage rate of service tokens and dynamically adjusting the number of tokens, the token congestion problem when the number of service requests skyrockets is solved, reducing the delay of service requests and improving the elastic adjustment ability of the service.
Patent Information
- Application Number
- CN202211677038.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-26
- Publication Date
- 2025-06-17
- Estimated Expiration
- 2042-12-26
AI Technical Summary
In the virtualization and containerization technology environment, when the number of service requests skyrockets, existing traffic control methods lead to token congestion, increase the delay of service requests, and lack the ability to adjust elastically.
By detecting the usage rate of the service token within the set time, if the first set threshold is exceeded, the number of service tokens is adjusted to prevent token congestion and reduce the delay of service requests.
Dynamically adjusting the number of tokens can effectively prevent token congestion when the number of service requests skyrockets, reduce the delay of service requests, and improve the elastic adjustment ability of services.
Smart Images

Figure CN115967677B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the technical field of service invocation, and in particular, to a traffic control method, device, equipment and storage medium for service invocation. Background Art
[0002] Traffic control refers to taking certain measures to limit the number of access requests when resources become a bottleneck under the condition of limited resources. When a service invoker makes a request, it will obtain an invoker token, and according to whether the token is obtained, the request is allowed to enter the cache queue. Before the request is forwarded, it will obtain a provider token from the traffic controller again, and according to whether the token is obtained, the request is forwarded from the cache queue to the provider. This method will cause token congestion in the face of a sudden explosion of requests. Although it can effectively protect enterprise applications, in the context of the prevalence of virtualization and containerization technologies, to a certain extent, it directly limits the service capabilities of applications and there is no room for elastic adjustment. Summary of the Invention
[0003] Embodiments of the present invention provide a traffic control method, device, equipment and storage medium for service invocation, which dynamically adjusts the number of tokens and reduces the latency of service requests.
[0004] In a first aspect, an embodiment of the present invention provides a traffic control method for service invocation, including:
[0005] During service invocation, detecting the usage rate of service tokens within a set duration; wherein, the service tokens include invoker tokens and / or provider tokens;
[0006] Judging whether the usage rate exceeds a first set threshold;
[0007] If the usage rate exceeds the first set threshold, adjusting the number of the service tokens;
[0008] Performing service invocation based on the adjusted service tokens.
[0009] In a second aspect, an embodiment of the present invention further provides a traffic control device for service invocation, including:
[0010] A service token usage rate detection module, configured to detect the usage rate of service tokens within a set duration during service invocation; wherein, the service tokens include invoker tokens and / or provider tokens;
[0011] A judgment module, configured to judge whether the usage rate exceeds a first set threshold;
[0012] A service token adjustment module, configured to adjust the number of the service tokens if the usage rate exceeds the first set threshold;
[0013] A service call module, configured to perform service calls based on the adjusted service token.
[0014] Thirdly, an embodiment of the present invention further provides an electronic device, where the electronic device includes:
[0015] At least one processor; and
[0016] A memory communicatively connected to the at least one processor; wherein,
[0017] The memory stores a computer program executable by the at least one processor, and when the computer program is executed by the at least one processor, the at least one processor is enabled to execute the traffic control method for service calls according to the embodiment of the present invention.
[0018] Fourthly, an embodiment of the present invention provides a computer-readable storage medium, where the computer-readable storage medium stores computer instructions, and the computer instructions are used to implement the traffic control method for service calls according to the embodiment of the present invention when executed by a processor.
[0019] Fifthly, an embodiment of the present invention further provides a computer program product, including a computer program, characterized in that the computer program implements the traffic control method for service calls according to the embodiment of the present invention when executed by a processor.
[0020] An embodiment of the present invention discloses a traffic control method, device, equipment and storage medium for service calls. During the service call process, the usage rate of the service token within a set time period is detected; wherein, the service token includes a caller token and / or a provider token; it is determined whether the usage rate exceeds a first set threshold; if the usage rate exceeds the first set threshold, the number of service tokens is adjusted; and service calls are performed based on the adjusted service tokens. The traffic control method for service calls provided by the embodiment of the present invention can prevent the situation of token congestion when the service request volume surges by adjusting the number of service tokens when the usage rate of the service token within a set time period exceeds the first set threshold, and reduce the delay of service requests. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1 A flowchart of a traffic control method for service calls in Embodiment 1 of the present invention;
[0022] Figure 2 Is a flowchart of adjusting the number of service tokens in Embodiment 1 of the present invention;
[0023] Figure 3 Is a schematic diagram of a service call in Embodiment 1 of the present invention;
[0024] Figure 4It is a schematic structural diagram of a traffic control device for service invocation in the second embodiment of the present invention;
[0025] Figure 5 It is a schematic structural diagram of an electronic device in the third embodiment of the present invention. Detailed implementation manners
[0026] The present invention will be further described in detail below with reference to the drawings and embodiments. It can be understood that the specific embodiments described herein are only used to explain the present invention, rather than limiting the present invention. Additionally, it should be noted that for the sake of description, only parts related to the present invention are shown in the drawings, rather than all the structures.
[0027] Embodiment 1
[0028] Figure 1 It is a flowchart of a traffic control method for service invocation provided in Embodiment 1 of the present invention. This embodiment is applicable to the situation of traffic control during service invocation. This method can be executed by a traffic control device for service invocation, and this device can be implemented in the form of software and / or hardware. Optionally, it is implemented by an electronic device, and this electronic device can be a mobile terminal, a PC terminal, a server, etc. As Figure 1 shown, the method specifically includes the following steps:
[0029] S110, during service invocation, detect the usage rate of service tokens within a set duration.
[0030] Among them, service tokens include caller tokens and / or provider tokens. The process of service invocation can be understood as the process in which the service caller requests services from the service provider. Service tokens are pre-configured in the traffic controller and can be understood as passes for service invocation. The usage rate of service tokens can be understood as the ratio between the number of used service tokens and the total number of service tokens. The set duration can be understood as within a cycle.
[0031] In this embodiment, during service invocation, the usage rate of service tokens is detected at regular intervals, so as to obtain the usage rates of multiple service tokens within the set duration.
[0032] S120, determine whether the usage rate exceeds a first set threshold.
[0033] Among them, the first set threshold can be a pre-set value. For example, it can be any value between 90% and 100%. In this embodiment, the usage rates within the set duration include multiple; determining whether the usage rate exceeds the first set threshold can be understood as: determining whether the proportion of the usage rates exceeding the first set threshold among the multiple usage rates is greater than a second set threshold; if the proportion is greater than the second set threshold, then the usage rate exceeds the first set threshold.
[0034] Among them, the second set threshold can be a pre-set value. For example, it can be any value between 80% and 100%. The proportion of the multiple usage rates that exceed the first set threshold being greater than the second set threshold can be understood as the usage rate continuously being greater than the first set threshold within the set time period, indicating that the current service request volume is large. Exemplarily, assume that 10 usage rate values are detected within the set time period, and 9 of them exceed the first set threshold, that is, the proportion of the usage rates exceeding the first set threshold is 90%. Assume that the second set threshold is set to 85%, then 90% > 85%, indicating that the current service request volume is large.
[0035] S130, if the usage rate exceeds the first set threshold, then adjust the number of service tokens.
[0036] In this embodiment, if the usage rate exceeds the first set threshold, it indicates that the current service request volume is large. In order to prevent congestion of service tokens, the number of service tokens in the traffic controller needs to be adjusted here.
[0037] In this embodiment, the way to adjust the number of service tokens can be: determine whether the provider is a microservice provider; if the provider is a microservice provider, then adjust the number of service tokens according to the total number of microservice instances and the number of tokens per instance; if the provider is not a microservice provider, then increase the service tokens according to a set ratio.
[0038] Among them, the number of tokens per instance can be understood as the number of tokens corresponding to a microservice instance. Specifically, the way to adjust the number of service tokens according to the total number of microservice instances and the number of tokens per instance can be: perform a multiplication operation on the total number of microservice instances and the number of tokens per instance to obtain the target number of tokens; adjust the number of service tokens to the target number of tokens.
[0039] Among them, the calculation formula for the target number of tokens can be expressed as: target number of tokens = total number of microservice instances * number of tokens per instance. In this embodiment, dynamically adjusting the number of service tokens according to the total number of microservice instances and the number of tokens per instance can quickly and accurately adjust the number of service tokens.
[0040] Among them, the set ratio can be a pre-set value, for example, set to any value between 20% and 40%. Specifically, increasing the number of service tokens according to the set ratio can be understood as: multiplying the set ratio by the current existing number of service tokens to obtain the number of service tokens that need to be increased, and adding this number of service tokens to the traffic controller. Exemplarily, assume that the current existing number of service tokens is m, and the set ratio is set to 30%, then the number of service tokens that need to be increased is 30% * m, and the final number of service tokens is m + 30% * m.
[0041] Optionally, the way to increase the number of service tokens according to a set ratio can be: if the cumulative increase times of the service tokens do not reach the set times threshold, the number of service tokens is increased according to the set ratio.
[0042] Among them, the cumulative increase times can be understood as the number of adjustment times that the service tokens in the traffic controller have experienced from the initial configuration to the current moment. The set times threshold can be set in advance. In this embodiment, if the cumulative increase times of the service tokens do not reach the set times threshold, the number of service tokens is increased according to the set ratio; if the cumulative increase times of the service tokens reach the set times threshold, the number of service tokens is no longer adjusted. In this embodiment, restricting the increase times of the service tokens can prevent the unlimited increase of service tokens, which may cause the problem of excessive pressure on the service system and collapse.
[0043] Specifically, Figure 2 is a flowchart for adjusting the number of service tokens in this embodiment, as Figure 2 shown. When starting a service call, when applying for a service token, it is judged whether the usage rate of the service token exceeds the first set threshold. If it exceeds, it is judged whether the provider is a microservice provider. If it is a microservice provider, the number of service tokens is adjusted according to the total number of microservice instances and the number of tokens per instance; if it is not a microservice provider, the number of service tokens is increased according to the set ratio.
[0044] S140, perform service calls based on the adjusted service tokens.
[0045] In this embodiment, the process of performing service calls based on the adjusted service tokens can be: allocate the adjusted caller token to the request sent by the caller; store the request allocated with the caller token in the message queue for queuing; when the queuing of the request ends, allocate the adjusted provider token to the request; send the request allocated with the provider token to the provider.
[0046] Figure 3 is a schematic diagram of a service call in this embodiment, as Figure 3 shown. After the enterprise integration platform receives the request sent by the service caller, it obtains the caller token from the access traffic controller. The access traffic controller allocates the adjusted caller token to the request, and accesses the request allocated with the caller token to the message queue for queuing. When the queuing of this request ends, it obtains the provider token from the outgoing traffic controller. The outgoing traffic controller allocates the adjusted provider token to the request, and sends the request allocated with the provider token out of the cache queue and then sends it to the service provider.
[0047] In the technical solution of this embodiment, during the service call process, the usage rate of the service token within a set time period is detected; wherein, the service token includes a caller token and / or a provider token; it is determined whether the usage rate exceeds a first set threshold; if the usage rate exceeds the first set threshold, the number of service tokens is adjusted; and the service call is performed based on the adjusted service tokens. The traffic control method for service call provided by the embodiment of the present invention can prevent the token congestion when the service request volume surges and reduce the latency of service requests by adjusting the number of service tokens when the usage rate of the service token within a set time period exceeds the first set threshold.
[0048] Embodiment 2
[0049] Figure 4 FIG. is a schematic structural diagram of a traffic control device for service call provided by Embodiment 2 of the present invention, as Figure 4 shown, the device includes:
[0050] A service token usage rate detection module 410, configured to detect the usage rate of the service token within a set time period during the service call process; wherein, the service token includes a caller token and / or a provider token;
[0051] A judgment module 420, configured to judge whether the usage rate exceeds a first set threshold;
[0052] A service token adjustment module 430, configured to adjust the number of service tokens if the usage rate exceeds the first set threshold;
[0053] A service call module 440, configured to perform a service call based on the adjusted service tokens.
[0054] Optionally, there are multiple usage rates within the set time period; the judgment module 420 is further configured to:
[0055] Judge whether the proportion of the usage rates exceeding the first set threshold among the multiple usage rates is greater than a second set threshold;
[0056] If the proportion is greater than the second set threshold, it means the usage rate exceeds the first set threshold.
[0057] Optionally, the service token adjustment module 430 is further configured to:
[0058] Judge whether the provider is a microservice provider;
[0059] If the provider is a microservice provider, adjust the number of service tokens according to the total number of microservice instances and the number of tokens per single instance;
[0060] If the provider is not a microservice provider, increase the number of service tokens according to a set ratio.
[0061] Optionally, the service token adjustment module 430 is further configured to:
[0062] Perform a multiplication operation on the total number of instances of the microservice and the number of tokens per instance to obtain the target number of tokens;
[0063] Adjust the number of service tokens to the target number of tokens.
[0064] Optionally, the service token adjustment module 430 is further configured to:
[0065] If the cumulative increase times of the service tokens do not reach the set times threshold, increase the number of service tokens according to the set ratio.
[0066] Optionally, the service call module 440 is further configured to:
[0067] Allocate the adjusted caller token to the request sent by the caller;
[0068] Store the request with the allocated caller token in the message queue for queuing;
[0069] When the queuing of the request ends, allocate the adjusted provider token to the request;
[0070] Send the request with the allocated provider token to the provider.
[0071] The above device can execute the methods provided in all the foregoing embodiments of the present invention, and has the corresponding functional modules and beneficial effects for executing the above methods. For technical details not described in detail in this embodiment, reference may be made to the methods provided in all the foregoing embodiments of the present invention.
[0072] Embodiment III
[0073] Figure 5 FIG. shows a schematic structural diagram of an electronic device 10 that can be used to implement the embodiments of the present invention. The electronic device is intended to represent various forms of digital computers, such as, laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as, personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present invention described herein and / or claimed.
[0074] As Figure 5As shown, the electronic device 10 includes at least one processor 11 and a memory communicatively connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc. Among them, the memory stores a computer program executable by the at least one processor. The processor 11 can execute various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 into the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. The input / output (I / O) interface 15 is also connected to the bus 14.
[0075] Multiple components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a magnetic disk, an optical disc, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0076] The processor 11 can be various general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include but are not limited to a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as the traffic control method for service invocation.
[0077] In some embodiments, the traffic control method for service invocation can be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as the storage unit 18. In some embodiments, part or all of the computer program can be loaded and / or installed onto the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the traffic control method for service invocation described above can be executed. Alternatively, in other embodiments, the processor 11 can be configured to execute the traffic control method for service invocation in any other appropriate way (e.g., by means of firmware).
[0078] The various embodiments of the systems and techniques described above in this specification can be implemented in digital electronic circuitry, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems-on-chip (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include: being implemented in one or more computer programs that are executable and / or interpretable on a programmable system including at least one programmable processor, which may be a special-purpose or general-purpose programmable processor that receives data and instructions from, and transmits data and instructions to, a storage system, at least one input device, and at least one output device.
[0079] The computer programs for implementing the methods of the present invention can be written in any combination of one or more programming languages. These computer programs can be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the computer programs, when executed by the processor, cause the functions / operations specified in the flowchart and / or block diagram to be implemented. The computer programs can be executed entirely on the machine, partly on the machine, as a stand-alone software package partly on the machine and partly on a remote machine or entirely on the remote machine or server.
[0080] In the context of the present invention, a computer-readable storage medium can be a tangible medium that can contain or store a computer program for use by or in connection with an instruction execution system, apparatus, or device. The computer-readable storage medium can include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. Alternatively, the computer-readable storage medium can be a machine-readable signal medium. More specific examples of the machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0081] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or a trackball) by which the user can provide input to the electronic device. Other kinds of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, speech input, or tactile input).
[0082] The systems and techniques described herein can be implemented in a computing system including backend components (e.g., as a data server), or a computing system including middleware components (e.g., an application server), or a computing system including frontend components (e.g., a user computer having a graphical user interface or a web browser through which the user can interact with an implementation of the systems and techniques described herein), or a computing system including any combination of such backend components, middleware components, or frontend components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local area network (LAN), wide area network (WAN), blockchain network, and the Internet.
[0083] The computing system can include a client and a server. The client and the server are generally far from each other and typically interact through a communication network. The relationship between the client and the server is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or a cloud host, which is a host product in the cloud computing service system, solving the defects of difficult management and weak business scalability existing in traditional physical hosts and VPS services.
[0084] It should be understood that various forms of the processes shown above can be used, with steps reordered, added, or deleted. For example, the steps recited in the present invention can be executed in parallel, sequentially, or in a different order, as long as the desired results of the technical solution of the present invention can be achieved, and no limitation is imposed herein.
[0085] The above specific embodiments do not constitute a limitation on the protection scope of the present invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.
Claims
1. A traffic control method for service invocation, characterized in that, Including: During the service call process, detect the usage rate of service tokens within a set time period; wherein, the service tokens include caller tokens and / or provider tokens; Judge whether the usage rate exceeds a first set threshold; If the usage rate exceeds the first set threshold, adjust the quantity of the service tokens; Perform service calls based on the adjusted service tokens; The adjusting the quantity of the service tokens includes: Judge whether the provider is a microservice provider; If the provider is a microservice provider, dynamically adjust the quantity of the service tokens according to the total number of instances of the microservice and the number of tokens per single instance; wherein, the number of tokens per single instance is the number of tokens corresponding to one microservice instance; If the provider is not a microservice provider, increase the quantity of the service tokens according to a set ratio; There are multiple usage rates within the set time period; judging whether the usage rate exceeds the first set threshold includes: Judge whether the proportion of the usage rates exceeding the first set threshold among multiple usage rates is greater than a second set threshold; If the proportion is greater than the second set threshold, the usage rate exceeds the first set threshold; the performing service calls based on the adjusted service tokens includes: Allocate the adjusted caller tokens to the requests sent by the caller; Store the requests allocated with caller tokens into a message queue for queuing; After the queuing of the requests ends, allocate the adjusted provider tokens to the requests; Send the requests allocated with the provider tokens to the provider.
2. The method according to claim 1, characterized in that, Adjusting the quantity of the provider tokens according to the total number of instances of the microservice and the number of tokens per single instance includes: Perform a multiplication operation on the total number of instances of the microservice and the number of tokens per single instance to obtain the target number of tokens; Adjust the quantity of the provider tokens to the target number of tokens.
3. The method according to claim 1, characterized in that, Increasing the quantity of the service tokens according to a set ratio includes: If the cumulative increase times of the service tokens do not reach the set times threshold, increase the quantity of the service tokens according to a set ratio.
4. A traffic control device for service invocation, characterized in that, Including: A service token usage rate detection module, configured to detect the usage rate of service tokens within a set time period during the service call process; wherein, the service tokens include caller tokens and / or provider tokens; A judgment module, configured to judge whether the usage rate exceeds a first set threshold; A service token adjustment module, configured to adjust the quantity of the service tokens if the usage rate exceeds the first set threshold; A service call module, configured to perform service calls based on the adjusted service tokens; The service token adjustment module is further configured to: Judge whether the provider is a microservice provider; If the provider is a microservice provider, dynamically adjust the quantity of the service tokens according to the total number of instances of the microservice and the number of tokens per single instance; wherein, the number of tokens per single instance is the number of tokens corresponding to one microservice instance; If the provider is not a microservice provider, increase the quantity of the service tokens according to a set ratio; A judgment module, configured to judge whether the usage rate exceeds the first set threshold; A service token adjustment module, configured to adjust the quantity of the service tokens if the usage rate exceeds the first set threshold; A service call module, configured to perform service calls based on the adjusted service tokens; The service call module is further configured to: allocate the adjusted caller token to the request sent by the caller; store the request with the allocated caller token in a message queue for queuing; when the queuing of the request ends, allocate the adjusted provider token to the request; send the request with the allocated provider token to the provider.
5. An electronic device, characterized in that, The electronic device includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein, the memory stores a computer program executable by the at least one processor, and when the computer program is executed by the at least one processor, the at least one processor is enabled to execute the traffic control method of service call according to any one of claims 1-3.
6. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions for implementing the traffic control method of service call according to any one of claims 1-3 when executed by a processor.
7. A computer program product, comprising a computer program, characterized in that, The computer program, when executed by a processor, implements the traffic control method of service call according to any one of claims 1-3.
Citation Information
Patent Citations
Multi-dimensional centralized flow control method and system
CN111107012A
Data processing method and device, computer equipment and computer readable storage medium
CN115277577A