A gateway throttling method and system based on user session

By reusing the user login session and/or token mechanism in gateway rate limiting, and combining it with the LRU algorithm to sort user access, the problem of traffic amplification in gateway interface rate limiting strategies under sudden situations is solved, thus improving the user experience.

CN116866278BActive Publication Date: 2026-05-05CHINA CITIC BANK CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
CHINA CITIC BANK CO LTD
Filing Date
2023-06-30
Publication Date
2026-05-05

AI Technical Summary

Technical Problem

In existing technologies, gateway interface rate limiting strategies can easily lead to increased traffic and a deterioration in user experience during sudden business surges, especially when some interface requests are restricted while others are not, during continuous user operations.

Method used

By reusing the session and/or token mechanism during user login and combining it with the LRU algorithm to sort user access, gateway rate limiting within the interface is implemented, user records that have not been accessed for a long time are eliminated, and user records that have been accessed recently are retained first.

Benefits of technology

By avoiding traffic amplification caused by individual user operations during user refreshes and other actions, the user experience of accessing the gateway service is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116866278B_ABST
    Figure CN116866278B_ABST
Patent Text Reader

Abstract

The application provides a gateway flow limiting method and system based on a user session, and has the characteristics that the method comprises the following steps: S1, receiving a login request of a first user, and judging whether the first user has a login record; S2, if the first user has a login record, judging whether a first queue meets a partition limit condition, and if yes, putting a first user session into the first queue based on an LRU algorithm; S3, if the first queue does not meet the partition limit condition, eliminating a second user session at the last rank of the first queue based on the LRU algorithm, and then putting the first user session into the first queue based on the LRU algorithm; S4, updating the last access time of the first user session, and updating the first queue based on the LRU algorithm; and S5, responding to an access request of the first user, and providing gateway service for the first user. The application reuses an existing user session and / or token mechanism, realizes gateway flow limiting by using an LRU algorithm, and improves user experience.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer-related technologies, and in particular to a gateway rate limiting method and system based on user session. Background Technology

[0002] Current technologies for gateway interface rate limiting are often interface-level, such as rate limiting based on the number of requests or token bucket algorithms for gateway interfaces (APIs). In the event of a sudden surge in business activity, traffic may increase exponentially. If ordinary rate limiting algorithms are limited to interface-level rate limiting, some interface requests may be restricted while others are not, resulting in users repeatedly refreshing the page, amplifying traffic and ultimately degrading the user experience.

[0003] To address the above deficiencies, this application reuses the session and / or token mechanism existing during user login. When a user has access records, it uses the LRU algorithm to sort user accesses and arranges the order of users most likely to access the service using the LRU algorithm. This achieves gateway rate limiting within the interface, preventing traffic amplification due to individual user operations such as refreshing or other actions, thus improving the user experience. Summary of the Invention

[0004] To address the shortcomings of the existing system, and considering the deficiencies of the aforementioned background technology, this invention proposes a gateway rate limiting method and system based on user session. Specifically, it includes:

[0005] The first aspect of this application proposes a gateway rate limiting method based on user session, characterized by comprising:

[0006] S1. Receive the login request from the first user and determine whether the first user has a login record;

[0007] S2. If the first user has a login record, determine whether the first queue meets the partition restriction condition. If it does, put the first user's session into the first queue based on the LRU algorithm.

[0008] S3. If the partitioning restriction conditions are not met, the second user session ranked last in the first queue is eliminated based on the LRU algorithm, and then the first user session is put into the first queue based on the LRU algorithm.

[0009] S4. Update the last access time of the first user session and update the first queue based on the LRU algorithm;

[0010] S5. In response to the access request from the first user, provide gateway services to the first user.

[0011] Furthermore, S1 also includes: if the first user does not have a login record, then gateway rate limiting is performed based on a preset interface rate limiting strategy.

[0012] Furthermore, the zoning restrictions include restrictions on the number of predetermined cities.

[0013] Furthermore, in S2, placing the first user's session into the first queue based on the LRU algorithm includes placing the first user's token at the front of the first queue.

[0014] Furthermore, the process of eliminating the second user session that ranks last in the first queue in S3 includes: determining whether the second user session meets the elimination conditions; if the elimination conditions are met, then eliminating the second user session.

[0015] Furthermore, the first queue is recorded using a hashmap and a doubly linked list, and the doubly linked list also records the last access time of the first user.

[0016] Furthermore, the method also includes setting a first login token with a predetermined validity period, the first login token being used for repeated logins within the predetermined period.

[0017] A second aspect of this application proposes a gateway rate limiting device based on user session, characterized in that it includes:

[0018] The login detection module is used to receive the login request from the first user and determine whether the first user has a login record.

[0019] The restriction and sorting module is used to determine whether the first queue meets the partition restriction conditions if the first user has a login record. If it does, the first user's session is put into the first queue based on the LRU algorithm.

[0020] The elimination and sorting module is used to eliminate the second user session ranked last in the first queue based on the LRU algorithm if the partition restriction conditions are not met, and then put the first user session into the first queue based on the LRU algorithm.

[0021] The update module is used to update the last access time of the first user session and update the first queue based on the LRU algorithm.

[0022] The service module is used to respond to the access request of the first user and provide gateway services to the first user.

[0023] A third aspect of this application provides an electronic device, characterized in that it comprises: a processor, and a memory communicatively connected to the processor;

[0024] The memory stores computer-executed instructions;

[0025] The processor executes computer execution instructions stored in the memory to implement the aforementioned gateway rate limiting method based on user session.

[0026] A fourth aspect of this application provides a computer-readable storage medium, characterized in that the computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the above-described gateway rate limiting method based on user session.

[0027] The beneficial effects of this invention are as follows: This application reuses the session and / or token mechanism existing during user login. When a user has access records, it uses the LRU algorithm to sort the user's access. Combined with the LRU algorithm, it arranges the order of users most likely to access the interface, thereby realizing gateway rate limiting within the interface. In the case of user refresh and other operations, traffic will not be amplified due to the operation of a single user, thus improving the user experience. Attached Figure Description

[0028] Figure 1 This is a flowchart illustrating the gateway rate limiting method based on user session of the present invention.

[0029] Figure 2 This is a structural block diagram of the gateway rate limiting device based on user session according to the present invention.

[0030] Figure 3 A schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation

[0031] To better understand the content of this invention, a detailed description will be provided in conjunction with the accompanying drawings and embodiments.

[0032] However, it should be understood that these descriptions are merely exemplary and not intended to limit the scope of the invention. Furthermore, descriptions of well-known structures and techniques are omitted in the following description to avoid unnecessarily obscuring the concept of the invention. The terminology used herein is solely for describing particular embodiments and is not intended to limit the invention. The words “a,” “an,” and “the,” as used herein, should also include the meanings of “a plurality” and “multiple,” unless the context clearly indicates otherwise. Furthermore, the terms “comprising,” “including,” etc., as used herein indicate the presence of the stated features, steps, operations, and / or components, but do not exclude the presence or addition of one or more other features, steps, operations, or components.

[0033] All terms used herein (including technical and scientific terms) have the meanings commonly understood by those skilled in the art, unless otherwise defined. It should be noted that the terms used herein are to be interpreted in a manner consistent with the context of this specification, and not in an idealized or overly rigid manner. This invention is an improvement upon prior art; therefore, any parts not described in this application are implemented using existing technology.

[0034] LRU (Least Recently Used) algorithm: This algorithm evicts data based on its historical access records. Its core idea is that "if data has been accessed recently, it is more likely to be accessed in the future."

[0035] User Session: A session refers to the time interval between a user's communication with an interactive system, typically the time elapsed from registering to logging out. A user session refers to the session state maintained between a user and the server after logging in through an app. Browsers generally use cookies, while mobile apps typically use token-based mechanisms.

[0036] Currently, gateway interface rate limiting strategies are often at the interface level, such as rate limiting based on the number of requests or the token bucket algorithm for gateway interfaces (APIs). In the event of a sudden business surge, traffic may increase N times. If ordinary rate limiting algorithms are limited to interface-level rate limiting, some interface requests may be restricted while others are not restricted in a series of continuous operations. In this case, users may refresh repeatedly, causing traffic amplification and ultimately leading to a poor user experience. This application reuses the session and / or token mechanism existing during user login. When a user has access records, it uses the LRU algorithm to sort user accesses. By combining the LRU algorithm with the order of users most likely to access the service, gateway rate limiting within the interface is implemented. Specifically, if a user has recently accessed a related gateway service interface, the probability of their recent access to the gateway service will increase. Therefore, by arranging recently accessed user records at the front, convenient access is achieved for users. Meanwhile, user records that have not been accessed for a long time are placed at the back of the queue. If a quantity limit is imposed, long-inaccessible user records are first eliminated to meet the gateway interface rate limiting requirements. On the other hand, the existing session and / or token mechanism is reused. This mechanism serves as the basis for establishing service between the user and the gateway. When a user performs a refresh operation, there will be no sudden increase in traffic due to a single user's access, thus improving the user experience when accessing the gateway service.

[0037] The first aspect of this application proposes a gateway rate limiting method based on user session, characterized by comprising:

[0038] S1. Receive the login request from the first user and determine whether the first user has a login record;

[0039] In this application, the user's request to access the gateway is the starting point for the gateway to provide services. If the first user has an access record, the existing session and / or token can be reused. Therefore, it is necessary to first determine whether the first user has a login record. As the information for configuring access gateway services is not the core inventive point of this application, this application will not emphasize it. However, the necessary configuration is still essential to this application.

[0040] It is worth noting that specific access records can be replaced by other methods to replace the user's session and / or token, but the corresponding reuse also needs to be replaced by other alternative methods to meet the requirements for sorting. The session in this application can be the identification information or other information recorded in the system.

[0041] Furthermore, S1 also includes: if the first user does not have a login record, then perform gateway rate limiting based on a preset interface rate limiting policy. Alternatively, add the first user's session to a first queue.

[0042] Specifically, in the embodiments of this application, if a user has no login history, then the existing session and / or token cannot be reused. Therefore, the access of such users is subject to the original interface-level rate limiting strategy. At the same time, a new session and / or token for such users can be created and sorted based on the LRU algorithm so that such users can reuse the session and / or token on their next login, thereby implementing the rate limiting strategy described in this application.

[0043] Specifically, the determination of access history can be made by the user's identification information and whether the user's session and / or token exist in the first queue. The determination of user access records in this application is not limited to specific implementations in this field.

[0044] S2. If the first user has a login record, determine whether the first queue meets the partition restriction condition. If it does, put the first user's session into the first queue based on the LRU algorithm.

[0045] Furthermore, in S2, placing the first user's session into the first queue based on the LRU algorithm includes placing the first user's token at the front of the first queue.

[0046] Specifically, based on the core idea of ​​the LRU algorithm, the first user session is placed at the front of the queue. The corresponding first queue can also contain other information, such as recording the last access time of the first user session. The last access time can be recorded in ways such as recording the timestamp of the last access.

[0047] Furthermore, the zoning restrictions include restrictions on the number of predetermined cities.

[0048] For example, based on the city, if an LRU (Least Recently Used) queue of 10,000 is set for Beijing and Shanghai, then even if more than 10,000 people are accessing the service, a maximum of 10,000 people can operate smoothly simultaneously without triggering rate limiting, and 10,000 users can have access privileges at the same time. Meanwhile, users outside of Beijing and Shanghai can be set to not have access privileges.

[0049] S3. If the partitioning restriction conditions are not met, the second user session ranked last in the first queue is eliminated based on the LRU algorithm, and then the first user session is put into the first queue based on the LRU algorithm.

[0050] Furthermore, the process of eliminating the second user session that ranks last in the first queue in S3 includes: determining whether the second user session meets the elimination conditions; if the elimination conditions are met, then eliminating the second user session.

[0051] The elimination criteria can be set by presetting the user's priority, etc., and this application does not impose any restrictions.

[0052] If the partition restriction condition is triggered, the first queue needs to be evictped to meet the requirements of the rate limiting policy. For example, if there are more than 10,000 users, the session and / or token of the user who has not been accessed for the longest time will be deleted based on the LRU algorithm. Similarly, if there are multiple new users, the sessions and / or tokens of multiple users who have not been accessed for a long time need to be evictped. The evictment includes deletion to meet the requirements of the first queue's number limit, etc.

[0053] S4. Update the last access time of the first user session and update the first queue based on the LRU algorithm;

[0054] Furthermore, the first queue is recorded using a hashmap and a doubly linked list, and the doubly linked list also records the last access time of the first user.

[0055] After a user successfully logs in, both the hashmap and the doubly linked list are updated. The last access time of the first user in the doubly linked list is updated to meet the sorting requirements of the LRU algorithm.

[0056] S5. In response to the access request from the first user, provide gateway services to the first user.

[0057] Specifically, different rate limiting strategies can be provided for different gateways. The access records of users of different gateways can be stored in the caching system to sort the first queue. Different first queues can be set for different gateway services, and the order of the first queues of different gateway services can be sorted by the frequency of commonly used gateway services.

[0058] Furthermore, the method also includes setting a first login token with a predetermined validity period, the first login token being used for repeated logins within the predetermined period.

[0059] The first login token with a predetermined validity period can meet the needs of users who log in repeatedly within a certain period. The corresponding recycling or distribution mechanism, and the corresponding configuration of the client and gateway, are not limited in this application.

[0060] A second aspect of this application proposes a gateway rate limiting device based on user session, characterized in that it includes:

[0061] The login detection module is used to receive the login request from the first user and determine whether the first user has a login record.

[0062] The restriction and sorting module is used to determine whether the first queue meets the partition restriction conditions if the first user has a login record. If it does, the first user's session is put into the first queue based on the LRU algorithm.

[0063] The elimination and sorting module is used to eliminate the second user session ranked last in the first queue based on the LRU algorithm if the partition restriction conditions are not met, and then put the first user session into the first queue based on the LRU algorithm.

[0064] The update module is used to update the last access time of the first user session and update the first queue based on the LRU algorithm.

[0065] The service module is used to respond to the access request of the first user and provide gateway services to the first user.

[0066] Furthermore, the login determination module is also used to: if the first user does not have a login record, then perform gateway rate limiting based on a preset interface rate limiting strategy.

[0067] Furthermore, the zoning restrictions include restrictions on the number of predetermined cities.

[0068] Furthermore, the restriction arrangement module is also used to: put the first user session into the first queue based on the LRU algorithm, including: putting the first user's token at the front of the first queue.

[0069] Furthermore, the elimination and sorting module is also used to: determine whether the second user session meets the elimination conditions, and if the elimination conditions are met, then eliminate the second user session.

[0070] Furthermore, the first queue is recorded using a hashmap and a doubly linked list, and the doubly linked list also records the last access time of the first user.

[0071] Furthermore, the device also includes a timed validity module for setting a first login token with a predetermined validity period, the first login token being used for repeated logins within the predetermined period.

[0072] Figure 3 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 3As shown, the electronic device may include: transceiver 121, processor 122, and memory 123.

[0073] Transceiver 121 can be used to cache the last access time of the first queue and the first user session.

[0074] Processor 122 executes computer execution instructions stored in memory, causing processor 122 to perform the scheme in the above embodiments. Processor 122 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.

[0075] The memory 123 is connected to the processor 122 via the system bus and completes communication between them. The memory 123 is used to store computer program instructions.

[0076] The system bus can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The system bus can be divided into address bus, data bus, control bus, etc. For ease of representation, only one thick line is used in the diagram, but this does not indicate that there is only one bus or one type of bus. Transceivers are used to enable communication between database access devices and other computers (e.g., clients, read-write libraries, and read-only libraries). Memory may include random access memory (RAM) and may also include non-volatile memory.

[0077] The electronic device provided in this application embodiment can be the terminal device described in the above embodiments.

[0078] This application also provides a chip for executing instructions, which is used to execute the technical solution of the gateway rate limiting method based on user session in the above embodiments.

[0079] This application also provides a computer-readable storage medium storing computer instructions. When the computer instructions are executed on a computer, the computer performs the technical solution of the gateway rate limiting method based on user session described in the above embodiments.

[0080] This application also provides a computer program product, which includes a computer program stored in a computer-readable storage medium. At least one processor can read the computer program from the computer-readable storage medium. When the at least one processor executes the computer program, it can implement the technical solution of the gateway rate limiting method based on user session described in the above embodiments.

[0081] The beneficial effects of this invention are as follows: This application reuses the session and / or token mechanism existing during user login. When a user has access records, it uses the LRU algorithm to sort the user's access. Combined with the LRU algorithm, it arranges the order of users most likely to access the interface, thereby realizing gateway rate limiting within the interface. In the case of user refresh and other operations, traffic will not be amplified due to the operation of a single user, thus improving the user experience.

[0082] It is worth noting that the data collection and migration involved in this application have been with the user's consent and are necessary for the applicant's normal business operations. The applicant has anonymized and desensitized the collected data and set corresponding access permissions to ensure that user privacy is not leaked. The data compliance measures involved in this application are only listed here; the applicant has also implemented other relevant data compliance measures. The data processing activities carried out by the applicant comply with the provisions of the Data Security Law and the Personal Information Protection Law, and other relevant laws and regulations.

[0083] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this application are indicated by the following claims.

[0084] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.

[0085] Those skilled in the art will further recognize that the algorithm steps in connection with the embodiments herein can be implemented in electronic hardware, computer software, or a combination of both. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present invention.

[0086] Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including both the preferred embodiments and all changes and modifications falling within the scope of the invention.

[0087] The above description is merely a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A gateway rate limiting method based on user session, characterized in that, include: S1. Receive the login request from the first user and determine whether the first user has a login record; S2. If the first user has a login record, determine whether the first queue meets the partition restriction condition. If it does, put the first user's session into the first queue based on the LRU algorithm. S3. If the partitioning restriction conditions are not met, the second user session ranked last in the first queue is eliminated based on the LRU algorithm, and then the first user session is put into the first queue based on the LRU algorithm. S4. Update the last access time of the first user session and update the first queue based on the LRU algorithm; S5. In response to the access request from the first user, provide gateway services to the first user.

2. The method according to claim 1, characterized in that, S1 further includes: if the first user does not have a login record, then perform gateway rate limiting based on a preset interface rate limiting strategy.

3. The method according to claim 1, characterized in that, The zoning restrictions include restrictions on the number of predetermined cities.

4. The method according to claim 1, characterized in that, The step of adding the first user's session to the first queue based on the LRU algorithm in S2 includes: adding the first user's token to the front of the first queue.

5. The method according to claim 1, characterized in that, The process of eliminating the second user session that ranks last in the first queue in S3 includes: determining whether the second user session meets the elimination criteria, and eliminating the second user session if the elimination criteria are met.

6. The method according to claim 1, characterized in that, The first queue is recorded using a hashmap and a doubly linked list, which also records the last access time of the first user.

7. The method according to claim 1, characterized in that, The method further includes setting a first login token with a predetermined validity period, the first login token being used for repeated logins within the predetermined period.

8. A gateway rate limiting device based on user session, characterized in that, include: The login detection module is used to receive the login request from the first user and determine whether the first user has a login record. The restriction and sorting module is used to determine whether the first queue meets the partition restriction conditions if the first user has a login record. If it does, the first user's session is put into the first queue based on the LRU algorithm. The elimination and sorting module is used to eliminate the second user session ranked last in the first queue based on the LRU algorithm if the partition restriction conditions are not met, and then put the first user session into the first queue based on the LRU algorithm. The update module is used to update the last access time of the first user session and update the first queue based on the LRU algorithm. The service module is used to respond to the access request of the first user and provide gateway services to the first user.

9. An electronic device, characterized in that, include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory to implement the method as described in any one of claims 1-7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any one of claims 1-7.

Citation Information

Patent Citations

  • Login request processing method, equipment and medium

    CN110430062A

  • Facilitating access to web flows utilizing network access tokens according to network capacity

    US20230139078A1