Search

CN-116866278-B - Gateway current limiting method and system based on user session

CN116866278BCN 116866278 BCN116866278 BCN 116866278BCN-116866278-B

Abstract

The application provides a gateway flow limiting method and a gateway flow limiting system based on user session, which are characterized by comprising the steps of S1, receiving a login request of a first user, judging whether the first user has a login record, S2, judging whether a first queue meets partition limiting conditions or not if the first user has the login record, if so, putting the first user session into the first queue based on an LRU algorithm, S3, eliminating a second user session which is ranked last on the first queue based on the LRU algorithm, 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, updating the first queue based on the LRU algorithm, and S5, responding to the access request of the first user, and providing gateway service for the first user. The application multiplexes the existing user session and token mechanism, realizes gateway current limit by using LRU algorithm, and improves user experience.

Inventors

  • CHEN PENGFEI
  • SUN YANSEN
  • XU XIAOJIAN

Assignees

  • 中信银行股份有限公司

Dates

Publication Date
20260505
Application Date
20230630

Claims (10)

  1. 1. The gateway flow limiting method based on the user session is characterized by comprising the following steps: s1, receiving a login request of a first user, and judging whether the first user has a login record or not; S2, if the first user has a login record, judging whether the first queue meets partition limiting conditions, and if so, putting the first user session into the first queue based on an LRU algorithm; S3, if the partition limiting condition is not met, eliminating the last second user session of the first queue based on the LRU algorithm, and then placing 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 an LRU algorithm; and S5, responding to the access request of the first user, and providing gateway service for the first user.
  2. 2. The method of claim 1, wherein S1 further comprises gateway throttling based on a preset interface throttling policy if the first user does not have a login record.
  3. 3. The method of claim 1, wherein the partition limit condition comprises a number of predetermined cities limit condition.
  4. 4. The method of claim 1, wherein placing the first user session in the first queue based on the LRU algorithm in S2 comprises placing a token of the first user at a front end of the first queue.
  5. 5. The method of claim 1, wherein the eliminating the last second user session of the first queue in S3 comprises determining whether the second user session satisfies an elimination condition, and eliminating the second user session if the elimination condition is satisfied.
  6. 6. The method of claim 1, wherein the first queue is recorded based on hashmap and a doubly linked list that also records a last access time of the first user.
  7. 7. The method of claim 1, further comprising setting a first login token for a predetermined validity time, the first login token being used for repeated logins for the predetermined time.
  8. 8. A gateway flow limiting device based on user session, comprising: The login judging module is used for receiving a login request of the first user and judging whether the first user has a login record or not; The limit arrangement module is used for judging whether the first queue meets partition limit conditions or not if the first user has login records, and if so, putting the first user session into the first queue based on an LRU algorithm; The elimination arrangement module is used for eliminating the last second user session of the first queue rank based on the LRU algorithm if the partition limiting condition is not met, and then placing the first user session into the first queue based on the LRU algorithm; The updating module is used for updating the last access time of the first user session and updating the first queue based on an LRU algorithm; and the service module is used for responding to the access request of the first user and providing gateway service for the first user.
  9. 9. An electronic device comprising a processor and a memory communicatively coupled to the processor; the memory stores computer-executable instructions; The processor executes computer-executable instructions stored in the memory to implement the method of any one of claims 1-7.
  10. 10. A computer readable storage medium having stored therein computer executable instructions which when executed by a processor are adapted to carry out the method of any one of claims 1-7.

Description

Gateway current limiting method and system based on user session Technical Field The invention relates to the technical field of computer correlation, in particular to a gateway current limiting method and system based on user session. Background The current prior art is often an interface level for gateway interface flow limiting strategies, such as flow limiting based on a frequency or token bucket algorithm for gateway interfaces (API), under the condition of traffic emergency, the flow rate may be increased by N times, if the common flow limiting algorithm is limited to interface level flow limiting, the situation that a part of interface requests are limited and the other part of interface requests are not limited under a series of continuous operation conditions of users occurs, and under the condition, the users may repeatedly refresh the flow rate, thereby causing flow rate amplification and finally resulting in poor user experience. Aiming at the defects, the application uses the LRU algorithm to sort the accesses of the users under the condition that the users have access records by multiplexing session and/or token mechanisms existing when the users log in, and combines the LRU algorithm to arrange the most possible access user sequence, thereby realizing gateway current limiting in an interface, avoiding flow amplification caused by the operation of individual users under the conditions of user refreshing and other operations, and improving the user experience. Disclosure of Invention Aiming at the defects of the background technology, the invention provides a gateway current limiting method and a gateway current limiting system based on user session. The method specifically comprises the following steps: the first aspect of the present application provides a gateway current limiting method based on user session, which is characterized in that the method comprises: s1, receiving a login request of a first user, and judging whether the first user has a login record or not; S2, if the first user has a login record, judging whether the first queue meets partition limiting conditions, and if so, putting the first user session into the first queue based on an LRU algorithm; S3, if the partition limiting condition is not met, eliminating the last second user session of the first queue based on the LRU algorithm, and then placing 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 an LRU algorithm; and S5, responding to the access request of the first user, and providing gateway service for the first user. Further, the S1 further comprises gateway throttling based on a preset interface throttling strategy if the first user does not have login records. Further, the partition limit condition includes a number limit condition of a predetermined city. Further, the step of placing the first user session in the first queue based on the LRU algorithm in step S2 includes placing a token of the first user at a front end of the first queue. Further, the step of eliminating the second user session with the last ranking of the first queue in the step S3 comprises the steps of judging whether the second user session meets the elimination condition, and eliminating the second user session if the second user session meets the elimination condition. Further, the first queue is recorded based on hashmap and a doubly linked list, which also records the last access time of the first user. Further, the method also includes setting a first login token for a predetermined valid time, the first login token being used for repeated login for the predetermined time. The second aspect of the present application proposes a gateway current limiting device based on user session, which is characterized in that the gateway current limiting device comprises: The login judging module is used for receiving a login request of the first user and judging whether the first user has a login record or not; The limit arrangement module is used for judging whether the first queue meets partition limit conditions or not if the first user has login records, and if so, putting the first user session into the first queue based on an LRU algorithm; The elimination arrangement module is used for eliminating the last second user session of the first queue rank based on the LRU algorithm if the partition limiting condition is not met, and then placing the first user session into the first queue based on the LRU algorithm; The updating module is used for updating the last access time of the first user session and updating the first queue based on an LRU algorithm; and the service module is used for responding to the access request of the first user and providing gateway service for the first user. A third aspect of the present application provides an electronic device, comprising a processor, and a memory communicatively coupled to the