A current limiting method, device, equipment and storage medium
By setting the label of the current limiting service in the service system and deciding whether to limit the current according to its current limiting status, the problem of poor stability of the service system in high concurrency scenarios is solved, and the effect of improving the stability of the service system is achieved.
Patent Information
- Application Number
- CN201911032324.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-10-28
- Publication Date
- 2025-06-17
- Estimated Expiration
- 2039-10-28
AI Technical Summary
In high concurrency scenarios, the service system has poor stability and can easily lead to downtime or crash.
By setting the tag of the current limit service when the service system is started, when the access request of the target service is received, it is determined whether it is a current limit service, and whether it is a current limit service is determined based on its current limit status.
It realizes the flow restriction of the access requests of the target service, protects the stable operation of the service system, and improves the stability of the service system in high concurrency scenarios.
Smart Images

Figure CN112799824B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of Internet technologies, and in particular, to a current-limiting method, apparatus, device, and storage medium. Background Art
[0002] Disruptor is a high-performance asynchronous processing framework and an in-memory message component for efficient low-latency communication between threads. It can achieve a throughput of millions per second and is widely used in major e-commerce service systems.
[0003] However, in the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:
[0004] With the prevalence of online shopping, the frequency of high-concurrency requests is increasing. When the number of concurrent requests exceeds the processing capacity of the service system, it will cause the service system to crash or freeze. Therefore, the existing service systems have poor stability. Summary of the Invention
[0005] Embodiments of the present invention provide a current-limiting method, apparatus, device, and storage medium, and the method can achieve the purpose of improving the stability of the service system.
[0006] In a first aspect, embodiments of the present invention provide a current-limiting method, which includes:
[0007] When receiving an access request for a target service, determining whether the target service is a current-limiting service marked in a preset storage area;
[0008] If the target service is the current-limiting service, determining whether to limit the access request according to the current-limiting status of the target service;
[0009] Wherein, when the service system starts, the label of the set current-limiting service is mapped to the preset storage area, and the service system is a system that bears the service for processing access requests.
[0010] In a second aspect, embodiments of the present invention further provide a current-limiting apparatus, which includes:
[0011] A service determination module, configured to determine whether a target service is a current-limiting service marked in a preset storage area when receiving an access request for the target service;
[0012] A current-limiting module, configured to determine whether to limit the access request according to the current-limiting status of the target service if the target service is the current-limiting service;
[0013] Wherein, when the service system starts, the label of the set current-limiting service is mapped to the preset storage area, and the service system is a system that bears the service for processing access requests.
[0014] In a third aspect, an embodiment of the present invention further provides a device, which includes:
[0015] One or more processors;
[0016] A memory for storing one or more programs;
[0017] When the one or more programs are executed by the one or more processors, the one or more processors implement the steps of the current limiting method provided in any embodiment of the present invention.
[0018] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, it implements the steps of the current limiting method provided in any embodiment of the present invention.
[0019] The embodiments in the above invention have the following advantages or beneficial effects:
[0020] When receiving an access request for a target service, first determine whether the target service is a current limiting service marked in a preset storage area; if the target service is the current limiting service, determine whether to limit the access request according to the current limiting state of the target service; wherein, when the service system starts, map the label of the set current limiting service to the preset storage area, and the service system is a system that bears the service for processing access requests. By this technical means, the purpose of limiting the access request for the target service is achieved, and the technical effect of protecting the stable operation of the target service is achieved by limiting the access request for the target service. Furthermore, the technical problem of poor stability of the service system in a high-concurrency scenario is solved, and the technical effect of improving the stability of the service system is achieved. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1 is a flowchart of a current limiting method provided in Embodiment 1 of the present invention;
[0022] Figure 2 is a schematic diagram of the system architecture of an application current limiting method provided in Embodiment 1 of the present invention;
[0023] Figure 3 is a schematic diagram of the architecture of a current limiting scheme based on Disruptor provided in Embodiment 1 of the present invention;
[0024] Figure 4 is a flowchart of a current limiting method provided in Embodiment 2 of the present invention;
[0025] Figure 5 is a schematic diagram of the structure of a current limiting method device provided in Embodiment 3 of the present invention;
[0026] Figure 6 It is a schematic structural diagram of a device provided in Embodiment 4 of the present invention. Detailed implementation manners
[0027] 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 convenience of description, only the parts related to the present invention rather than all the structures are shown in the drawings.
[0028] Embodiment 1
[0029] Figure 1 It is a flowchart of a current limiting method provided in Embodiment 1 of the present invention. This embodiment is applicable to the situation of appropriately limiting the access requests to a specific service in a high-concurrency scenario. This method can be executed by a current limiting device, which can be implemented in a software and / or hardware manner and is usually integrated into a service system, such as a server. As Figure 1 shown, the method specifically includes the following steps:
[0030] Step 110: When receiving an access request for a target service, determine whether the target service is a current limiting service marked in a preset storage area.
[0031] Among them, when the service system starts, the label of the set current limiting service is mapped to the preset storage area. The service system is a system that bears the service for processing access requests. Each label of the set current limiting service can be generated by a Hash algorithm and is used to identify a unique service.
[0032] The set current limiting service generally refers to a service with high-concurrency access requests. Such services are prone to crashing due to excessive access requests. Therefore, in order to improve the stability of such services, appropriate current limiting can be performed on such services to limit the number of access requests for such services processed per unit time. The set current limiting service can be preset by engineers according to the business scenario. For example, in the business scenario of a certain commodity flash sale, the service for displaying the purchase page of the commodity can be set as the current limiting service.
[0033] Step 120: If the target service is the current limiting service, determine whether to limit the access request according to the current limiting state of the target service.
[0034] Specifically, if the label state of the target service in the preset storage area is the current limiting state, it is determined to limit the access request; otherwise, the access request is not limited.
[0035] Among them, the status of the label includes a current-limiting status and a non-current-limiting status. If the label status of the target service in the preset storage area is the current-limiting status, it means that the number of times the target service is accessed within the current unit time has reached the current-limiting threshold. At this time, if the access request of the target service is continued to be connected to the service system, it is likely to cause the target service to crash. To prevent the target service from crashing and improve the stability of the target service, when the number of times the target service is accessed within the unit time reaches the current-limiting threshold, the access request of the target service is current-limited, that is, the response to new access requests is refused, and new access requests are no longer connected to the service system. The current-limiting threshold is set by engineers according to the stress test results of each service.
[0036] In an embodiment of the present invention, the current-limiting method further includes:
[0037] Real-time statistics of the number of times each service is accessed within the unit time. If the number of times of the target service reaches the current-limiting threshold, the label status of the target service in the preset storage area is changed to the current-limiting status, so as to determine whether to current-limit the access request of the target service based on the label status of the target service, achieving the purpose of improving the stability of the target service and the service system carrying the target service, and solving the technical problem of poor stability of the service system.
[0038] In an embodiment of the present invention, after changing the label status of the target service in the preset storage area to the current-limiting status, the current-limiting method further includes:
[0039] Real-time monitoring of the processing status of the access request of the target service, so as to change the label status of the target service in the preset storage area from the current-limiting status to the non-current-limiting status according to the processing status.
[0040] Exemplarily, real-time monitoring of the processing status of the access request of the target service, so as to change the label status of the target service in the preset storage area from the current-limiting status to the non-current-limiting status according to the processing status, includes:
[0041] Real-time statistics of the numerical value of the unprocessed access requests of the target service;
[0042] If at least one access request of the target service is processed, the statistically counted numerical value is changed;
[0043] When the numerical value is lower than the set threshold, the label status of the target service in the preset storage area is changed to the non-current-limiting status.
[0044] For example, the flow-limiting threshold corresponding to the target service is 1000 times per second, that is, the target service is allowed to be accessed 1000 times per second. Assuming that the access request frequency of the current target service has reached 1000 times per second, that is, the number value of unprocessed access requests is 1000. At this time, the label status of the target service in the preset storage area is changed from the non-flow-limiting state to the flow-limiting state. After that, the access requests of the target service are no longer connected to the service system. When at least one of the 1000 unprocessed access requests is processed, the label status of the target service in the preset storage area is changed from the flow-limiting state to the non-flow-limiting state to continue to connect to new incoming access requests.
[0045] The technical solution of this embodiment realizes the purpose of ensuring that the number of times each service is accessed per unit time does not exceed the flow-limiting threshold, thereby achieving the beneficial effect of improving service stability and solving the technical problem of poor service system stability by means of real-time statistics of the number of times each service is accessed per unit time. If the number of times of the target service reaches the flow-limiting threshold, the label status of the target service in the preset storage area is changed to the flow-limiting state. When an access request for the target service is received, it is determined whether the target service is the flow-limiting service marked in the preset storage area; if the target service is the flow-limiting service and the label status of the target service is the flow-limiting state, the access request is flow-limited.
[0046] In an embodiment of the present invention, refer to Figure 2Schematic diagram of a system architecture applying a current limiting method, specifically including a gateway 210, a current limiting module 220, a control center 230, a service container engine (service Docker) 240, and a service registration module 250. Among them, the gateway 210 is responsible for accessing the access request to the service system or rejecting the access request under the instruction of the current limiting module 220, so that the access request cannot enter the service system; the current limiting module 220 is used to perform current limiting operations according to the current limiting policy issued by the control center. The current limiting policy includes, for example, the current limiting threshold of each service and the specific service that needs to be current limited. Specifically, when the current limiting module 220 monitors that the gateway 210 receives an access request for a target service, it determines whether the target service is the current limited service indicated in the current limiting policy. If so, it further determines the current limiting state of the target service. If the current limiting state of the target service is current limited, it instructs the gateway 210 to reject the access request. If the current limiting state of the target service is not current limited, it instructs 210 to access the access request to the service system and send the access request to the service container engine 240 to process the access request through the target service. The control center 230 is responsible for sending specific current limiting policies to the current limiting module 220. The service container engine 240 is used to carry service application packages to process access requests through specific service application packages. The service registration module 250 is used to register the current limited services indicated by the current limiting policy into the preset storage area of the current limiting module 220 when the system starts. Among them, the control center 231, the current limiting module 220, the service container engine 240, and the service registration module 250 are arranged on the same server to facilitate communication between the control center 231 and each part; the control center 232 is arranged on another server to facilitate engineering personnel to perform manual intervention on the current limiting policy and further improve the stability of the service system. At the same time, to avoid the problem that a server fails and cannot work properly, the control center 232 is arranged in the zookeeper server cluster, which further improves the stability of the entire service system.
[0047] In another embodiment of the present invention, the preset storage area includes a ring buffer RingBuffer under the Disruptor framework. Disruptor is a high-performance asynchronous processing framework. Its internal bounded queue is implemented by a ring buffer RingBuffer, which can be used as a high-performance bounded memory queue. Based on the producer-consumer mode, it can implement a business scenario where one or more producers correspond to multiple consumers, and is suitable for business scenarios with high performance requirements and low latency. For specific reference, see Figure 3 Schematic diagram of a framework of a current limiting scheme based on Disruptor. This framework is integrated into a service system (such as a server), as Figure 3As shown in the figure, it includes: a producer barrier 310, a ring buffer RingBuffer 320, a coordinator 330, a consumer barrier 340, a service container engine (service Docker) 350, and a registration module 360. Among them, the registration module 360 is used to perform a Hash operation on the set rate-limiting service when the service system starts, so as to obtain a unique tag for each set rate-limiting service, and at the same time map the tag of the set rate-limiting service to the ring buffer RingBuffer 320, as Figure 3 shown. Assume that service A, service B, service C, service D, service E, service F, and service N are set rate-limiting services, and their mapped tags in RingBuffer 320 are A, B, C, D, E, F, and N respectively. The ring buffer RingBuffer 320 is used to store the tags of the set rate-limiting services and the status of each tag. The coordinator 330 is used to count the number of times each service is accessed per unit time in real time. When the number reaches the rate-limiting threshold, it updates the corresponding tag status in RingBuffer 320 to the rate-limiting status, and is also used to count the number value of the unprocessed access requests of the target service in real time. If at least one access request of the target service is processed, it changes the counted number value; when the number value is lower than the set threshold, it changes the tag status of the target service in RingBuffer 320 to the non-rate-limiting status. The producer barrier 310 is used to receive the access request of the target service sent from the outside, and determine whether the target service is a rate-limiting service marked in RingBuffer 320. If so, it further judges whether the status of the tag of the target service in RingBuffer 320 is the rate-limiting status. If it is the rate-limiting status, it rejects the access request. If it is not the rate-limiting status, it accesses the access request and sends it to the coordinator 330. After receiving the access request, the coordinator completes the statistics of the number of times the target service is accessed per unit time, and further sends the access request to the consumer barrier 340. The consumer barrier 340 is used to process the access request by calling the matching service based on the received access request, and when at least one access request is processed, it feeds back a message indicating that the access request has been processed to the coordinator 330, so that the coordinator 330 can count the number value of the unprocessed access requests of each service in real time, and update the corresponding tag status in RingBuffer 320 according to this number value. By implementing the rate-limiting method based on Disruptor, while improving the stability of the service system, it also improves the full utilization of the high-performance resources of Disruptor.
[0048] Embodiment 2
[0049] Figure 4The flowchart of a current limiting method provided in the second embodiment of the present invention. Based on the above embodiment, this embodiment further optimizes the current limiting method. Specifically, it adds steps to dynamically adjust the set current limiting service and the current limiting threshold. The advantage of such optimization is that the current limiting policy can be adjusted according to the actual access situation of each service, achieving full utilization of each service resource and system resources. The explanations of the same or corresponding terms as those in the above embodiment will not be elaborated here.
[0050] See Figure 4 , the current limiting method provided in this embodiment specifically includes the following steps:
[0051] Step 410: When receiving an access request for a target service, determine whether the target service is the current limiting service marked in the preset storage area.
[0052] Step 420: If the target service is the current limiting service and it is determined not to limit the current of the target service, send the access request to the consumer thread so that the consumer thread processes the access request by calling the target service.
[0053] Step 430: If the target service is the current limiting service and it is determined to limit the current of the target service, send a prompt message indicating that it cannot be processed to the sender of the access request.
[0054] For example, display an error web page at the sender of the access request, and the error web page displays a prompt message such as "The target page does not exist".
[0055] Step 440: Statistically count the access frequency of each service within a set time period.
[0056] Step 450: Adjust the current limiting service marked in the preset storage area according to the frequency.
[0057] Specifically, adjusting the current limiting service marked in the preset storage area according to the frequency includes:
[0058] If the current service does not belong to the current limiting service already marked in the preset storage area and its access frequency within the set time period exceeds the preset value, add the label of the current service to the preset storage area to mark the current service as the current limiting service;
[0059] If the current service belongs to the current limiting service already marked in the preset storage area and its access frequency within the set time period is lower than the preset value, delete the label of the current service in the preset storage area.
[0060] For example, Service A is a flow-limiting service already marked in the preset storage area, and its flow-limiting threshold is 1000 times per second. Through statistics, it is found that the number of times Service A is accessed per second within a one-month period is 400, which is much lower than its flow-limiting threshold of 1000 times per second, indicating that Service A does not need to be set as a flow-limiting service. At this time, the label of Service A in the preset storage area is deleted. In the opposite case, for example, Service B is not a flow-limiting service marked in the preset storage area. Through statistics, it is found that the number of times Service B is accessed per second within a one-month period reaches 1000, far exceeding its stress test upper limit of 600 times per second. At this time, it indicates that Service B needs to be set as a flow-limiting service, and the label of Service B is mapped to the preset storage area to mark Service B as a flow-limiting service.
[0061] Furthermore, the flow-limiting method may further include:
[0062] According to the occupancy situation of the server system resources, adjust the flow-limiting threshold of the flow-limiting service; for example, assume that the server only hosts Service A, and the flow-limiting threshold of Service A is 1000 times per second. Through business practice, it is found that when the access requests of Service A reach the flow-limiting threshold, there is still surplus in the server's system resources, such as the memory occupancy rate is lower than the threshold, and the CPU usage rate is not high, etc., indicating that the server can still handle more access requests. At this time, the flow-limiting threshold of Service A is appropriately increased.
[0063] The technical solution of this embodiment realizes the purpose of reasonably setting the flow-limiting service by statistically analyzing the access frequency of each service within a set duration and adjusting the flow-limiting service marked in the preset storage area according to the frequency, thereby improving the stability of the service system and the utilization rate of service resources.
[0064] The following is an embodiment of a flow-limiting method device provided by an embodiment of the present invention. This device belongs to the same inventive concept as the flow-limiting methods of the above embodiments. For the details not described in detail in the embodiment of the flow-limiting method device, reference can be made to the embodiments of the above flow-limiting methods.
[0065] Embodiment III
[0066] Figure 5 FIG. 19 is a schematic structural diagram of a flow-limiting device provided by Embodiment III of the present invention. This embodiment is applicable to the situation of appropriately limiting the access requests of specific services in a high-concurrency scenario. The device specifically includes: a service determination module 510 and a flow-limiting module 520.
[0067] Among them, a service determination module 510 is configured to determine whether the target service is a rate-limited service marked in a preset storage area when receiving an access request for the target service; a rate-limiting module 520 is configured to, if the target service is the rate-limited service, determine whether to rate-limit the access request according to the rate-limiting status of the target service; among them, when the service system is started, the label of the set rate-limited service is mapped to the preset storage area, and the service system is a system that bears the service for processing access requests.
[0068] In an embodiment of the present invention, the rate-limiting module 520 is specifically configured to:
[0069] If the label status of the target service in the preset storage area is a rate-limiting status, determine to rate-limit the access request, otherwise do not rate-limit the access request;
[0070] Among them, the status of the label includes a rate-limiting status and a non-rate-limiting status.
[0071] In an embodiment of the present invention, the device further includes:
[0072] A first statistics module is configured to statistically count the number of times each service is accessed within a unit time in real time;
[0073] A first status update module is configured to, if the number of times of the target service reaches a rate-limiting threshold, change the label status of the target service in the preset storage area to a rate-limiting status.
[0074] In an embodiment of the present invention, the device further includes:
[0075] A monitoring module is configured to monitor the processing status of the access request of the target service in real time;
[0076] A second status update module is further configured to change the label status of the target service in the preset storage area from a rate-limiting status to a non-rate-limiting status according to the processing status.
[0077] In an embodiment of the present invention, the second status update module includes:
[0078] A statistics unit is configured to statistically count the numerical value of the number of unprocessed access requests of the target service in real time;
[0079] A first change unit is configured to change the statistically counted numerical value if at least one access request of the target service is processed and completed;
[0080] A second change unit is configured to, when the numerical value is lower than a set threshold, change the label status of the target service in the preset storage area to a non-rate-limiting status.
[0081] In an embodiment of the present invention, the device further includes:
[0082] A sending module, configured to, if it is determined that the target service is not rate-limited, send the access request to a consumer thread, so that the consumer thread processes the access request by calling the target service; if it is determined that the target service is rate-limited, send a preset unprocessable prompt message to the sender of the access request.
[0083] In an embodiment of the present invention, the device further includes:
[0084] A second statistics module, configured to count the access frequency of each service within a set duration;
[0085] An adjustment module, configured to adjust the rate-limited services marked in a preset storage area according to the frequency.
[0086] In an embodiment of the present invention, the adjustment module includes:
[0087] An adding unit, configured to, if the current service does not belong to the rate-limited services already marked in the preset storage area and the access frequency within the set duration exceeds a preset value, add the label of the current service to the preset storage area to mark the current service as a rate-limited service;
[0088] A deleting unit, configured to, if the current service belongs to the rate-limited services already marked in the preset storage area and the access frequency within the set duration is lower than the preset value, delete the label of the current service in the preset storage area.
[0089] In an embodiment of the present invention, the preset storage area includes a RingBuffer, a circular buffer under the Disruptor framework.
[0090] The technical solution of this embodiment, by statistically counting the number of times each service is accessed per unit time in real time, if the number of times of the target service reaches the rate-limiting threshold, changing the label status of the target service in the preset storage area to the rate-limiting status, and when receiving an access request for the target service, determining whether the target service is a rate-limited service marked in the preset storage area; if the target service is the rate-limited service and the label status of the target service is the rate-limiting status, the technical means of rate-limiting the access request realizes the purpose of ensuring that the number of times each service is accessed per unit time does not exceed the rate-limiting threshold, thereby achieving the beneficial effect of improving service stability and solving the technical problem of poor service system stability.
[0091] The rate-limiting device provided by the embodiments of the present invention can execute the rate-limiting method provided by any embodiment of the present invention, and has corresponding functional modules and beneficial effects for executing the rate-limiting method.
[0092] Example 4
[0093] Figure 6 FIG. 5 is a schematic structural diagram of a device provided in Example 4 of the present invention. Figure 6 FIG. 6 shows a block diagram of an exemplary device 12 suitable for implementing the embodiments of the present invention. Figure 6 The shown device 12 is merely an example and should not impose any limitation on the functions and usage scope of the embodiments of the present invention.
[0094] As Figure 6 shown, the device 12 is presented in the form of a general-purpose computing device. The components of the device 12 may include, but are not limited to: one or more processors or processing units 16, a system memory 28, and a bus 18 connecting different system components (including the system memory 28 and the processing unit 16).
[0095] The bus 18 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, a graphics acceleration port, a processor, or a local bus using any of the multiple bus structures. For example, these architectures include, but are not limited to, Industry Standard Architecture (ISA) bus, Micro Channel Architecture (MAC) bus, Enhanced ISA bus, Video Electronics Standards Association (VESA) local bus, and Peripheral Component Interconnect (PCI) bus.
[0096] The device 12 typically includes a variety of computer system-readable media. These media can be any available media accessible by the device 12, including volatile and non-volatile media, removable and non-removable media.
[0097] The system memory 28 may include computer system-readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory 32. The device 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, a storage system 34 may be used for reading and writing on non-removable, non-volatile magnetic media ( Figure 6 not shown, typically referred to as a "hard disk drive"). Although Figure 6 not shown in FIG. 5, a disk drive for reading and writing on a removable non-volatile disk (such as a "floppy disk"), and an optical disk drive for reading and writing on a removable non-volatile optical disk (such as a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to the bus 18 through one or more data media interfaces. The system memory 28 may include at least one program product having a set of program modules (such as a service determination module 510 and a current limiting module 520), and these program modules are configured to execute the functions of the embodiments of the present invention.
[0098] A program / utility 40 having a set of program modules 42 (such as a service determination module 510 and a current limiting module 520) can be stored in, for example, the system memory 28. Such program modules 42 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include the implementation of a network environment. The program modules 42 generally execute the functions and / or methods in the embodiments described in the present invention.
[0099] The device 12 can also communicate with one or more external devices 14 (such as a keyboard, a pointing device, a display 24, etc.), and can also communicate with one or more devices that enable a user to interact with the device 12, and / or communicate with any device that enables the device 12 to communicate with one or more other computing devices (such as a network card, a modem, etc.). Such communication can be carried out through the input / output (I / O) interface 22. Moreover, the device 12 can also communicate with one or more networks (such as a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) through the network adapter 20. As shown in the figure, the network adapter 20 communicates with other modules of the device 12 through the bus 18. It should be understood that although not shown in the figure, other hardware and / or software modules can be used in combination with the device 12, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, etc.
[0100] The processing unit 16 executes various functional applications and data processing by running the programs stored in the system memory 28, such as implementing the steps of a current limiting method provided by the embodiments of the present invention. The method includes:
[0101] When receiving an access request for a target service, determining whether the target service is a current limiting service marked in a preset storage area;
[0102] If the target service is the current limiting service, determining whether to limit the access request according to the current limiting state of the target service;
[0103] Wherein, when the service system starts, the label of the set current limiting service is mapped to the preset storage area, and the service system is a system that bears the service for processing access requests.
[0104] Of course, those skilled in the art can understand that the processor can also implement the technical solutions of the current limiting method provided by any embodiment of the present invention.
[0105] Embodiment Five
[0106] Example 5 of the present invention provides a computer-readable storage medium, on which a computer program is stored. When the program is executed by a processor, it implements the steps of the current limiting method provided in any embodiment of the present invention. The method includes:
[0107] When receiving an access request for a target service, determine whether the target service is a current-limiting service marked in a preset storage area;
[0108] If the target service is the current-limiting service, determine whether to limit the access request according to the current-limiting state of the target service;
[0109] Wherein, when the service system is started, the label of the set current-limiting service is mapped to the preset storage area, and the service system is a system that bears the service for processing access requests.
[0110] The computer storage medium of the embodiment of the present invention can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to: an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples (non-exhaustive list) of the computer-readable storage medium include: an electrical connection having one or more wires, a portable computer disk, 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 disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, the computer-readable storage medium can be any tangible medium that contains or stores a program, and the program can be used by or in combination with an instruction execution system, apparatus, or device.
[0111] The computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, which carries the computer-readable program code. Such a propagated data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal medium can also be any computer-readable medium other than the computer-readable storage medium, and the computer-readable medium can send, propagate, or transmit a program for use by or in combination with an instruction execution system, apparatus, or device.
[0112] The program code included on the computer-readable medium can be transmitted by any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0113] Computer program code for performing the operations of the present invention may be written in one or more programming languages or combinations thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and also including conventional procedural programming languages such as the "C" language or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, executed as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0114] Those of ordinary skill in the art should understand that the above-described modules or steps of the present invention may be implemented using a general-purpose computing device. They may be centralized on a single computing device or distributed across a network of multiple computing devices. Optionally, they may be implemented using program code executable by a computer device, so that they can be stored in a storage device and executed by the computing device, or they may be separately fabricated into individual integrated circuit modules, or multiple modules or steps of them may be fabricated into a single integrated circuit module to be implemented. Thus, the present invention is not limited to any specific combination of hardware and software.
[0115] Note that the above is only a preferred embodiment of the present invention and the technical principles applied. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein. Various obvious changes, re-adjustments, and substitutions can be made by those skilled in the art without departing from the protection scope of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments. Without departing from the concept of the present invention, more other equivalent embodiments may be included, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. A current limiting method, characterized in that, including: When receiving an access request for a target service, determining whether the target service is a rate-limited service marked in a preset storage area; If the target service is the rate-limited service, determining whether to rate-limit the access request according to the rate-limiting status of the target service; Wherein, when the service system is started, the label of the set rate-limited service is mapped to the preset storage area, and the service system is a system that bears the service for processing access requests; The method further includes: statistically counting the number of times each service is accessed within a unit time in real time. If the number of times of the target service reaches the rate-limiting threshold, changing the label status of the target service in the preset storage area to the rate-limiting status; After changing the label status of the target service in the preset storage area to the rate-limiting status, it further includes: Monitoring the processing status of the access request of the target service in real time, so as to change the label status of the target service in the preset storage area from the rate-limiting status to the non-rate-limiting status according to the processing status.
2. The method according to claim 1, characterized in that, Determining whether to rate-limit the access request according to the rate-limiting status of the target service includes: If the label status of the target service in the preset storage area is the rate-limiting status, determining to rate-limit the access request, otherwise not rate-limiting the access request.
3. The method according to claim 1, characterized in that, Monitoring the processing status of the access request of the target service in real time, so as to change the label status of the target service in the preset storage area from the rate-limiting status to the non-rate-limiting status according to the processing status, includes: Statistically counting the numerical value of the number of unprocessed access requests of the target service in real time; If at least one access request of the target service is processed and completed, changing the statistically counted numerical value; When the numerical value is lower than the set threshold, changing the label status of the target service in the preset storage area to the non-rate-limiting status.
4. The method according to any one of claims 1 - 3, characterized in that, It also includes: If it is determined not to rate-limit the target service, sending the access request to a consumer thread, so that the consumer thread processes the access request by calling the target service; If it is determined to rate-limit the target service, sending a set unprocessable prompt message to the sending end of the access request.
5. The method according to any one of claims 1 - 3, characterized in that, It also includes: Statistically counting the access frequency of each service within a set duration; Adjusting the rate-limited services marked in the preset storage area according to the frequency.
6. The method according to claim 5, characterized in that, Adjusting the rate-limited services marked in the preset storage area according to the frequency includes: If the current service does not belong to the rate-limited services already marked in the preset storage area and the access frequency within the set duration exceeds the preset value, adding the label of the current service to the preset storage area to mark the current service as a rate-limited service; If the current service belongs to the rate-limited services already marked in the preset storage area and the access frequency within the set duration is lower than the preset value, deleting the label of the current service in the preset storage area.
7. The method according to any one of claims 1 - 3, characterized in that, The preset storage area includes a RingBuffer, a circular buffer area under the Disruptor framework.
8. A current limiting device, characterized in that, including: A service determination module, configured to determine whether the target service is a rate-limited service marked in a preset storage area when receiving an access request for the target service; A current-limiting module, configured to determine whether to limit the access request according to the current-limiting status of the target service if the target service is the current-limiting service; Wherein, when the service system is started, the label of the set current-limiting service is mapped to the preset storage area, and the service system is a system that bears the service for processing access requests; The device further includes: A first statistics module, configured to statistically count the number of times each service is accessed per unit time in real time; A first status update module, configured to change the label status of the target service in the preset storage area to the current-limiting status if the number of times of the target service reaches the current-limiting threshold; The device further includes: A monitoring module, configured to monitor the processing status of the access request of the target service in real time; A second status update module, further configured to change the label status of the target service in the preset storage area from the current-limiting status to the non-current-limiting status according to the processing status.
9. A device, characterized in that, The device includes: One or more processors; A memory, configured to store one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the current-limiting method steps described in any one of claims 1-7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, the current-limiting method steps described in any one of claims 1-7 are implemented.
Citation Information
Patent Citations
Access request processing method and apparatus, and server
CN106375472A