Micro-service current limiting method and device, current limiting equipment, program product and medium

By using shared memory and private cache in the current limiting service, dynamically loading and updating the current limiting configuration of microservices, the problem that the current limiting method in the existing technology cannot adapt to the microservice architecture, and the refined current limiting and high-flexible traffic management of microservices are realized.

CN119922138APending Publication Date: 2025-05-02QINGDAO TELAI BIG DATA CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510134658.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-06
Publication Date
2025-05-02

AI Technical Summary

Technical Problem

The existing flow current limiting method cannot adapt to the microservice architecture, and the current limiting flexibility is insufficient, making it difficult to effectively deal with the surge in the charging service network of new energy vehicles.

Method used

By using shared memory and private cache in the current limiting service, the current limiting configuration of microservices can be dynamically loaded and updated. The first process loads the current limit configuration to shared memory when the current limit service is started, and the second process loads the current limit from the shared memory to the private cache and performs the current limit according to the configuration. At the same time, dynamic updates to current limit configurations are supported.

Benefits of technology

It realizes flexible current limiting for microservices, improves the granularity and flexibility of current limiting, and can more effectively deal with the surge in traffic in the charging service network and prevent back-end crashes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119922138A_ABST
    Figure CN119922138A_ABST
Patent Text Reader

Abstract

The invention provides a micro-service current limiting method and device, current limiting equipment, a program product and a medium, and relates to the technical field of networks, the method comprises the following steps: controlling a first process to load current limiting configuration corresponding to each micro-service from a preset configuration file to a shared memory when a current limiting service is started; controlling the second process to load the flow limiting configuration from the shared memory to the private cache of the second process, so as to limit the flow of the network request sent to each micro-service according to the flow limiting configuration in the private cache; controlling the first process to judge whether a configuration updating request is received or not, and updating the corresponding flow limiting configuration in the shared memory by utilizing the flow limiting configuration in the configuration updating request when the configuration updating request is received; controlling the second process to judge whether the current limiting configuration in the shared memory is updated or not, and loading the updated current limiting configuration to the private cache from the shared memory when determining that the current limiting configuration in the shared memory is updated; and the granularity and the flexibility of micro-service flow limiting can be effectively enhanced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of network technology, and in particular to a microservice current limiting method, device, current limiting equipment, program product and medium. Background Art

[0002] With the continuous development of new energy technologies, the number of new energy vehicles is increasing, and the demand for charging new energy vehicles is also increasing. In order to ensure the reliability of charging services, it is of great significance to effectively limit the surge traffic received by the charging service network in a timely manner to prevent the surge traffic from causing backend crashes.

[0003] In the related art, traffic limiting is usually performed on a specific backend server or source IP, and the limiting is usually performed according to a fixed configuration. However, this is not suitable for the microservice architecture currently used in charging business networks, and cannot achieve a high degree of flow limiting flexibility. Summary of the invention

[0004] The purpose of the present invention is to provide a microservice current limiting method, device, current limiting equipment, program product and medium, which can limit the current of microservices, and the current limiting configuration of microservices can be dynamically adjusted, so as to refine the granularity of microservice current limiting and improve flexibility.

[0005] In order to solve the above technical problems, the present invention provides a microservice current limiting method, comprising:

[0006] Control the first process to load the current limiting configuration corresponding to each microservice from the preset configuration file to the shared memory when the current limiting service is started;

[0007] Control the second process to load the current limiting configuration from the shared memory to its own private cache, and limit the current of network requests sent to each of the microservices according to the current limiting configuration in the private cache;

[0008] Controlling the first process to determine whether a configuration update request is received, and when the configuration update request is received, updating the corresponding current limiting configuration in the shared memory using the current limiting configuration in the configuration update request;

[0009] The second process is controlled to determine whether the current limiting configuration in the shared memory is updated, and when it is determined that the current limiting configuration in the shared memory has been updated, the updated current limiting configuration is loaded from the shared memory to the private cache.

[0010] Optionally, after receiving the configuration update request, the method further includes:

[0011] Control the first process to update the current limiting configuration in the configuration update request to the preset configuration file.

[0012] Optionally, after loading the current limiting configuration corresponding to each microservice from a preset configuration file into the shared memory, the method further includes:

[0013] Control the first process to record the global loading time of each current limiting configuration loaded into the shared memory, and set the global update time of the shared memory to the current time;

[0014] After controlling the second process to load the current limiting configuration from the shared memory to its own private cache, the method further includes:

[0015] Control the second process to record the private loading time of each current limiting configuration loaded into the private cache according to the global loading time of each current limiting configuration loaded into the shared memory, and set the private update time of the private cache according to the global update time of the shared memory;

[0016] After the corresponding current limiting configuration in the shared memory is updated using the current limiting configuration in the configuration update request, the method further includes:

[0017] Controlling the first process to update the global loading time corresponding to the updated current limiting configuration, and updating the global update time;

[0018] The controlling the second process to determine whether the current limiting configuration in the shared memory is updated, and when it is determined that the current limiting configuration in the shared memory has been updated, loading the updated current limiting configuration from the shared memory to the private cache includes:

[0019] Controlling the second process to determine whether the private update time is the same as the global update time;

[0020] If they are the same, it is determined that the current limiting configuration in the shared memory is not updated;

[0021] If they are not the same, it is determined that the current limiting configuration in the shared memory has been updated, and the current limiting configuration in which the global loading time is different from the private loading time is used as the updated current limiting configuration. The updated current limiting configuration is loaded from the shared memory to the private cache, and the corresponding private loading time is numerically adjusted according to the global loading time corresponding to the updated current limiting configuration, and the private update time is numerically adjusted according to the global update time.

[0022] Optionally, it also includes:

[0023] Control the first process to obtain a preset polling time from the preset configuration file, and configure the preset polling time for the second process;

[0024] The controlling the second process to determine whether the private update time is the same as the global update time includes:

[0025] The second process is controlled to periodically determine whether the private update time is the same as the global update time according to the preset polling time.

[0026] Optionally, controlling the first process to determine whether a configuration update request is received includes:

[0027] The first process is controlled to determine whether the configuration update request is input through a preset API interface.

[0028] Optionally, limiting the flow of network requests sent to each of the microservices according to the flow limiting configuration in the private cache includes:

[0029] Control the second process to receive a network request, and determine a target microservice for receiving the network request according to a microservice identifier in the network request;

[0030] Determine the current limiting algorithm and current limiting parameters corresponding to the target microservice according to the current limiting configuration corresponding to the target microservice in the private cache;

[0031] Performing current limiting detection on the network request using the current limiting algorithm and the current limiting parameters to determine whether the network request triggers current limiting;

[0032] If the network request does not trigger current limiting, the network request is released to the target microservice;

[0033] If the network request triggers current limiting, the network request is handled as an exception.

[0034] Optionally, performing current limiting detection on the network request using the current limiting algorithm and the current limiting parameter includes:

[0035] Control the second process in each preset time slice, if the microservice receives a network request in the preset time slice, then increase the flow number of the preset time slice by one, if the microservice completes a network request in the preset time slice, then reduce the flow number of the preset time slice by one;

[0036] Counting the total traffic of a plurality of consecutive preset time slices, and when it is determined that the total traffic exceeds a preset total traffic threshold, determining that the current network request triggers traffic limiting;

[0037] Or, control the second process to count the total number of network requests received by the microservice in a preset time period, and when it is determined that the total number exceeds a preset total number threshold, determine that the current network request triggers current limiting.

[0038] Optionally, the performing exception processing on the network request includes:

[0039] Control the second process to determine whether the target microservice opens the observation mode according to the current limiting configuration corresponding to the target microservice in the private cache;

[0040] If enabled, the network request is sent to the target microservice and an abnormal warning message is output;

[0041] If not enabled, the network request is prohibited from being sent to the target microservice.

[0042] The present invention also provides a microservice current limiting device, comprising:

[0043] A shared memory loading module is used to control the first process to load the current limiting configuration corresponding to each microservice from a preset configuration file to the shared memory when the current limiting service is started;

[0044] A current limiting module, used to control the second process to load the current limiting configuration from the shared memory to its own private cache, and to limit the network requests sent to each of the microservices according to the current limiting configuration in the private cache;

[0045] A shared memory update module, used to control the first process to determine whether a configuration update request is received, and when the configuration update request is received, update the corresponding current limiting configuration in the shared memory using the current limiting configuration in the configuration update request;

[0046] The private cache update module is used to control the second process to determine whether the current limiting configuration in the shared memory is updated, and when it is determined that the current limiting configuration in the shared memory has been updated, load the updated current limiting configuration from the shared memory to the private cache.

[0047] The present invention also provides a current limiting device, comprising:

[0048] Memory for storing computer programs;

[0049] A processor is used to implement the microservice current limiting method as described above when executing the computer program.

[0050] The present invention also provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are loaded and executed by a processor, the microservice current limiting method as described above is implemented.

[0051] The present invention also provides a computer program product, including a computer program or instructions, which implement the microservice current limiting method as described above when executed by a processor.

[0052] The present invention provides a microservice current limiting method, comprising: controlling a first process to load a current limiting configuration corresponding to each microservice from a preset configuration file to a shared memory when a current limiting service is started; controlling a second process to load the current limiting configuration from the shared memory to its own private cache, so as to limit the network request sent to each of the microservices according to the current limiting configuration in the private cache; controlling the first process to determine whether a configuration update request is received, and when the configuration update request is received, using the current limiting configuration in the configuration update request to update the corresponding current limiting configuration in the shared memory; controlling the second process to determine whether the current limiting configuration in the shared memory is updated, and when it is determined that the current limiting configuration in the shared memory has been updated, loading the updated current limiting configuration from the shared memory to the private cache.

[0053] It can be seen that in the present invention, when the current limiting service is started, the first process can first load the current limiting configuration corresponding to each microservice from the preset configuration file to the shared memory; and the second process loads the current limiting configuration from the shared memory to its own private cache, so as to limit the network request sent to each microservice according to the current limiting configuration in the private cache. In other words, the present invention can limit the current for microservices instead of limiting the current for the backend server or source IP; and the present invention can set a corresponding current limiting configuration for each microservice, so as to improve the current limiting granularity. In addition, the first process can determine whether a configuration update request is received, and when a configuration update request is received, the corresponding current limiting configuration in the shared memory is updated using the current limiting configuration in the configuration update request; the second process can determine whether the current limiting configuration in the shared memory is updated, and when it is determined that the current limiting configuration in the shared memory has been updated, the updated current limiting configuration is loaded from the shared memory to the private cache. In other words, the present invention supports dynamic update of the current limiting configuration, which can effectively enhance the flexibility of microservice current limiting, so that the microservice can be more effectively current limited. The present invention also provides a microservice current limiting device, a current limiting equipment, a computer program product and a computer-readable storage medium, which have the above-mentioned beneficial effects. BRIEF DESCRIPTION OF THE DRAWINGS

[0054] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0055] Figure 1 A flow chart of a microservice current limiting method provided by an embodiment of the present invention;

[0056] Figure 2A flowchart of service loading and starting provided by an embodiment of the present invention;

[0057] Figure 3 A flow chart of a service flow limiting control provided by an embodiment of the present invention;

[0058] Figure 4 A flow chart of dynamically adjusting the current limiting threshold provided by an embodiment of the present invention;

[0059] Figure 5 A flow chart of a timed polling and updating current limiting strategy provided by an embodiment of the present invention;

[0060] Figure 6 A structural block diagram of a microservice current limiting device provided by an embodiment of the present invention;

[0061] Figure 7 This is a structural block diagram of a current limiting device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0062] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0063] With the continuous development of new energy technologies, new energy vehicles are increasing, and the demand for charging new energy vehicles is also increasing. In order to ensure the reliability of the charging service, it is of great significance for the charging service to effectively limit the surge traffic received by the charging service network in a timely manner to prevent the surge traffic from causing the backend to crash. In related technologies, traffic limiting is usually performed on specific backend servers or source IPs, and the limiting is usually performed according to a fixed configuration. However, this is not suitable for the microservice architecture currently used in charging service networks, and cannot achieve a high degree of flow limiting flexibility.

[0064] In view of this, the present invention can provide a microservice current limiting method, which can limit the current of microservices, and the current limiting configuration of microservices can be dynamically adjusted, thereby refining the granularity of microservice current limiting and improving flexibility.

[0065] The following is an introduction to the microservice current limiting method provided by the embodiment of the present invention. It should be noted that the execution subject of this method can be called a current limiting device, and its specific hardware form can be set according to actual application requirements, for example, it can be a server. Please refer to Figure 1 , Figure 1A flow chart of a microservice current limiting method provided by an embodiment of the present invention, the method may include:

[0066] S101. Control the first process to load the current limiting configuration corresponding to each microservice from a preset configuration file to a shared memory when the current limiting service is started.

[0067] In this embodiment, the current limiting service refers to a service that limits network requests input to a microservice; the current limiting device may first include a first process for adding and updating the current limiting configuration. In this step, the first process may obtain a preset configuration file from the local machine when the current limiting service is started, obtain the current limiting configuration corresponding to each microservice from the file, and load the current limiting configuration into the shared memory. Among them, the current limiting configuration is used to perform current limiting processing, and may include the type of current limiting algorithm and current limiting parameters. The type of current limiting algorithm is used to indicate the type of current limiting algorithm required for microservice current limiting; the current limiting parameters are adjustable parameters required to execute the current limiting algorithm, for example, they may include current limiting threshold, current limiting duration, current limiting source IP, current limiting source device, etc. Each microservice has a corresponding current limiting configuration, and the current limiting configuration corresponding to each microservice may be different. In this way, this embodiment can provide different current limiting services for each microservice to refine the current limiting granularity and improve the current limiting flexibility.

[0068] It should be noted that this embodiment does not limit the specific current limiting algorithm and current limiting parameters, which can be set according to actual application requirements, and can also refer to the description in subsequent embodiments.

[0069] S102: Control the second process to load the current limiting configuration from the shared memory to its own private cache, and limit the current of network requests sent to each microservice according to the current limiting configuration in the private cache.

[0070] In this embodiment, the current limiting device may further include a second process for providing current limiting services to the microservices. The number of second processes may be one or more, and multiple second processes may jointly provide services to multiple microservices; in addition, each second process may have a private cache. In this step, the second process may load the current limiting configuration from the shared memory to its own private cache, so as to limit the network requests sent to each microservice according to the current limiting configuration in the private cache.

[0071] S103: Control the first process to determine whether a configuration update request is received, and when the configuration update request is received, use the current limiting configuration in the configuration update request to update the corresponding current limiting configuration in the shared memory.

[0072] In this step, the first process can determine whether a configuration update request is received, and when a configuration update request is received, the current limiting configuration update in the configuration update request is loaded into the shared memory. It is worth noting that the configuration update request can update the current limiting configuration for one microservice or for multiple microservices, thereby improving the flexibility of the current limiting configuration update.

[0073] Furthermore, for the convenience of users, the current limiting device may set an API interface (Application Programming Interface). The user may input the configuration update request by calling the API interface; the first process may determine whether to input the configuration update request through the preset API interface.

[0074] Based on this, controlling the first process to determine whether a configuration update request is received may include:

[0075] Step 11: Control the first process to determine whether a configuration update request is input via a preset API interface.

[0076] Furthermore, to ensure that the updated current limiting configuration can be inherited and retained when the current limiting service is restarted, in addition to writing the updated current limiting configuration to the shared memory, the first process can also update the updated current limiting configuration to the preset configuration file. In this way, the next time the service is restarted, the updated current limiting configuration can be loaded from the preset configuration file.

[0077] Based on this, after receiving the configuration update request, the following may also be included:

[0078] Step 21: Control the first process to update the current limiting configuration in the configuration update request to a preset configuration file.

[0079] S104: Control the second process to determine whether the current limiting configuration in the shared memory is updated, and when it is determined that the current limiting configuration in the shared memory is updated, load the updated current limiting configuration from the shared memory to the private cache.

[0080] In this step, the second process can determine whether the current limiting configuration in the shared memory is updated, and when it is determined that the current limiting configuration in the shared memory has been updated, load the updated current limiting configuration from the shared memory to the private cache to complete the current limiting configuration update.

[0081] Simply put, this embodiment can set a shared memory shared by the first process and the second process in the current limiting device, and can set a current limiting configuration distribution mechanism based on the shared memory. In the initialization stage, the first process can load the current limiting configuration into the shared memory, and then the second process can load the current limiting configuration from the shared memory to its own private cache to complete the initialization distribution of the current limiting configuration. Similarly, in the current limiting configuration update stage, the first process can load the updated current limiting configuration into the shared memory, and then the second process detects whether the current limiting configuration in the shared memory has been updated. If updated, the updated current limiting configuration is loaded from the shared memory to its own private cache to complete the update distribution of the current limiting configuration. In this way, this embodiment can realize the dynamic update of the current limiting configuration, thereby improving the flexibility of microservice current limiting.

[0082] It should be noted that this embodiment does not limit how the second process determines whether the current limiting configuration in the shared memory is updated. In a simple case, the second process can compare the current limiting configuration in its own private cache with the current limiting configuration in the shared memory. If the two are found to be inconsistent, it can be determined that the current limiting configuration in the shared memory has been updated. However, considering the number of microservices and the current limiting configuration corresponding to each microservice may be large, frequent comparisons are likely to affect performance. Therefore, in this embodiment, the first process and the second process can maintain two sets of time information, and can determine whether the shared memory is updated based on these two sets of time information.

[0083] Specifically, the first process can separately record the global loading time of each current limiting configuration loaded into the shared memory, and the global update time of the shared memory. The global loading time refers to the time when the current limiting configuration was last updated to the shared memory, and the global update time refers to the time when the shared memory was last updated. The second process can separately record the private loading time of each current limiting configuration loaded into the private cache, and separately record the private update time of its own private cache. When the second process updates the current limiting configuration to the private cache, it adjusts the private loading time of the current limiting configuration according to the global loading time corresponding to the current limiting configuration; when the second process completes the update of the private cache, it adjusts the private update time according to the global update time. Simply put, when the current limiting configuration in the shared memory is updated, the global loading time and the global update time will be updated synchronously. At this time, the private loading time and the private update time will be different from the global loading time and the global update time. As long as the second process perceives that the private loading time and the private update time are different from the global loading time and the global update time, it can determine that the shared memory has been updated, and can locate which current limiting configuration has been updated.

[0084] Based on the above embodiments, in the present invention, when the current limiting service is started, the first process can first load the current limiting configuration corresponding to each microservice from the preset configuration file to the shared memory; and the second process loads the current limiting configuration from the shared memory to its own private cache, so as to limit the network request sent to each microservice according to the current limiting configuration in the private cache. In other words, the present invention can limit the current for microservices instead of limiting the current for the backend server or source IP; and the present invention can set a corresponding current limiting configuration for each microservice, so as to improve the current limiting granularity. In addition, the first process can determine whether a configuration update request is received, and when receiving a configuration update request, the current limiting configuration in the configuration update request is updated and loaded into the shared memory; the second process can determine whether the current limiting configuration in the shared memory is updated, and when it is determined that the current limiting configuration in the shared memory has been updated, the updated current limiting configuration is loaded from the shared memory to the private cache. In other words, the present invention supports dynamic update of the current limiting configuration, which can effectively enhance the flexibility of microservice current limiting, so that the microservice can be more effectively current limited.

[0085] Based on the above embodiment, the specific process of determining whether the shared memory has a current limiting configuration update based on two sets of time information is introduced below. Based on this, the method may also include:

[0086] S201. Control the first process to load the current limiting configuration corresponding to each microservice from a preset configuration file to a shared memory when the current limiting service is started.

[0087] S202: Control the first process to record the global loading time of each current limiting configuration loaded into the shared memory, and set the global update time of the shared memory to the current time.

[0088] In this step, when the first process loads the current limiting configuration from the preset configuration file to the shared memory, it can record the global loading time of each current limiting configuration loaded into the shared memory, and adjust the global update time to the current time (i.e., the time when all the current limiting configurations in the preset configuration file are loaded).

[0089] S203: Control the second process to load the current limiting configuration from the shared memory to its own private cache, so as to limit the current of network requests sent to each microservice according to the current limiting configuration in the private cache.

[0090] S204, controlling the second process to record the private loading time of each current limiting configuration loaded into the private cache according to the global loading time of each current limiting configuration loaded into the shared memory, and setting the private update time of the private cache according to the global update time of the shared memory.

[0091] In this step, the second process can set the private loading time of each current limiting configuration loaded into the private cache, adjust the private loading time numerically according to the global loading time, and adjust the private update time of its own private cache numerically according to the global update time. At this time, the private loading time is equal to the global loading time, and the private update time is equal to the global update time.

[0092] S205. Control the first process to determine whether a configuration update request is received, and when a configuration update request is received, use the current limiting configuration in the configuration update request to update the corresponding current limiting configuration in the shared memory, update the global loading time corresponding to the updated current limiting configuration, and update the global update time.

[0093] In this step, after the first process updates the corresponding current limiting configuration in the shared memory using the current limiting configuration in the configuration update request, it can update the global load time corresponding to the updated current limiting configuration to the current time, and update the global update time to the current time. At this time, since the private load time and the private update time have not changed, the private load time corresponding to the updated current limiting configuration is not equal to the corresponding global load time, and the private update time is not equal to the global update time.

[0094] S206, controlling the second process to determine whether the private update time is the same as the global update time; if they are the same, proceeding to S207; if they are not the same, proceeding to S208.

[0095] In this step, the second process can first determine whether the shared memory is updated based on whether the private update time is the same as the global update time. If they are equal, it means that the shared memory has not been updated; if they are equal, it means that the shared memory has been updated.

[0096] S207, determining that the current limiting configuration in the shared memory is not updated;

[0097] S208. Determine that the current limiting configuration in the shared memory has been updated, use the current limiting configuration with a different global loading time and a private loading time as an updated current limiting configuration, load the updated current limiting configuration from the shared memory to the private cache, and numerically adjust the corresponding private loading time according to the global loading time corresponding to the updated current limiting configuration, and numerically adjust the private update time according to the global update time.

[0098] In this step, when the second process determines that the shared memory has been updated, it can further compare whether the global loading time and private loading time of each current limiting configuration are the same. If they are the same, it means that the current limiting configuration has not been updated, and the loading time of the next current limiting configuration can be compared; if they are different, it means that the current limiting configuration has been updated. Subsequently, the second process can use the current limiting configuration with a different global loading time and private loading time as the updated current limiting configuration, load the updated current limiting configuration from the shared memory to the private cache, and numerically adjust the corresponding private loading time according to the global loading time corresponding to the updated current limiting configuration, and numerically adjust the private update time according to the global update time. At this point, the private loading time is equal to the global loading time again, and the private update time is equal to the global update time again.

[0099] It can be seen that by comparing the time information, the second process can quickly determine whether the shared memory has a current limiting configuration update, and can quickly determine which current limiting configurations are sent for update, thereby improving the efficiency of current limiting configuration update.

[0100] Of course, in order to avoid the second process frequently detecting whether the private update time is the same as the global update time, thereby affecting its working performance, this embodiment can also set a corresponding preset polling time in the preset configuration file. The first process can configure a preset polling time for the second process when the current limiting service is started; and the second process can periodically determine whether the private update time is the same as the global update time according to the preset polling time.

[0101] Based on this, the method may further include:

[0102] Step 31: Control the first process to obtain a preset polling time from a preset configuration file, and configure the preset polling time for the second process;

[0103] Controlling the second process to determine whether the private update time is the same as the global update time, including:

[0104] Step 41: Control the second process to periodically determine whether the private update time is the same as the global update time according to a preset polling time.

[0105] It should be noted that the present embodiment does not limit the specific value of the preset polling time, and it can be set according to actual application requirements.

[0106] Based on the above embodiment, the specific process of the second process performing microservice current limiting is introduced below. In one possible scenario, current limiting of network requests sent to each microservice according to the current limiting configuration in the private cache may include:

[0107] S301. Control the second process to receive a network request, and determine a target microservice for receiving the network request according to a microservice identifier in the network request.

[0108] In this step, when the second process receives the network request, it can determine the target microservice that receives the network request according to the microservice identifier in the request, wherein the microservice identifier is used to uniquely identify the microservice.

[0109] It should be noted that this embodiment does not limit the specific form of the microservice identifier, which can be set according to actual application requirements.

[0110] S302: Determine the current limiting algorithm and current limiting parameters corresponding to the target microservice according to the current limiting configuration corresponding to the target microservice in the private cache;

[0111] In this step, the second process can search for the current limiting configuration of the target microservice, and determine the current limiting algorithm and current limiting parameters corresponding to the target microservice according to the current limiting configuration, so as to perform targeted current limiting on the target microservice.

[0112] S303: Perform current limiting detection on the network request using the current limiting algorithm and current limiting parameters to determine whether the network request triggers current limiting.

[0113] In this step, the second process uses the current limiting algorithm and current limiting parameters to perform current limiting detection on the network request, and determines whether the current network request triggers current limiting. If current limiting is not triggered, the second process can release the network request to the target microservice. On the contrary, if current limiting is triggered, the second process needs to perform exception processing on the network request.

[0114] It should be noted that this embodiment does not limit the specific current limiting algorithm, which can be set according to actual application requirements. For example, current limiting can be performed based on QPS, or based on time period. The following is a specific implementation method of current limiting based on QPS:

[0115] Based on this, the current limiting algorithm and current limiting parameters are used to perform current limiting detection on network requests, which may include:

[0116] Step 51: Control the second process in each preset time slice. If the microservice receives a network request in the preset time slice, the flow number of the preset time slice is increased by one. If the microservice completes a network request in the preset time slice, the flow number of the preset time slice is reduced by one.

[0117] Step 52: Count the total traffic of multiple consecutive preset time slices, and when it is determined that the total traffic exceeds the preset total traffic threshold, determine that the current network request triggers traffic limiting;

[0118] It can be seen that this embodiment can control the amount of network requests being processed by the microservice within the preset threshold, so that it can cope with both traffic peaks and continuous traffic mutations. It should be noted that this embodiment does not limit the duration of each preset time slice, nor does it limit the number of preset time slices used when counting the total traffic volume, which can be set according to actual application requirements. For example, 1 second can be divided into 10 time slices, that is, one group of 100 milliseconds. When each request enters, the traffic in the slice is +1, and when the request ends, the traffic in the slice is -1. When the amount of requests in 100 seconds exceeds the threshold / 10, the flow limit is triggered.

[0119] Of course, the above method can also be further combined with IP features. For example, in each preset time slice of the second process, if the microservice receives a network request in the preset time slice, and the network request belongs to the specified IP, then the flow number of the specified IP in the preset time slice is increased by one, and if the microservice completes a network request of the specified IP in the preset time slice, then the flow number of the specified IP in the preset time slice is increased by one. Then, the total flow number of the specified IP in multiple consecutive preset time slices is counted, and when it is determined that the total flow number exceeds the preset total flow threshold, it is determined that the current network request of the specified IP triggers current limiting. In this way, frequent sniffing of network interfaces by malicious IPs can be effectively dealt with.

[0120] The following is a specific implementation method for current limiting based on time periods:

[0121] Based on this, the current limiting algorithm and current limiting parameters are used to perform current limiting detection on network requests, which may include:

[0122] Step 61: Control the second process to count the total number of network requests received by the microservice in a preset time period, and when it is determined that the total number exceeds a preset total number threshold, determine that the current network request triggers current limiting.

[0123] It can be seen that this embodiment can control the amount of network requests that a microservice can receive within a preset time period within a preset threshold. This embodiment does not limit the specific duration of the preset time period. For example, flow limiting can be performed according to four time period types: seconds, minutes, hours, and days. For example, flow limiting is defined as limiting 100 requests in a 2-minute time period. If the number of requests exceeds 100 within two minutes, flow limiting is triggered.

[0124] S304: If the network request does not trigger current limiting, the network request is released to the target microservice.

[0125] S305: If the network request triggers current limiting, perform exception processing on the network request.

[0126] It should be noted that this embodiment does not limit the specific method of exception handling, which can be set according to actual application requirements. For example, the network request can be directly intercepted; for another example, if it is necessary to further observe the attack mode to better protect the microservice, the observation mode can be enabled for the target microservice, and when the mode is enabled, the network request is sent to the target microservice, and the abnormal alarm information is output to prompt the operation and maintenance personnel to conduct on-site analysis.

[0127] Based on this, exception handling for network requests can include:

[0128] Step 71: Control the second process to determine whether the target microservice has enabled the observation mode according to the current limiting configuration corresponding to the target microservice in the private cache; if enabled, proceed to step 72; if not, proceed to step 73:

[0129] Step 72: Send the network request to the target microservice and output abnormal warning information;

[0130] Step 73: Disable network requests from being sent to the target microservice.

[0131] Based on the above embodiment, the above microservice current limiting method is introduced below based on a specific schematic diagram. In this example, the current limiting device can be Nginx.

[0132] This solution involves four aspects: service loading and starting, service flow control, dynamic adjustment of flow control strategy, and timed polling and updating of flow control strategy. The specific implementation details are as follows.

[0133] 1. Service loading and startup:

[0134] When Nginx starts, it registers and loads the microservices provided to the outside world. At the same time, it initializes the flow control strategy of each microservice so that it can perform flow control checks when requests come in. Please refer to Figure 2 , Figure 2 This is a flow chart of service loading and starting provided by an embodiment of the present invention. The steps of this stage are as follows:

[0135] A) Read the sgmetadata.json and sgtraffic.json files (preset configuration files) in the host directory where the Nginx service is located, and load the microservice and current limiting information into the LUA shared memory;

[0136] B) Read the config.json file to obtain the preset polling time for each Nginx worker process to poll whether the current limiting policy has changed. The worker process is the second process.

[0137] C) Each Nginx worker process initializes the current limiting object to Lua_LRU_Cache (private cache) based on the microservice current limiting strategy in the LUA shared cache.

[0138] 2. Service flow control:

[0139] Please refer to Figure 3 , Figure 3 A flow chart of service flow limiting control provided by an embodiment of the present invention.

[0140] A) The Nginx worker process receives a microservice request and checks whether there is a current limiting object for the microservice;

[0141] B) If it exists, check whether flow control is needed according to the flow control strategy of the flow control object. Currently, the system provides three algorithms based on QPS, time period, and request source IPQPS, which are introduced as follows:

[0142] 1) QPS: Check the number of visits per second based on a single microservice. Slice 10 time periods within 1 second, that is, one group every 100 milliseconds. When each request comes in, the flow in the slicing is increased by 1, and when the request ends, the flow is reduced by 1. When the number of requests in 100 seconds exceeds the threshold / 10, the flow limit is triggered. This algorithm can cope with both traffic peaks and continuous traffic mutations.

[0143] 2) Time period: Check the access volume based on the set time period. Currently, four time period types are supported: ** seconds, ** minutes, ** hours, and ** days. For example, if the flow limit is defined as 100 in a 2-minute time period, the flow limit will be triggered when the number of requests for memory exceeds 100 within two minutes.

[0144] 3) Request source IP QPS: This algorithm adds the source IP feature based on 1), that is, recording the QPS of a specific source IP to a certain microservice. The judgment algorithm refers to 1). This algorithm can effectively deal with frequent sniffing of login interfaces by malicious IPs.

[0145] C) If there is no current limiting strategy or the current limiting threshold is not exceeded, the microservice execution phase is directly entered;

[0146] D) If the current limit threshold is exceeded, check the current processing strategy and respond:

[0147] 1) Observer mode: only records and reports the trigger flow control, does not intercept the request, and the request continues to enter the microservice execution phase;

[0148] 2) Intercept mode: intercept and return exception information to the requester, and report to trigger flow control. The custom exception number and custom exception prompt information are both derived from the flow control definition, so as to provide more accurate feedback to the requester.

[0149] E) The system administrator receives the reported current limiting alarm and can take further action, for example:

[0150] 1) The backend service resources are still sufficient, so the current limiting strategy is adjusted;

[0151] 2) Insufficient backend service resources, and solutions such as application expansion and adding new servers are used to cope with traffic growth;

[0152] 3) Malicious attacks: Block malicious requests through security protection, WAF interception, etc.

[0153] 3. Dynamically adjust the current limiting threshold:

[0154] When the backend service resources are sufficient or insufficient, the administrator can dynamically adjust the microservice current limit threshold after analysis to cope with traffic growth and ensure the normal operation of core microservices. Figure 4 , Figure 4 This is a flow chart of dynamically adjusting the current limiting threshold provided by an embodiment of the present invention. This section only describes the dynamic adjustment of the current limiting threshold in this solution.

[0155] A) The Nginx routing synchronization management API receives a request from the system administrator to adjust the current limit of a certain microservice;

[0156] B) The system loop compares the change list in the request with the data in the LUA shared cache to see if they are consistent;

[0157] C) If they are consistent, no update is performed;

[0158] D) If they are inconsistent, update the local sgtraffic.json file first so that the current limiting information can be initialized directly based on this file when the Nginx service is started next time;

[0159] E) Then update the current limiting data for the service in the LUA shared cache, record the update time, and adjust the global system-level update time.

[0160] 4. Regularly poll and update the current limiting strategy

[0161] Please refer to Figure 5 , Figure 5 A flowchart of a timed polling and updating current limiting strategy provided by an embodiment of the present invention.

[0162] A) The Nginx worker process periodically polls the thread to check whether the system-level update time is consistent with the last update time of this process;

[0163] B) If they are consistent, it is considered that the infinite flow strategy is adjusted during this polling period;

[0164] C) If they are inconsistent, loop to check whether the last modification time of each microservice in Lua_LRU_Cache is consistent with the last update time in the shared cache;

[0165] D) If the last modification time of a Lua_LRU_Cache microservice is earlier than the value in the shared cache, the current limiting object in the original cache is deleted, and a new current limiting object is generated based on the shared cache and placed in the Lua_LRU_Cache cache.

[0166] The following is an introduction to the microservice current limiting device, electronic device, computer program product, and computer-readable storage medium provided in an embodiment of the present invention. The microservice current limiting device, electronic device, computer program product, and computer-readable storage medium described below can correspond to the microservice current limiting method described above.

[0167] Please refer to Figure 6 , Figure 6 This is a structural block diagram of a microservice current limiting device provided by an embodiment of the present invention, and the device may include:

[0168] The shared memory loading module 601 is used to control the first process to load the current limiting configuration corresponding to each microservice from the preset configuration file to the shared memory when the current limiting service is started;

[0169] The current limiting module 602 is used to control the second process to load the current limiting configuration from the shared memory to its own private cache, and to limit the network requests sent to each microservice according to the current limiting configuration in the private cache;

[0170] The shared memory update module 603 is used to control the first process to determine whether a configuration update request is received, and when the configuration update request is received, update the corresponding current limiting configuration in the shared memory using the current limiting configuration in the configuration update request;

[0171] The private cache update module 604 is used to control the second process to determine whether the current limiting configuration in the shared memory is updated, and when it is determined that the current limiting configuration in the shared memory has been updated, load the updated current limiting configuration from the shared memory to the private cache.

[0172] Optionally, the device may further include:

[0173] The preset configuration file updating module is used to control the first process to update the current limiting configuration in the configuration update request to the preset configuration file.

[0174] Optionally, the device may further include:

[0175] A first time recording module, used to control the first process to record the global loading time of each current limiting configuration loaded into the shared memory, and set the global update time of the shared memory to the current time;

[0176] A second time recording module, used to control the second process to record the private loading time of each current limiting configuration loaded into the private cache according to the global loading time of each current limiting configuration loaded into the shared memory, and set the private update time of the private cache according to the global update time of the shared memory;

[0177] A first time update module, used to control the first process to update the global loading time corresponding to the updated current limiting configuration, and to update the global update time;

[0178] Private cache update module, which can include:

[0179] A judgment submodule, used to control the second process to judge whether the private update time is the same as the global update time;

[0180] A determination submodule is used to determine that the current limiting configuration in the shared memory has not been updated if they are the same;

[0181] The update submodule is used to determine that the current limiting configuration in the shared memory has been updated if they are not the same, and use the current limiting configuration with a different global loading time and private loading time as the updated current limiting configuration, load the updated current limiting configuration from the shared memory to the private cache, and numerically adjust the corresponding private loading time according to the global loading time corresponding to the updated current limiting configuration, and numerically adjust the private update time according to the global update time.

[0182] Optionally, the device may further include:

[0183] A polling time setting module, used to control the first process to obtain a preset polling time from a preset configuration file, and configure the preset polling time for the second process;

[0184] The judgment submodule is used to:

[0185] The second process is controlled to periodically determine whether the private update time is the same as the global update time according to a preset polling time.

[0186] Optionally, a shared memory update module includes:

[0187] The receiving and judging submodule is used to control the first process to judge whether a configuration update request is input through a preset API interface.

[0188] Optionally, the current limiting module includes:

[0189] A microservice determination module, used to control the second process to receive the network request, and determine the target microservice for receiving the network request according to the microservice identifier in the network request;

[0190] A current limiting configuration determination module is used to determine the current limiting algorithm and current limiting parameters corresponding to the target microservice according to the current limiting configuration corresponding to the target microservice in the private cache;

[0191] The current limiting judgment module is used to perform current limiting detection on network requests using the current limiting algorithm and current limiting parameters to determine whether the network request triggers current limiting;

[0192] The release module is used to release the network request to the target microservice if the network request does not trigger the current limit;

[0193] The exception handling module is used to handle exceptions to network requests if they trigger current limiting.

[0194] Optionally, the current limiting judgment module includes:

[0195] The traffic statistics submodule is used to control the second process in each preset time slice. If the microservice receives a network request in the preset time slice, the traffic number of the preset time slice is increased by one; if the microservice completes a network request in the preset time slice, the traffic number of the preset time slice is reduced by one;

[0196] The QPS detection submodule is used to count the total traffic of multiple consecutive preset time slices, and when it is determined that the total traffic exceeds the preset total traffic threshold, determine that the current network request triggers the current limit;

[0197] Or, a time period detection submodule is used to control the second process to count the total number of network requests received by the microservice in a preset time period, and when it is determined that the total number exceeds a preset total number threshold, determine that the current network request triggers current limiting.

[0198] Optionally, the exception handling module includes:

[0199] The mode judgment submodule is used to control the second process to judge whether the target microservice is in observation mode according to the current limiting configuration corresponding to the target microservice in the private cache;

[0200] The alarm submodule is used to send network requests to the target microservice and output abnormal alarm information if it is enabled;

[0201] The blocking submodule is used to prohibit network requests from being sent to the target microservice if it is not enabled.

[0202] Please refer to Figure 7 , Figure 7 This is a structural block diagram of a current limiting device provided in an embodiment of the present invention. An embodiment of the present invention provides a current limiting device 10, including a processor 11 and a memory 12; wherein the memory 12 is used to store a computer program; the processor 11 is used to execute the microservice current limiting method provided in the aforementioned embodiment when executing the computer program.

[0203] For the specific process of the above-mentioned microservice current limiting method, please refer to the corresponding content provided in the above-mentioned embodiment, which will not be repeated here.

[0204] Furthermore, the memory 12, as a carrier for storing resources, may be a read-only memory, a random access memory, a magnetic disk or an optical disk, etc., and the storage method may be temporary storage or permanent storage.

[0205] In addition, the current limiting device 10 also includes a power supply 13, a communication interface 14, an input / output interface 15 and a communication bus 16; wherein the power supply 13 is used to provide working voltage for each hardware device on the current limiting device 10; the communication interface 14 can create a data transmission channel between the current limiting device 10 and external devices, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present invention, and is not specifically limited here; the input / output interface 15 is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.

[0206] An embodiment of the present invention further provides a computer program product, including a computer program / instruction, which implements the microservice current limiting method described in the above embodiment when the computer program / instruction is executed by a processor.

[0207] Since the embodiments of the computer program product part correspond to the embodiments of the microservice current limiting method part, please refer to the description of the embodiments of the microservice current limiting method part for the embodiments of the computer program product part, and will not be repeated here.

[0208] An embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the microservice current limiting method described in the above embodiment is implemented.

[0209] Since the embodiments of the computer-readable storage medium part correspond to the embodiments of the microservice current limiting method part, please refer to the description of the embodiments of the microservice current limiting method part for the embodiments of the storage medium part, which will not be repeated here.

[0210] The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description.

[0211] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0212] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0213] The above is a detailed introduction to a microservice current limiting method, device, current limiting device, program product and medium provided by the present invention. This article uses specific examples to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present invention, the present invention can also be improved and modified in a number of ways, and these improvements and modifications also fall within the scope of protection of the present invention.

Claims

1. A microservice current limiting method, characterized in that: include: Control the first process to load the current limiting configuration corresponding to each microservice from the preset configuration file to the shared memory when the current limiting service is started; Control the second process to load the current limiting configuration from the shared memory to its own private cache, and limit the current of network requests sent to each of the microservices according to the current limiting configuration in the private cache; Controlling the first process to determine whether a configuration update request is received, and when the configuration update request is received, updating the corresponding current limiting configuration in the shared memory using the current limiting configuration in the configuration update request; The second process is controlled to determine whether the current limiting configuration in the shared memory is updated, and when it is determined that the current limiting configuration in the shared memory has been updated, the updated current limiting configuration is loaded from the shared memory to the private cache.

2. The microservice current limiting method according to claim 1 is characterized in that: After receiving the configuration update request, the method further includes: Control the first process to update the current limiting configuration in the configuration update request to the preset configuration file.

3. The microservice current limiting method according to claim 1 is characterized in that: After loading the current limiting configuration corresponding to each microservice from the preset configuration file to the shared memory, it also includes: Control the first process to record the global loading time of each current limiting configuration loaded into the shared memory, and set the global update time of the shared memory to the current time; After controlling the second process to load the current limiting configuration from the shared memory to its own private cache, the method further includes: Control the second process to record the private loading time of each current limiting configuration loaded into the private cache according to the global loading time of each current limiting configuration loaded into the shared memory, and set the private update time of the private cache according to the global update time of the shared memory; After the corresponding current limiting configuration in the shared memory is updated using the current limiting configuration in the configuration update request, the method further includes: Controlling the first process to update the global loading time corresponding to the updated current limiting configuration, and updating the global update time; The controlling the second process to determine whether the current limiting configuration in the shared memory is updated, and when it is determined that the current limiting configuration in the shared memory has been updated, loading the updated current limiting configuration from the shared memory to the private cache includes: Controlling the second process to determine whether the private update time is the same as the global update time; If they are the same, it is determined that the current limiting configuration in the shared memory is not updated; If they are not the same, it is determined that the current limiting configuration in the shared memory has been updated, and the current limiting configuration in which the global loading time is different from the private loading time is used as the updated current limiting configuration. The updated current limiting configuration is loaded from the shared memory to the private cache, and the corresponding private loading time is numerically adjusted according to the global loading time corresponding to the updated current limiting configuration, and the private update time is numerically adjusted according to the global update time.

4. The microservice current limiting method according to claim 3 is characterized in that: Also includes: Control the first process to obtain a preset polling time from the preset configuration file, and configure the preset polling time for the second process; The controlling the second process to determine whether the private update time is the same as the global update time includes: The second process is controlled to periodically determine whether the private update time is the same as the global update time according to the preset polling time.

5. The microservice current limiting method according to claim 1 is characterized in that: The controlling the first process to determine whether a configuration update request is received includes: The first process is controlled to determine whether the configuration update request is input through a preset API interface.

6. The microservice current limiting method according to any one of claims 1 to 5, characterized in that: The limiting the flow of network requests sent to each of the microservices according to the flow limiting configuration in the private cache includes: Control the second process to receive a network request, and determine a target microservice for receiving the network request according to a microservice identifier in the network request; Determine the current limiting algorithm and current limiting parameters corresponding to the target microservice according to the current limiting configuration corresponding to the target microservice in the private cache; Performing current limiting detection on the network request using the current limiting algorithm and the current limiting parameters to determine whether the network request triggers current limiting; If the network request does not trigger current limiting, the network request is released to the target microservice; If the network request triggers current limiting, the network request is handled as an exception.

7. The microservice current limiting method according to claim 6 is characterized in that: The using the current limiting algorithm and the current limiting parameters to perform current limiting detection on the network request includes: Control the second process in each preset time slice, if the microservice receives a network request in the preset time slice, then increase the flow number of the preset time slice by one, if the microservice completes a network request in the preset time slice, then reduce the flow number of the preset time slice by one; Counting the total traffic of a plurality of consecutive preset time slices, and when it is determined that the total traffic exceeds a preset total traffic threshold, determining that the current network request triggers traffic limiting; Or, control the second process to count the total number of network requests received by the microservice in a preset time period, and when it is determined that the total number exceeds a preset total number threshold, determine that the current network request triggers current limiting.

8. The microservice current limiting method according to claim 6 is characterized in that: The performing exception processing on the network request includes: Control the second process to determine whether the target microservice opens the observation mode according to the current limiting configuration corresponding to the target microservice in the private cache; If enabled, the network request is sent to the target microservice and an abnormal warning message is output; If not enabled, the network request is prohibited from being sent to the target microservice.

9. A microservice current limiting device, characterized in that: include: A shared memory loading module is used to control the first process to load the current limiting configuration corresponding to each microservice from a preset configuration file to the shared memory when the current limiting service is started; A current limiting module, used to control the second process to load the current limiting configuration from the shared memory to its own private cache, and to limit the network requests sent to each of the microservices according to the current limiting configuration in the private cache; A shared memory update module, used to control the first process to determine whether a configuration update request is received, and when the configuration update request is received, update the corresponding current limiting configuration in the shared memory using the current limiting configuration in the configuration update request; The private cache update module is used to control the second process to determine whether the current limiting configuration in the shared memory is updated, and when it is determined that the current limiting configuration in the shared memory has been updated, load the updated current limiting configuration from the shared memory to the private cache.

10. A current limiting device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the microservice current limiting method as described in any one of claims 1 to 8 when executing the computer program.

11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are loaded and executed by the processor, the microservice current limiting method according to any one of claims 1 to 8 is implemented.

12. A computer program product comprising a computer program or instructions, characterized in that When the computer program or instruction is executed by a processor, the microservice current limiting method as described in any one of claims 1 to 8 is implemented.