Service request processing method and device, electronic equipment and computer storage medium
By serializing the service requests on the server side and determining whether to store service requests based on the total number of requests and the time difference threshold, fine-grained interface current limiting is achieved, and the existing current limiting algorithms perform poorly in the face of traffic peaks and cross-time traffic exceeding limits, improving system performance.
Patent Information
- Application Number
- CN202411833763.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-12
- Publication Date
- 2025-05-09
AI Technical Summary
Existing current limiting algorithms perform poorly in the face of traffic flood peaks and cross-time traffic exceeding limits, and complex transaction operations affect system performance.
By serializing the service requests on the server side, and determining whether to store service requests based on the total number of requests and the time difference threshold, fine-grained interface current limit is achieved.
It effectively solves the problems of traffic flood peaks and cross-time traffic exceeding limits, improves the system's performance in emergencies, and simplifies the processing of traffic data.
Smart Images

Figure CN119966897A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of network application technology, and in particular to a method for processing a service request, a device for processing a service request, an electronic device and a computer-readable storage medium. Background Art
[0002] In a distributed system, in order to ensure the stability and reliability of the system, it is necessary to limit the flow of requests entering the system to prevent the system from crashing due to overload.
[0003] Common current limiting algorithms are as follows:
[0004] 1) Leaky Bucket Algorithm: Requests are placed in a bucket, which leaks requests at a fixed rate. When the bucket is full, new requests will be discarded.
[0005] 2) Token Bucket Algorithm: Tokens are put into the bucket at a fixed rate, and requests need to consume tokens to pass. When the tokens in the bucket are used up, subsequent requests will be rejected.
[0006] 3) Counter Algorithm / Fixed Time Window Algorithm (Counter Algorithm): Record the number of requests per unit time. When the number of requests exceeds the set threshold, reject subsequent requests. Sliding Window Algorithm (Sliding Window Algorithm): Divide time into windows of fixed size, maintain a counter in each window, and use sliding windows to count the number of requests per unit time, thereby achieving current limiting.
[0007] Assuming the current limiting rule is 60 requests per minute, the conventional current limiting algorithm has the following problems:
[0008] Traffic peak problem: The leaky bucket algorithm can only pass requests at a fixed rate (assuming one request per second). If 30 requests arrive at the same time in a minute, it takes 30 seconds to process them. The burst performance is very poor, and it is almost impossible to implement fine-grained interface current limiting.
[0009] Cross-time traffic excess problem: The token bucket algorithm and counter algorithm can solve the traffic peak problem, but if the request traffic is concentrated before and after the token is issued / counter is reset, such as the token is issued once a minute / counter is reset once a minute, and a large number of requests arrive at the 59th second and the 61st second respectively, the traffic passing through at this time will exceed the limit.
[0010] Performance issues: Distributed systems involve concurrent scenarios. The statistics, comparisons, and updates of traffic data often require complex transaction operations or are guaranteed by distributed locks. The current limiting algorithm will instead affect the system's performance in processing traffic. Summary of the invention
[0011] In view of the above problems, embodiments of the present invention are proposed to provide a method for processing a service request, a device for processing a service request, an electronic device and a computer-readable storage medium that overcome the above problems or at least partially solve the above problems.
[0012] In order to solve the above problem, an embodiment of the present invention discloses a method for processing a service request, the method comprising:
[0013] When the current service request is obtained, the total number of historical requests is updated based on the service request to obtain the total number of current requests;
[0014] If the total number of current requests is less than the total number of requests threshold, storing the service request as a pending service request in a target storage location;
[0015] If the current total number of requests is not less than the total number of requests threshold, determining whether a storage requirement for storing the business request in the target storage location is met;
[0016] If satisfied, the business request is stored in the target storage location as a pending business request;
[0017] If not satisfied, the service request is discarded, and the current total number of requests is updated to the total number of historical requests.
[0018] In one or more embodiments, determining whether a storage requirement for storing the service request in the target storage location is met includes:
[0019] Determine the target historical service request based on the total number of requests threshold;
[0020] If the target historical service request has not expired, determining the time difference between the service request and the target historical service request;
[0021] If the time difference is greater than the time difference threshold, the storage requirement is met;
[0022] If the time difference is not greater than the time difference threshold, the storage requirement is not met.
[0023] In one or more embodiments, storing the service request as a pending service request in a target storage location includes:
[0024] Using the total number of current requests as the sequence number of the service request;
[0025] The service request including the sequence number is stored in a target storage location, and the request time of the service request is recorded.
[0026] In one or more embodiments, determining the time difference between the service request and the target historical service request includes:
[0027] Calculate the difference between the current total number of requests and the total number of requests threshold to obtain the target historical business requests;
[0028] If the target historical service request has not expired, obtaining the request time of the target historical service request from the target storage location;
[0029] The time difference between the request time of the service request and the request time of the target historical service request is calculated.
[0030] In one or more embodiments, further comprising:
[0031] If the target historical service request has expired, the storage requirement is met.
[0032] In one or more embodiments, the expiration time of the service request is greater than a time difference threshold.
[0033] In one or more embodiments, the target storage location comprises a distributed logical queue.
[0034] Accordingly, an embodiment of the present invention discloses a device for processing a service request, the device comprising:
[0035] The acquisition module is used to obtain the current business request;
[0036] An updating module, used to update the total number of historical requests based on the business request to obtain the total number of current requests;
[0037] A storage module, configured to store the service request as a pending service request in a target storage location if the current total number of requests is less than a total number of requests threshold;
[0038] A determination module, configured to determine whether a storage requirement for storing the service request in the target storage location is met if the current total number of requests is not less than the total number of requests threshold;
[0039] If satisfied, calling the storage module;
[0040] A discarding module, used for discarding the service request if the conditions are not met;
[0041] The updating module is further used to update the current total number of requests to the total number of historical requests.
[0042] In one or more embodiments, the determining module includes:
[0043] A first processing submodule, configured to determine a target historical service request based on the total number of requests threshold;
[0044] A second processing submodule, configured to determine a time difference between the service request and the target historical service request if the target historical service request has not expired;
[0045] A third processing submodule, configured to determine that the storage requirement is met if the time difference is greater than a time difference threshold;
[0046] The fourth processing submodule is configured to determine that the storage requirement is not met if the time difference is not greater than the time difference threshold.
[0047] In one or more embodiments, the storage module is specifically used for:
[0048] Using the total number of current requests as the sequence number of the service request;
[0049] The service request including the sequence number is stored in a target storage location, and the request time of the service request is recorded.
[0050] In one or more embodiments, the second processing submodule is specifically configured to:
[0051] Calculate the difference between the current total number of requests and the total number of requests threshold to obtain the target historical business requests;
[0052] If the target historical service request has not expired, obtaining the request time of the target historical service request from the target storage location;
[0053] The time difference between the request time of the service request and the request time of the target historical service request is calculated.
[0054] In one or more embodiments, further comprising:
[0055] The fifth processing submodule is used to determine whether the storage requirement is met if the target historical service request has expired.
[0056] In one or more embodiments, the expiration time of the service request is greater than a time difference threshold.
[0057] In one or more embodiments, the target storage location comprises a distributed logical queue.
[0058] Accordingly, an embodiment of the present invention discloses an electronic device, comprising: a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program implements the various steps of the above-mentioned service request processing method embodiment when executed by the processor.
[0059] Accordingly, an embodiment of the present invention discloses a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, each step of the above-mentioned embodiment of the method for processing a business request is implemented.
[0060] The embodiments of the present invention include the following advantages:
[0061] When the server obtains the current business request, the total number of historical requests is updated based on the business request to obtain the current total number of requests; if the current total number of requests is less than the total number of requests threshold, the business request is stored in the target storage location as a pending business request; if the current total number of requests is not less than the total number of requests threshold, it is determined whether the storage requirements for storing the business request in the target storage location are met; if it is met, the business request is stored in the target storage location as a pending business request; if it is not met, the business request is discarded, and the current total number of requests is updated to the total number of historical requests. Through the above method, when the server processes the business request, it can determine whether the business request needs to be limited by the sequence number or request time of the business request. In this way, even in the face of traffic peaks, fine-grained interface current limiting can be achieved, and the burst performance is better. Moreover, when limiting the flow, accurate current limiting can be performed according to the number of business requests, thereby solving the problem of cross-time traffic overlimit. At the same time, the transaction operation of traffic data can be realized through addition and subtraction operations, without the need for complex transaction operations, which improves the processing performance of business requests. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] Figure 1 It is a flowchart of a method for processing a service request according to an embodiment of the present invention;
[0063] Figure 2 It is a schematic diagram of a scene mode of the present invention;
[0064] Figure 3 It is a structural block diagram of an embodiment of a device for processing a service request of the present invention. DETAILED DESCRIPTION
[0065] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0066] One of the core concepts of the embodiments of the present invention is that when the server processes a service request, it can determine whether the service request needs to be limited by the sequence number or request time of the service request. In this way, even in the face of a traffic peak, fine-grained interface current limiting can be achieved, and the burst performance is better. Moreover, when limiting the flow, accurate current limiting can be performed according to the number of service requests, thereby solving the problem of excessive traffic across time. At the same time, the transaction operation of traffic data can be achieved through addition and subtraction operations, without the need for complex transaction operations, thereby improving the processing performance of service requests.
[0067] Reference Figure 1 , which shows a flow chart of steps of an embodiment of a method for processing a service request of the present invention. The embodiment of the present invention can be applied to a server. Figure 2 , shows a schematic diagram of a scenario mode of an embodiment of the present invention, a service system can be deployed in the server, the server can interact with the terminal for data, and the user can initiate a service request to the server through the terminal, wherein the terminal can have the following characteristics:
[0068] (1) In terms of hardware system, the device has a central processing unit, memory, input components and output components, that is, the device is often a microcomputer device with communication function. In addition, it can also have multiple input methods, such as keyboard, mouse, touch screen, microphone and camera, and the input can be adjusted as needed. At the same time, the device often has multiple output methods, such as receiver, display screen, etc., which can also be adjusted as needed;
[0069] (2) In terms of software system, the device must have an operating system, such as Windows Mobile, Symbian, Palm, Android, iOS, etc. At the same time, these operating systems are becoming more and more open, and personalized applications developed based on these open operating system platforms are emerging in an endless stream, such as address books, calendars, notepads, calculators, and various games, which greatly meet the needs of personalized users;
[0070] (3) In terms of communication capabilities, the device has flexible access methods and high-bandwidth communication performance, and can automatically adjust the selected communication method according to the selected service and the environment, so as to facilitate user use. The device can support 3GPP (3rd Generation Partnership Project), 4GPP (4th Generation Partnership Project), 5GPP (5th Generation Partnership Project), LTE (Long Term Evolution), WIMAX (World Interoperability for Microwave Access) mobile communications, computer network communications based on TCP / IP (Transmission Control Protocol / Internet Protocol) and UDP (User Datagram Protocol) protocols, and short-range wireless transmission methods based on Bluetooth and infrared transmission standards. It not only supports voice services, but also supports a variety of wireless data services;
[0071] (4) In terms of functional use, the equipment pays more attention to humanization, personalization and multi-functionality. With the development of computer technology, the equipment has moved from a "device-centric" model to a "people-centric" model, integrating embedded computing, control technology, artificial intelligence technology and biometric authentication technology, fully reflecting the people-oriented purpose. Due to the development of software technology, the equipment can adjust the settings according to personal needs and become more personalized. At the same time, the equipment itself integrates a lot of software and hardware, and its functions are becoming more and more powerful.
[0072] It should be noted that the server can interact with multiple terminals. In the embodiment of the present invention, data interaction between the server and one terminal is taken as an example. In actual applications, the specific number of terminals that interact with the server can be set according to actual needs, and the embodiment of the present invention does not limit this.
[0073] The method may specifically include the following steps:
[0074] Step 101: When a current service request is obtained, the total number of historical requests is updated based on the service request to obtain the total number of current requests.
[0075] The user can trigger a service request in the terminal, and the terminal can send the service request to the server. After obtaining the service request, the server can update the total number of historical requests according to the service request, thereby obtaining the updated total number of requests (for easy distinction, recorded as "current total number of requests").
[0076] The total number of historical requests may be the total number of all service requests obtained before the service request is obtained.
[0077] For example, before obtaining the current business request, the server has obtained a total of 100 business requests, so the total number of historical requests is 100. After obtaining the current business request, the total number of historical requests is updated, that is, the total number of historical requests is increased by 1, and the updated total number of current requests is 101.
[0078] Step 102: If the current total number of requests is less than the total number of requests threshold, the service request is stored in a target storage location as a pending service request.
[0079] If the current total number of requests is less than the preset total number of requests threshold, it means that the number of pending business requests in the server is small and there is no need to limit the flow of business requests. Therefore, the acquired business requests can be stored as pending business requests in a preset storage location (referred to as the "target storage location"). The server can process each pending business request in the target storage location according to the sequence number of the business request.
[0080] In the embodiment of the present invention, storing the service request as a pending service request in a target storage location includes:
[0081] Using the total number of current requests as the sequence number of the service request;
[0082] The service request including the sequence number is stored in a target storage location, and the request time of the service request is recorded.
[0083] Specifically, in order to ensure the order of each business request, the server can use the updated current total number of requests as the serial number of the business request after determining that the current total number of requests is less than the total number of requests threshold, and then store the business request in the target storage location. At the same time, record the request time of the business request in the target storage location.
[0084] Among them, the request time of the service request can be based on the time when the server receives the service request, or it can be based on the time when the terminal initiates the service request. In actual applications, the specific request time of the service request can be set according to actual needs, and the embodiment of the present invention does not limit this.
[0085] For example, continuing with the previous example, the preset total request threshold is 150, and the updated current total request is 101. Since the current total request is less than the total request threshold, "101" is used as the serial number of the business request, indicating the 101th business request, and then the 101th business request is stored in the preset target storage location. At the same time, the request time of the 101st business request is recorded in the target storage location.
[0086] Step 103: If the current total number of requests is not less than the total number of requests threshold, determine whether the storage requirement for storing the business request in the target storage location is met.
[0087] Since the pending business requests in the target storage location will be processed in sequence and the sequence number of each business request will not change, it is possible that the current total number of requests is not less than the total number of requests threshold, but the number of business requests in the target storage location is small, and thus no current limiting is required. In other words, if the current total number of requests is not less than the total number of requests threshold, it is necessary to further determine whether the storage requirements for storing the business requests in the target storage location are met.
[0088] In the embodiment of the present invention, the determining whether the storage requirement for storing the service request in the target storage location is met includes:
[0089] Determine the target historical service request based on the total number of requests threshold;
[0090] If the target historical service request has not expired, determining the time difference between the service request and the target historical service request;
[0091] If the time difference is greater than the time difference threshold, the storage requirement is met;
[0092] If the time difference is not greater than the time difference threshold, the storage requirement is not met.
[0093] Specifically, after obtaining the serial number of the service request, the historical service request (referred to as “target historical request”) to be compared may be determined according to the serial number of the service request and the total number of requests threshold.
[0094] If the target historical business request has not expired, then the time difference between the business request and the target historical business request can be calculated. If the time difference is greater than the preset time difference threshold, it means that the storage requirements for storing the business request in the target storage location are met. If the time difference is not greater than the time difference threshold, it means that the storage requirements for storing the business request in the target storage location are not met.
[0095] In the embodiment of the present invention, determining the time difference between the service request and the target historical service request includes:
[0096] Calculate the difference between the current total number of requests and the total number of requests threshold to obtain the target historical business requests;
[0097] Obtaining the request time of the target historical service request from the target storage location;
[0098] The time difference between the request time of the service request and the request time of the target historical service request is calculated.
[0099] Specifically, after obtaining the serial number of the business request, the difference between the serial number of the business request and the total request threshold can be calculated to obtain the target historical business request with the difference as the serial number, and then the request time of the target historical business request is obtained from the target storage location, as well as the request time of the business request, and the time difference between the request time of the business request and the request time of the target historical business request is calculated.
[0100] For example, the preset current limiting rule is that no more than 3 business requests are made in 1 second, that is, the time difference threshold is 1 second, and the total number of requests threshold is 3. When the 4th business request is obtained, the difference between the serial number of the business request and the total number of requests threshold is calculated, that is, 4-3=1, and the historical business request with serial number 1 is used as the target historical business request, that is, the 1st business request, and then it is determined whether the 1st business request is expired. If not expired, the time difference between the request time of the 4th business request and the 1st business request can be calculated. If the time difference is greater than the time difference threshold, that is, the time difference is greater than 1 second, then the 4th business request meets the storage requirements for storage in the target storage location.
[0101] Step 104: If satisfied, the service request is stored in a target storage location as a pending service request.
[0102] If it is determined that the business request meets the storage requirements of the target storage location, the acquired business request can be stored in the preset target storage location as a pending business request. The server can process each pending business request in the target storage location according to the sequence number of the business request.
[0103] For example, continuing with the previous example, if the time difference between the request time of the fourth business request and the request time of the first business request is greater than 1 second, then the fourth business request can be stored in the target storage location as a pending business request.
[0104] Step 105: If not satisfied, the service request is discarded, and the current total number of requests is updated to the total number of historical requests.
[0105] If it is determined that the service request does not meet the storage requirements for storage in the target storage location, the service request can be discarded, and the current total number of requests is updated to the total number of historical requests, that is, the service request is deleted from the total number of requests.
[0106] For example, continuing with the previous example, after obtaining the 5th business request, the current total number of requests is updated from 4 (the total number of historical requests) to 5. The time difference between the request time of the 5th business request and the request time of the 2nd business request is calculated. Since the time difference is less than 1 second, the 5th business request does not meet the storage requirements for storage in the target storage location. Therefore, the current total number of requests is reduced by 1 to obtain the total number of historical requests, which is 4.
[0107] In an embodiment of the present invention, when the service end obtains the current service request, the total number of historical requests is updated based on the service request to obtain the current total number of requests; if the current total number of requests is less than the total number of requests threshold, the service request is stored as a pending service request to the target storage location; if the current total number of requests is not less than the total number of requests threshold, it is determined whether the storage requirement for storing the service request to the target storage location is met; if it is met, the service request is stored as a pending service request to the target storage location; if it is not met, the service request is discarded, and the current total number of requests is updated to the total number of historical requests. In the above manner, when the service end processes the service request, it can determine whether the service request needs to be limited by the sequence number or request time of the service request. In this way, even in the face of traffic peaks, fine-grained interface current limiting can be achieved, and the burst performance is better. Moreover, when limiting the flow, accurate current limiting can be performed according to the number of service requests, thereby solving the problem of cross-time traffic overlimit. At the same time, the transaction operation of traffic data can be realized by addition and subtraction operations, without the need for complex transaction operations, which improves the processing performance of service requests.
[0108] The embodiments of the present invention Figure 1 The method for processing a service request shown in the figure is further described, and specifically may include the following steps:
[0109] Step 101: When a current service request is obtained, the total number of historical requests is updated based on the service request to obtain the total number of current requests.
[0110] The user can trigger a service request in the terminal, and the terminal can send the service request to the server. After obtaining the service request, the server can update the total number of historical requests according to the service request, thereby obtaining the updated total number of current requests.
[0111] The total number of historical requests may be the total number of all service requests obtained before the service request is obtained.
[0112] For example, before obtaining the current business request, the server has obtained a total of 100 business requests, so the total number of historical requests is 100. After obtaining the current business request, the total number of historical requests is updated, that is, the total number of historical requests is increased by 1, and the updated total number of current requests is 101.
[0113] Step 102: If the current total number of requests is less than the total number of requests threshold, the service request is stored in a target storage location as a pending service request.
[0114] If the current total number of requests is less than the preset total number of requests threshold, it means that the number of pending business requests in the server is small and there is no need to limit the flow of business requests. Therefore, the acquired business requests can be stored in the preset target storage location as pending business requests. The server can process each pending business request in the target storage location according to the sequence number of the business request.
[0115] In the embodiment of the present invention, storing the service request as a pending service request in a target storage location includes:
[0116] Using the total number of current requests as the sequence number of the service request;
[0117] The service request including the sequence number is stored in a target storage location, and the request time of the service request is recorded.
[0118] Specifically, in order to ensure the order of each business request, the server can use the updated current total number of requests as the serial number of the business request after determining that the current total number of requests is less than the total number of requests threshold, and then store the business request in the target storage location. At the same time, record the request time of the business request in the target storage location.
[0119] Among them, the request time of the service request can be based on the time when the server receives the service request, or it can be based on the time when the terminal initiates the service request. In actual applications, the specific request time of the service request can be set according to actual needs, and the embodiment of the present invention does not limit this.
[0120] For example, continuing with the previous example, the preset total request threshold is 150, and the updated current total request is 101. Since the current total request is less than the total request threshold, "101" is used as the serial number of the business request, indicating the 101th business request, and then the 101th business request is stored in the preset target storage location. At the same time, the request time of the 101st business request is recorded in the target storage location.
[0121] Further, in an embodiment of the present invention, the target storage location includes a distributed logical queue. For example, three cluster nodes are deployed in the server, and each cluster node is used to store business requests. After the server obtains the business request, after determining that the business request can be stored in the target storage location, it can obtain the request time of the business request, and store the business request (including the sequence number) and the request time in any one of the three cluster nodes, or store the business request and the request time in one of the three cluster nodes based on preset rules. In actual applications, the rules for storing business requests can be set according to actual needs, and the embodiment of the present invention does not limit this.
[0122] The cluster nodes may use redis or other storage structures. In practical applications, the storage structure of the cluster nodes may be set according to actual needs, and the embodiment of the present invention does not limit this.
[0123] Step 103: If the current total number of requests is not less than the total number of requests threshold, determine whether the storage requirement for storing the business request in the target storage location is met.
[0124] Since the pending business requests in the target storage location will be processed in sequence and the sequence number of each business request will not change, it is possible that the current total number of requests is not less than the total number of requests threshold, but the number of business requests in the target storage location is small, and thus no current limiting is required. In other words, if the current total number of requests is not less than the total number of requests threshold, it is necessary to further determine whether the storage requirements for storing the business requests in the target storage location are met.
[0125] In the embodiment of the present invention, the determining whether the storage requirement for storing the service request in the target storage location is met includes:
[0126] Determine the target historical service request based on the total number of requests threshold;
[0127] If the target historical service request has not expired, determining the time difference between the service request and the target historical service request;
[0128] If the time difference is greater than the time difference threshold, the storage requirement is met;
[0129] If the time difference is not greater than the time difference threshold, the storage requirement is not met.
[0130] Specifically, after obtaining the sequence number of the service request, the target historical request to be compared may be determined according to the sequence number of the service request and a threshold of the total number of requests.
[0131] If the target historical business request has not expired, then the time difference between the business request and the target historical business request can be calculated. If the time difference is greater than the preset time difference threshold, it means that the storage requirements for storing the business request in the target storage location are met. If the time difference is not greater than the time difference threshold, it means that the storage requirements for storing the business request in the target storage location are not met.
[0132] In the embodiment of the present invention, determining the time difference between the service request and the target historical service request includes:
[0133] Calculate the difference between the current total number of requests and the total number of requests threshold to obtain the target historical business requests;
[0134] Obtaining the request time of the target historical service request from the target storage location;
[0135] The time difference between the request time of the service request and the request time of the target historical service request is calculated.
[0136] Specifically, after obtaining the serial number of the business request, the difference between the serial number of the business request and the total request threshold can be calculated to obtain the target historical business request with the difference as the serial number, and then the request time of the target historical business request is obtained from the target storage location, as well as the request time of the business request, and the time difference between the request time of the business request and the request time of the target historical business request is calculated.
[0137] For example, the preset current limiting rule is that no more than 3 business requests are made in 1 second, that is, the time difference threshold is 1 second, and the total number of requests threshold is 3. When the 4th business request is obtained, the difference between the serial number of the business request and the total number of requests threshold is calculated, that is, 4-3=1, and the historical business request with serial number 1 is used as the target historical business request, that is, the 1st business request, and then it is determined whether the 1st business request is expired. If not expired, the time difference between the request time of the 4th business request and the 1st business request can be calculated. If the time difference is greater than the time difference threshold, that is, the time difference is greater than 1 second, then the 4th business request meets the storage requirements for storage in the target storage location.
[0138] Furthermore, in the embodiment of the present invention, the expiration time of the service request is greater than the time difference threshold, so that the service request can be prevented from being deleted in advance due to expiration, resulting in the failure of current limiting.
[0139] In an embodiment of the present invention, it also includes:
[0140] If the target historical service request has expired, the storage requirement is met.
[0141] Specifically, if the target historical business request has expired, then it can be determined that the business request meets the storage requirements for storage in the target storage location. For example, continuing with the previous example, when the fourth business request is obtained, it is determined that the first business request is the target historical business request, but the request time of the first business request is more than 5 minutes from the current time (assuming the expiration time is 1 minute), which means that the first business request has expired. At this time, it can be determined that the fourth business request meets the storage requirements for storage in the target storage location.
[0142] Furthermore, expired historical business requests can be deleted from the target storage location, thus avoiding unlimited expansion of the target storage location and achieving controllable resource usage.
[0143] It should be noted that in the embodiment of the present invention, the current limiting rules may include other indicators in addition to the total number of requests threshold and the time difference threshold, so the specific indicators of the current limiting rules, as well as the specific values of the total number of requests threshold and the time difference threshold can be set according to actual needs, and the embodiment of the present invention does not limit this. In this way, the current limiting rules can be adjusted in real time and dynamically according to needs, without restarting the service, thereby improving processing efficiency.
[0144] Step 104: If satisfied, the service request is stored in a target storage location as a pending service request.
[0145] If it is determined that the business request meets the storage requirements of the target storage location, the acquired business request can be stored in the preset target storage location as a pending business request. The server can process each pending business request in the target storage location according to the sequence number of the business request.
[0146] For example, continuing with the previous example, if the time difference between the request time of the fourth business request and the request time of the first business request is greater than 1 second, then the fourth business request can be stored in the target storage location as a pending business request.
[0147] Step 105: If not satisfied, the service request is discarded, and the current total number of requests is updated to the total number of historical requests.
[0148] If it is determined that the service request does not meet the storage requirements for storage in the target storage location, the service request can be discarded, and the current total number of requests is updated to the total number of historical requests, that is, the service request is deleted from the total number of requests.
[0149] For example, continuing with the previous example, after obtaining the 5th business request, the current total number of requests is updated from 4 (the total number of historical requests) to 5. The time difference between the request time of the 5th business request and the request time of the 2nd business request is calculated. Since the time difference is less than 1 second, the 5th business request does not meet the storage requirements for storage in the target storage location. Therefore, the current total number of requests is reduced by 1 to obtain the total number of historical requests, which is 4.
[0150] In the embodiment of the present invention, when the server processes the service request, it can determine whether the service request needs to be limited by the sequence number or request time of the service request. In this way, even in the face of traffic peaks, fine-grained interface current limiting can be achieved, and the burst performance is better. Moreover, when limiting the flow, accurate current limiting can be performed according to the number of service requests, thereby solving the problem of cross-time traffic exceeding the limit. At the same time, the transaction operation of traffic data can be achieved through addition and subtraction operations, without the need for complex transaction operations, which improves the processing performance of service requests.
[0151] Furthermore, for expired historical business requests, they can be deleted from the target storage location, thus avoiding the unlimited expansion of the target storage location and achieving controllable resource usage. Moreover, the flow limiting rules can be adjusted dynamically in real time according to demand without restarting the service, thus improving processing efficiency.
[0152] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.
[0153] Reference Figure 3 , shows a structural block diagram of an embodiment of a device for processing a service request of the present invention, which may specifically include the following modules:
[0154] Acquisition module 301, used to acquire the current service request;
[0155] An updating module 302 is used to update the total number of historical requests based on the business request to obtain the total number of current requests;
[0156] The storage module 303 is used to store the service request as a pending service request in a target storage location if the current total number of requests is less than the total number of requests threshold;
[0157] A determination module 304 is configured to determine whether a storage requirement for storing the business request in the target storage location is met if the current total number of requests is not less than the total number of requests threshold;
[0158] If satisfied, the storage module 303 is called;
[0159] A discarding module 305, configured to discard the service request if the conditions are not met;
[0160] The updating module 302 is further configured to update the current total number of requests to the total number of historical requests.
[0161] In an embodiment of the present invention, the determining module includes:
[0162] A first processing submodule, configured to determine a target historical service request based on the total number of requests threshold;
[0163] A second processing submodule, configured to determine a time difference between the service request and the target historical service request if the target historical service request has not expired;
[0164] A third processing submodule, configured to determine that the storage requirement is met if the time difference is greater than a time difference threshold;
[0165] The fourth processing submodule is configured to determine that the storage requirement is not met if the time difference is not greater than the time difference threshold.
[0166] In the embodiment of the present invention, the storage module is specifically used for:
[0167] Using the total number of current requests as the sequence number of the service request;
[0168] The service request including the sequence number is stored in a target storage location, and the request time of the service request is recorded.
[0169] In the embodiment of the present invention, the second processing submodule is specifically used to:
[0170] Calculate the difference between the current total number of requests and the total number of requests threshold to obtain the target historical business requests;
[0171] If the target historical service request has not expired, obtaining the request time of the target historical service request from the target storage location;
[0172] The time difference between the request time of the service request and the request time of the target historical service request is calculated.
[0173] In an embodiment of the present invention, it also includes:
[0174] The fifth processing submodule is used to determine whether the storage requirement is met if the target historical service request has expired.
[0175] In the embodiment of the present invention, the expiration time of the service request is greater than the time difference threshold.
[0176] In an embodiment of the present invention, the target storage location includes a distributed logical queue.
[0177] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0178] An embodiment of the present invention further provides an electronic device, including:
[0179] It includes a processor, a memory, and a computer program stored in the memory and capable of running on the processor. When the computer program is executed by the processor, the various processes of the above-mentioned business request processing method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0180] 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 various processes of the above-mentioned business request processing method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0181] The various embodiments in this 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 referenced to each other.
[0182] It will be appreciated by those skilled in the art that the embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0183] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0184] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0185] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0186] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.
[0187] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0188] The above is a detailed introduction to a method for processing a business request and a device for processing a business request provided by the present invention. Specific examples are used herein 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. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A method for processing a business request, characterized in that: The method comprises: When the current service request is obtained, the total number of historical requests is updated based on the service request to obtain the total number of current requests; If the total number of current requests is less than the total number of requests threshold, storing the service request as a pending service request in a target storage location; If the current total number of requests is not less than the total number of requests threshold, determining whether a storage requirement for storing the business request in the target storage location is met; If satisfied, the business request is stored in the target storage location as a pending business request; If not satisfied, the service request is discarded, and the current total number of requests is updated to the total number of historical requests.
2. The method for processing a service request according to claim 1, characterized in that: The determining whether a storage requirement for storing the service request in the target storage location is met includes: Determine the target historical service request based on the total number of requests threshold; If the target historical service request has not expired, determining the time difference between the service request and the target historical service request; If the time difference is greater than the time difference threshold, the storage requirement is met; If the time difference is not greater than the time difference threshold, the storage requirement is not met.
3. The method for processing a service request according to claim 1, characterized in that: The storing the service request as a pending service request in a target storage location includes: Using the total number of current requests as the sequence number of the service request; The service request including the sequence number is stored in a target storage location, and the request time of the service request is recorded.
4. The method for processing a service request according to claim 2, characterized in that: The determining the time difference between the service request and the target historical service request includes: Calculate the difference between the current total number of requests and the total number of requests threshold to obtain the target historical business requests; If the target historical service request has not expired, obtaining the request time of the target historical service request from the target storage location; The time difference between the request time of the service request and the request time of the target historical service request is calculated.
5. The method for processing a service request according to claim 2, characterized in that: Also includes: If the target historical service request has expired, the storage requirement is met.
6. The method for processing a service request according to claim 1, characterized in that: The expiration time of the service request is greater than the time difference threshold.
7. The method for processing a service request according to claim 1, characterized in that: The target storage location includes a distributed logical queue.
8. A device for processing a service request, characterized in that: The device comprises: The acquisition module is used to obtain the current business request; An updating module, used to update the total number of historical requests based on the business request to obtain the total number of current requests; A storage module, configured to store the service request as a pending service request in a target storage location if the current total number of requests is less than a total number of requests threshold; A determination module, configured to determine whether a storage requirement for storing the service request in the target storage location is met if the current total number of requests is not less than the total number of requests threshold; If satisfied, calling the storage module; A discarding module, used for discarding the service request if the conditions are not met; The updating module is further used to update the current total number of requests to the total number of historical requests.
9. An electronic device, characterized in that: include: A processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein when the computer program is executed by the processor, the steps of the method for processing a service request as claimed in any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method for processing a service request according to any one of claims 1 to 7 are implemented.