CN116886626A - Service data flow limiting method and device, computer equipment and storage medium - Google Patents

Service data flow limiting method and device, computer equipment and storage medium Download PDF

Info

Publication number
CN116886626A
CN116886626A CN202310678509.0A CN202310678509A CN116886626A CN 116886626 A CN116886626 A CN 116886626A CN 202310678509 A CN202310678509 A CN 202310678509A CN 116886626 A CN116886626 A CN 116886626A
Authority
CN
China
Prior art keywords
service
service request
request
token
token bucket
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310678509.0A
Other languages
Chinese (zh)
Inventor
邓策超
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Property and Casualty Insurance Company of China Ltd
Original Assignee
Ping An Property and Casualty Insurance Company of China Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Property and Casualty Insurance Company of China Ltd filed Critical Ping An Property and Casualty Insurance Company of China Ltd
Priority to CN202310678509.0A priority Critical patent/CN116886626A/en
Publication of CN116886626A publication Critical patent/CN116886626A/en
Pending legal-status Critical Current

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L47/00Traffic control in data switching networks
    • H04L47/10Flow control; Congestion control
    • H04L47/215Flow control; Congestion control using token-bucket

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

The embodiment of the application belongs to the technical field of financial science and technology, and discloses a service data flow limiting method, a device, computer equipment and a storage medium based on a token bucket, wherein the method comprises the following steps: receiving a service request sent by a user terminal; reading a preset Map set; acquiring a target service unique key corresponding to a service path and a target current limiter corresponding to the target service unique key from a preset Map set; distributing a flow limiting token to the service request according to the target flow limiter; when the service request needs to be responded, judging whether the service request has request content or not; if the service request does not contain the request content, responding to the service request; otherwise, judging whether the flow limiting token of the service request meets the flow limiting condition according to the token bucket algorithm and the token bucket flow limiter; if the current limiting token meets the current limiting condition, delaying a preset time response; otherwise, responding to the service request. The application has the advantages that: the traffic can be split based on finer granularity traffic, so that traffic is more reasonably limited.

Description

Service data flow limiting method and device, computer equipment and storage medium
Technical Field
The present application relates to the technical field of financial science and technology, and in particular, to a method, an apparatus, a computer device, and a storage medium for restricting service data based on a token bucket.
Background
The current limiting is a way of service degradation, and the current limiting aims to protect the system by limiting the speed of concurrent requests or limiting the number of requests in a time window, and once the limiting speed is reached, the processing of service, queuing or waiting, degradation and the like can be refused, however, for special application scenes, especially insurance business scenes in the field of financial insurance, if intelligent current limiting is realized, the problem is mainly solved.
The existing current flow limiting mode in the industry generally limits the flow, the finest flow limiting granularity is an interface, but the source of a request interface is not distinguished, and the flow limiting mode has no individual difference at the same time. For example: the insurance company A exposes an interface to the outside, and the insurance company B and the insurance company C call the interface, wherein the calling quantity of the insurance company B is smaller, the QPS is 5, and the system load is pressureless; however, the insurance company C calls a very large amount, QPS of 1000, which may cause excessive system load. For this insurance business scenario we need to have the insurance company C restricted but not affect the invocation of insurance company B, since his traffic is small for insurance company B and should not be restricted. However, the current limiting mode in the industry can only limit the current of the externally exposed interface of the insurance company a, but cannot limit the current of the service scene with finer granularity.
Disclosure of Invention
The application aims to solve the technical problems that the current limiting mode in the industry can only limit the current of an externally exposed interface for an insurance company A and cannot limit the current of a service scene with finer granularity.
The application adopts the following technical scheme to solve the technical problems: the service data flow limiting method based on the token bucket comprises the following steps:
receiving a service request sent by a user terminal, wherein the service request at least carries a service path;
reading a preset Map set, wherein the Map set comprises service unique keys corresponding to each service path and token bucket restrictors corresponding to each service unique key;
acquiring a target service unique key corresponding to the service path and a target current limiter corresponding to the target service unique key from the preset Map set;
distributing a current limiting token to the service request according to the target current limiter;
when the service request needs to be responded, judging whether the service request has request content or not;
if the service request does not contain the request content, responding to the service request;
if the request content exists in the service request, judging whether a flow limiting token of the service request meets a flow limiting condition according to the token bucket algorithm and the token bucket flow limiter;
If the current limiting token meets the current limiting condition, delaying a preset time response;
and if the current limiting token does not meet the current limiting condition, responding to the service request.
Preferably, before the step of reading the preset Map set, the method further comprises the following steps:
reading a service path carried in the service request;
dividing the service request into a main service request and a sub service request according to the flow of the service request of the same service path;
constructing a service unique key for a main service request of the same service path;
a unified service unique key is allocated for all secondary service requests.
Preferably, the token bucket restrictor comprises a plurality of groups of main token buckets and auxiliary token buckets, wherein the plurality of groups of main token buckets are used for restricting main service requests, and the auxiliary token buckets are used for restricting auxiliary service requests; before the step of reading the preset Map set, the method further comprises the following steps:
setting up capacity b of the token bucket;
setting the number r of tokens placed in the bucket per second according to the average speed of the user service request;
subtracting n tokens from the token bucket inner side when there is a request of n bytes;
if the service request carries out the operation of adding the tokens once before, judging whether the number of the tokens in the token bucket is larger than n;
If the number of tokens in the token bucket is greater than n, setting the size of the token bucket according to the rate of the service request, otherwise, refusing access;
where newly generated tokens will be discarded when the number of tokens in the token bucket is equal to b, the token bucket capacity b being proportional to the average rate of traffic requests.
Preferably, the flow limiting method of the token bucket flow limiter comprises the following steps:
acquiring a unique key of a service request;
traversing a Map set, and searching a token bucket matched with a service unique key from the Map set;
sending a token to the service request through a token bucket;
judging whether the service request carries a token or not, and limiting the service request which does not carry the token.
Preferably, the step of distributing the current limit token to the service request according to the target current limiter specifically includes the following steps:
and preferentially distributing the current limiting token for the service request delayed by the preset time response.
Preferably, the step of responding to the service request specifically includes the following steps:
judging whether the unprocessed business request is remained or not;
if the retained service request exists, adding the service request into a queuing sequence;
if the reserved service request does not exist, judging whether the number of tokens in the token bucket is smaller than the number of bytes of the service request;
If the number of tokens in the token bucket is smaller than the number of bytes of the service request, refusing to respond to the service request;
if the number of tokens in the token bucket is greater than or equal to the number of the service request bytes, normally responding to the service request bytes, and matching the tokens for the service request.
A token bucket based traffic data throttling device comprising:
the request receiving module is used for receiving a service request sent by a user terminal, wherein the service request at least carries a service path;
the Map set reading module is used for reading a preset Map set, wherein the Map set comprises service unique keys corresponding to each service path and token bucket restrictors corresponding to each service unique key;
the current limiter acquisition module is used for acquiring a target service unique key corresponding to the service path and a target current limiter corresponding to the target service unique key from the preset Map set;
the token distribution module is used for distributing a flow limiting token to the service request according to the target flow limiter;
the request content judging module is used for judging whether the service request has request content or not when the service request needs to be responded;
The first response module is used for responding to the service request if the request content does not exist in the service request;
the flow limiting condition judging module is used for judging whether the flow limiting token of the service request meets the flow limiting condition according to the token bucket algorithm and the token bucket flow limiter if the request content exists in the service request;
a delay response module, configured to delay a preset time response if the current limiting token meets the current limiting condition;
and the second response module is used for responding to the service request if the current limiting token does not meet the current limiting condition.
Preferably, the apparatus further comprises:
the service path reading module is used for reading the service path carried in the service request;
the request dividing module is used for dividing the service requests into main service requests and auxiliary service requests according to the flow of the service requests of the same service path;
the unique key construction module is used for constructing a service unique key for the main service request of the same service path;
and the unique key distribution module is used for distributing uniform service unique keys for all the auxiliary service requests.
A computer device comprising a memory having stored therein computer readable instructions which when executed by a processor implement the steps of the current limiting method as described above.
A computer readable storage medium having stored thereon computer readable instructions which when executed by a processor implement the steps of the current limiting method as described above
Compared with the prior art, the application provides a service flow limiter based on a token bucket algorithm, which has the following beneficial effects:
the application provides a service data flow limiting method based on a token bucket, which comprises the following steps: receiving a service request sent by a user terminal, wherein the service request at least carries a service path; reading a preset Map set, wherein the Map set comprises service unique keys corresponding to each service path and token bucket restrictors corresponding to each service unique key; acquiring a target service unique key corresponding to the service path and a target current limiter corresponding to the target service unique key from the preset Map set; distributing a current limiting token to the service request according to the target current limiter; when the service request needs to be responded, judging whether the service request has request content or not; if the service request does not contain the request content, responding to the service request; if the request content exists in the service request, judging whether a flow limiting token of the service request meets a flow limiting condition according to the token bucket algorithm and the token bucket flow limiter; if the current limiting token meets the current limiting condition, delaying a preset time response; and if the current limiting token does not meet the current limiting condition, responding to the service request. Compared with the prior art, the method and the system have the advantages that the request is received through the external interface of the company, the request content is classified, unique keys are respectively assigned, the token bucket is built, the unique keys are assigned to the token bucket, the unique keys of the token bucket are associated with the unique keys of the service, the token generation speed of the token bucket is matched with the average speed of the service request, the service can be limited by building the token bucket, the system is prevented from being protected from overlarge flow, the Map set is built, the key-value relation between the unique keys of the service and the service limiter is stored in the Map set, the relation between the service request and the token bucket is saved, the service special current limiting bucket is convenient to find, the service can be respectively limited by assigning the unique keys to the service, the service can be split based on the service with finer granularity, and the service current limiting is more reasonable.
Drawings
FIG. 1 is an exemplary system architecture diagram in which the present application may be applied;
fig. 2 is a flowchart of an implementation of a token bucket-based traffic data throttling method according to an embodiment of the present application;
fig. 3 is a schematic structural diagram of a service data flow limiting device based on a token bucket according to a second embodiment of the present application;
FIG. 4 is a schematic structural diagram of one embodiment of a computer device in accordance with the present application.
Detailed Description
The following description of the embodiments of the present application will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present application, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
As shown in fig. 1, a system architecture 100 may include terminal devices 101, 102, 103, a network 104, and a server 105. The network 104 is used as a medium to provide communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
The user may interact with the server 105 via the network 104 using the terminal devices 101, 102, 103 to receive or send messages or the like. Various communication client applications, such as a web browser application, a shopping class application, a search class application, an instant messaging tool, a mailbox client, social platform software, etc., may be installed on the terminal devices 101, 102, 103.
The terminal devices 101, 102, 103 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smartphones, tablet computers, electronic book readers, MP3 players (Moving Picture ExpertsGroup Audio Layer III, dynamic video expert compression standard audio plane 3), MP4 (Moving PictureExperts Group Audio Layer IV, dynamic video expert compression standard audio plane 4) players, laptop and desktop computers, and the like.
The server 105 may be a server providing various services, such as a background server providing support for pages displayed on the terminal devices 101, 102, 103.
It should be noted that, the service data flow limiting method based on the token bucket provided by the embodiment of the application is generally executed by the server/terminal device, and accordingly, the service data flow limiting device based on the token bucket is generally arranged in the server/terminal device.
It should be understood that the number of terminal devices, networks and servers in fig. 1 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
With continued reference to fig. 2, there is shown a flow chart of a traffic data throttling method according to the present application, a token bucket based traffic data throttling method, comprising the steps of:
step S201: and receiving a service request sent by the user terminal, wherein the service request at least carries a service path.
In an embodiment of the present application, an electronic device (such as a server/terminal device shown in fig. 1) on which a token bucket-based traffic data throttling method operates may receive a request from an access interface by a terminal device through a wired connection manner or a wireless connection manner, and it should be noted that the wireless connection manner may include, but is not limited to, a 3G/4G/5G connection, a WiFi connection, a bluetooth connection, a WiMAX connection, a Zigbee connection, a UWB (ultra wideband) connection, and other now known or future developed wireless connection manners.
In the embodiment of the application, the service requests are received through the external interface, wherein the external interface can be a computing device, a network device and a storage device, the paths corresponding to the service requests can be obtained through the IP addresses of the service requests, the service requests with the same IP address are endowed with the same unique key according to the IP addresses of the service requests, and the requests with the same paths are sorted.
Step S202: and reading a preset Map set, wherein the Map set comprises service unique keys corresponding to each service path and token bucket restrictors corresponding to each service unique key.
In the embodiment of the application, the service request carrying the service unique key can be matched with the corresponding token bucket restrictor by utilizing the preset Map set, so that the token bucket restrictor can be convenient for restricting the service request in a targeted manner.
Step S203: and acquiring a target service unique key corresponding to the service path and a target restrictor corresponding to the target service unique key from a preset Map set.
Step S204: and distributing the flow limiting token to the service request according to the target flow limiter.
In the embodiment of the application, the token is acquired from the Map set according to the service unique key, and different token barrels can be set for service requests of different paths through the Map set.
Step S205: when the service request needs to be responded, judging whether the service request has request content or not;
step S206: and if the service request does not contain the request content, responding to the service request.
In the embodiment of the application, the received service requests can exist, the content is empty, and the requests are normally responded.
Step S207: if the service request has the request content, judging whether the flow limiting token of the service request meets the flow limiting condition according to a token bucket algorithm and a token bucket flow limiter.
Step S208: if the current limiting token meets the current limiting condition, delaying the preset time response.
Step S209: and if the current limiting token does not meet the current limiting condition, responding to the service request.
In the embodiment of the application, taking an insurance service scenario as an example, if an insurance company a exposes an interface to the outside, the insurance company B and the insurance company C need to call the interface, wherein the call quantity of the insurance company B is smaller, QPS is 5, the system load is not pressurized, but the call quantity of the insurance company C is extremely large, QPS is 1000, which may cause the system load to be too high, at this time, the insurance company a obtains a service unique key B1 and a service unique key C1 corresponding to the insurance company B and the insurance company C respectively according to a preset Map set, and a token bucket restrictor B2 corresponding to the service unique key B1 and a token bucket restrictor C2 corresponding to the service unique key C1, and then distributes a restrictor token B3 and a restrictor token C3 to the insurance company B and the insurance company C respectively according to the token bucket restrictor B2, when a request of the insurance company B or the insurance company C needs to be responded, firstly, whether the request of the interface is requested by the insurance company B or the insurance company C has the request content, if not has the request content, and if the request content is not requested, the request of the insurance company B or the insurance company C needs to be further differentiated according to the request of the respective restrictor C needs to be further.
In an embodiment of the present application, a service data flow limiting method based on a token bucket is provided, including: receiving a service request sent by a user terminal, wherein the service request at least carries a service path; reading a preset Map set, wherein the Map set comprises service unique keys corresponding to each service path and token bucket restrictors corresponding to each service unique key; acquiring a target service unique key corresponding to a service path and a target current limiter corresponding to the target service unique key from a preset Map set; distributing a flow limiting token to the service request according to the target flow limiter; when the service request needs to be responded, judging whether the service request has request content or not; if the service request does not contain the request content, responding to the service request; if the service request has the request content, judging whether the flow limiting token of the service request meets the flow limiting condition according to a token bucket algorithm and a token bucket flow limiter; if the current limiting token meets the current limiting condition, delaying a preset time response; and if the current limiting token does not meet the current limiting condition, responding to the service request. Compared with the prior art, the method and the system have the advantages that the request is received through the external interface of the company, the request content is classified, unique keys are respectively assigned, the token bucket is built, the unique keys are assigned to the token bucket, the unique keys of the token bucket are associated with the unique keys of the service, the token generation speed of the token bucket is matched with the average speed of the service request, the service can be limited by building the token bucket, the system is prevented from being protected from overlarge flow, the Map set is built, the key-value relation between the unique keys of the service and the service limiter is stored in the Map set, the relation between the service request and the token bucket is saved, the service special current limiting bucket is convenient to find, the service can be respectively limited by assigning the unique keys to the service, the service can be split based on the service with finer granularity, and the service current limiting is more reasonable.
In some optional implementations of the present embodiment, before the step S202, the method further includes the following steps:
reading a service path carried in a service request;
dividing the service request into a main service request and a sub service request according to the flow of the service request of the same service path;
constructing a service unique key for a main service request of the same service path;
a unified service unique key is allocated for all secondary service requests.
In the embodiment of the application, the unique key of the service component can be used for facilitating service classification, ensuring that the service can be accurately matched with the service flow limiter, dividing the service request into the main service request and the auxiliary service request, constructing the unique key of the service for the service request in a targeted manner, and reducing the establishment of the token bucket flow limiter.
In some optional implementations of this embodiment, the token bucket restrictor comprises a plurality of sets of primary token buckets for restricting primary service requests and secondary token buckets for restricting secondary service requests; before the step S202, the method further includes the following steps:
setting up capacity b of the token bucket;
setting the number r of tokens placed in the bucket per second according to the average speed of the user service request;
Subtracting n tokens from the token bucket inner side when there is a request of n bytes;
if the service request carries out the operation of adding the tokens once before, judging whether the number of the tokens in the token bucket is larger than n;
if the number of tokens in the token bucket is greater than n, setting the size of the token bucket according to the rate of the service request, otherwise, refusing access;
wherein newly generated tokens will be discarded when the number of tokens in the token bucket is equal to b, the size of the token bucket capacity b being proportional to the average rate of service requests.
In the embodiment of the application, different restrictors are set for different services, so that the service can be subjected to refined flow restriction, and the blocking of small-flow service requests caused by the flow restriction of the service is prevented.
In some optional implementations of this embodiment, the token bucket restrictor method is:
acquiring a unique key of a service request;
traversing the Map set, and searching a token bucket matched with the service unique key from the Map set;
sending a token to the service request through a token bucket;
judging whether the service request carries a token or not, and limiting the service request which does not carry the token.
In the embodiment of the application, the relation between the service request and the token bucket is saved, the service special flow limiting bucket is conveniently searched, the services which need to be limited are judged, the response is made, the flow of the service request is limited, and the normal operation of the system is ensured.
In some optional implementations of this embodiment, the step S204 specifically includes the following steps:
the traffic request delayed by the preset time response is preferentially allocated with the current limiting token.
In some optional implementations of this embodiment, the step S206 or the step S209 described above includes the following steps:
judging whether the unprocessed business request is remained or not;
if the retained service request exists, adding the service request into a queuing sequence;
if the reserved service request does not exist, judging whether the number of tokens in the token bucket is smaller than the number of bytes of the service request;
if the number of tokens in the token bucket is smaller than the number of bytes of the service request, refusing to respond to the service request;
if the number of tokens in the token bucket is greater than or equal to the number of service request bytes, normally responding to the service request bytes, and matching the tokens for the service request.
In practical application, a request is received through an external interface of a company, then a route of the service request is judged according to an IP address of the external service request, unique keys are given to the requests of the same route, then a token bucket is built according to average request rates of different service requests, the token bucket is given to be associated with the service unique keys, the token generation speed of the token bucket is matched with the average rate of the service requests, a Map set is built, key-value relations between all the service unique keys and service restrictors are stored in the Map set, when the service request exists, the unique keys of the service request are firstly obtained, then the restrictors associated with the unique keys are found in the Map set, then tokens matched with the service request are obtained from the restrictors, when the tokens on the inner side of the token bucket are less than service request bytes, then response to the service request is refused, otherwise, normal response is performed, when no new request exists in the average rate of the service request, after the service request is responded normally, the content reflected by the database is accessed according to the service request, and the content response to the service appearance layer is displayed.
Those skilled in the art will appreciate that implementing all or part of the processes of the methods of the embodiments described above may be accomplished by way of computer readable instructions, stored on a computer readable storage medium, which when executed may comprise processes of embodiments of the methods described above. The storage medium may be a nonvolatile storage medium such as a magnetic disk, an optical disk, a Read-Only Memory (ROM), or a random access Memory (Random Access Memory, RAM).
It should be understood that, although the steps in the flowcharts of the figures are shown in order as indicated by the arrows, these steps are not necessarily performed in order as indicated by the arrows. The steps are not strictly limited in order and may be performed in other orders, unless explicitly stated herein. Moreover, at least some of the steps in the flowcharts of the figures may include a plurality of sub-steps or stages that are not necessarily performed at the same time, but may be performed at different times, the order of their execution not necessarily being sequential, but may be performed in turn or alternately with other steps or at least a portion of the other steps or stages.
Example two
With further reference to fig. 3, as an implementation of the method shown in fig. 2, the present application provides an embodiment of a token bucket-based traffic data throttling device, which corresponds to the method embodiment shown in fig. 2, and is particularly applicable to various electronic devices.
As shown in fig. 3, the token bucket-based traffic data throttling device 200 of the present embodiment includes: the request receiving module 210, the Map set reading module 220, the restrictor obtaining module 230, the token allocation module 240, the request content judging module 250, the first response module 260, the restrictor condition judging module 270, the deferred response module 280, and the second response module 290. Wherein:
a request receiving module 210, configured to receive a service request sent by a user terminal, where the service request at least carries a service path;
the Map set reading module 220 is configured to read a preset Map set, where the Map set includes service unique keys corresponding to each service path and token bucket restrictors corresponding to each service unique key;
a current limiter obtaining module 230, configured to obtain, from a preset Map set, a target service unique key corresponding to the service path and a target current limiter corresponding to the target service unique key;
A token allocation module 240, configured to allocate a current-limited token to the service request according to the target current limiter;
the request content judging module 250 is configured to judge whether the service request has a request content when the service request needs to be responded;
a first response module 260, configured to respond to the service request if the service request has no request content;
the restriction condition judging module 270 is configured to judge whether the restriction token of the service request meets the restriction condition according to the token bucket algorithm and the token bucket restrictor if the request content exists in the service request;
a postponed response module 280, configured to postpone the preset time response if the current limiting token meets the current limiting condition;
the second response module 290 is configured to respond to the service request if the current limit token does not satisfy the current limit condition.
In an embodiment of the present application, an electronic device (such as a server/terminal device shown in fig. 1) on which a token bucket-based traffic data throttling method operates may receive a request from an access interface by a terminal device through a wired connection manner or a wireless connection manner, and it should be noted that the wireless connection manner may include, but is not limited to, a 3G/4G/5G connection, a WiFi connection, a bluetooth connection, a WiMAX connection, a Zigbee connection, a UWB (ultra wideband) connection, and other now known or future developed wireless connection manners.
In the embodiment of the application, the service requests are received through the external interface, wherein the external interface can be a computing device, a network device and a storage device, the paths corresponding to the service requests can be obtained through the IP addresses of the service requests, the service requests with the same IP address are endowed with the same unique key according to the IP addresses of the service requests, and the requests with the same paths are sorted.
In the embodiment of the application, the service request carrying the service unique key can be matched with the corresponding token bucket restrictor by utilizing the preset Map set, so that the token bucket restrictor can be convenient for restricting the service request in a targeted manner.
In the embodiment of the application, the token is acquired from the Map set according to the service unique key, and different token barrels can be set for service requests of different paths through the Map set.
In the embodiment of the application, the received service requests can exist, the content is empty, and the requests are normally responded.
In the embodiment of the application, taking an insurance service scenario as an example, if an insurance company a exposes an interface to the outside, the insurance company B and the insurance company C need to call the interface, wherein the call quantity of the insurance company B is smaller, QPS is 5, the system load is not pressurized, but the call quantity of the insurance company C is extremely large, QPS is 1000, which may cause the system load to be too high, at this time, the insurance company a obtains a service unique key B1 and a service unique key C1 corresponding to the insurance company B and the insurance company C respectively according to a preset Map set, and a token bucket restrictor B2 corresponding to the service unique key B1 and a token bucket restrictor C2 corresponding to the service unique key C1, and then distributes a restrictor token B3 and a restrictor token C3 to the insurance company B and the insurance company C respectively according to the token bucket restrictor B2, when a request of the insurance company B or the insurance company C needs to be responded, firstly, whether the request of the interface is requested by the insurance company B or the insurance company C has the request content, if not has the request content, and if the request content is not requested, the request of the insurance company B or the insurance company C needs to be further differentiated according to the request of the respective restrictor C needs to be further.
In an embodiment of the present application, there is provided a service data flow limiting device 200 based on a token bucket, including: the request receiving module 210, the Map set reading module 220, the restrictor obtaining module 230, the token allocation module 240, the request content judging module 250, the first response module 260, the restrictor condition judging module 270, the deferred response module 280, and the second response module 290. Compared with the prior art, the method and the system have the advantages that the request is received through the external interface of the company, the request content is classified, unique keys are respectively assigned, the token bucket is built, the unique keys are assigned to the token bucket, the unique keys of the token bucket are associated with the unique keys of the service, the token generation speed of the token bucket is matched with the average speed of the service request, the service can be limited by building the token bucket, the system is prevented from being protected from overlarge flow, the Map set is built, the key-value relation between the unique keys of the service and the service limiter is stored in the Map set, the relation between the service request and the token bucket is saved, the service special current limiting bucket is convenient to find, the service can be respectively limited by assigning the unique keys to the service, the service can be split based on the service with finer granularity, and the service current limiting is more reasonable.
In some optional implementations of this embodiment, the apparatus 200 further includes: the system comprises a service path reading module, a request dividing module, a unique key construction module and a unique key distribution module, wherein:
the service path reading module is used for reading the service path carried in the service request;
the request dividing module is used for dividing the service requests into main service requests and auxiliary service requests according to the flow of the service requests of the same service path;
the unique key construction module is used for constructing a service unique key for the main service request of the same service path;
and the unique key distribution module is used for distributing uniform service unique keys for all the auxiliary service requests.
In some optional implementations of this embodiment, the token bucket restrictor includes a plurality of sets of primary token buckets for restricting primary service requests and a plurality of sets of secondary token buckets for restricting secondary service requests, and the apparatus 200 further includes: capacity setting module, quantity setting module, token prune module, quantity judge module and quantity judge result module, wherein:
a capacity setting module for setting up the capacity b of the token bucket;
the quantity setting module is used for setting the quantity r of tokens placed in the barrel every second according to the average speed of the user service request;
A token pruning module for subtracting n tokens from the token bucket inner side when there is a request of n bytes;
the quantity judging module is used for judging whether the quantity of tokens in the token bucket is larger than n if the business request carries out the operation of adding the tokens once before;
the number judgment result module is used for setting the size of the token bucket according to the speed of the service request if the number of tokens in the token bucket is greater than n, otherwise, refusing to access;
wherein newly generated tokens will be discarded when the number of tokens in the token bucket is equal to b, the size of the token bucket capacity b being proportional to the average rate of service requests.
In some optional implementations of this embodiment, the token bucket restrictor method is:
acquiring a unique key of a service request;
traversing the Map set, and searching a token bucket matched with the service unique key from the Map set;
sending a token to the service request through a token bucket;
judging whether the service request carries a token or not, and limiting the service request which does not carry the token.
In some optional implementations of this embodiment, the token assignment module 240 includes: a token assignment sub-module, wherein:
and the token allocation sub-module is used for preferentially allocating the current limiting token to the service request delayed by the preset time response.
In some optional implementations of this embodiment, the first response module or the second response module includes: the system comprises a retention request judging sub-module, a joining sequence sub-module, a token number judging sub-module, a refused response sub-module and a normal response sub-module, wherein:
a retention request judging sub-module for judging whether a retention unprocessed service request exists;
the joining sequence sub-module is used for joining the service request into the queuing sequence if the reserved service request exists;
the token quantity judging sub-module is used for judging whether the quantity of tokens in the token bucket is smaller than the quantity of service request bytes if no reserved service request exists;
a refusing response sub-module, configured to refuse to respond to the service request if the number of tokens in the token bucket is less than the number of bytes of the service request;
and the normal response sub-module is used for normally responding and matching the tokens for the service request if the number of the tokens in the token bucket is greater than or equal to the number of the service request bytes.
In order to solve the technical problems, the embodiment of the application also provides computer equipment. Referring specifically to fig. 4, fig. 4 is a basic structural block diagram of a computer device according to the present embodiment.
The computer device 6 comprises a memory 61, a processor 62, a network interface 63 communicatively connected to each other via a system bus. It is noted that only computer device 6 having components 61-63 is shown in the figures, but it should be understood that not all of the illustrated components are required to be implemented and that more or fewer components may be implemented instead. It will be appreciated by those skilled in the art that the computer device herein is a device capable of automatically performing numerical calculations and/or information processing in accordance with predetermined or stored instructions, the hardware of which includes, but is not limited to, microprocessors, application specific integrated circuits (Application Specific Integrated Circuit, ASICs), programmable gate arrays (fields-Programmable Gate Array, FPGAs), digital processors (Digital Signal Processor, DSPs), embedded devices, etc.
The computer device may be a desktop computer, a notebook computer, a palm computer, a cloud server, or the like. The computer device can perform man-machine interaction with a user through a keyboard, a mouse, a remote controller, a touch pad or voice control equipment and the like.
The memory 61 includes at least one type of readable storage media including flash memory, hard disk, multimedia card, card memory (e.g., SD or DX memory, etc.), random Access Memory (RAM), static Random Access Memory (SRAM), read Only Memory (ROM), electrically Erasable Programmable Read Only Memory (EEPROM), programmable Read Only Memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 61 may be an internal storage unit of the computer device 6, such as a hard disk or memory of the computer device 6. In other embodiments, the memory 61 may also be an external storage device of the computer device 6, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card) or the like, which are provided on the computer device 6. Of course, the memory 61 may also include both internal storage units of the computer device 6 and external storage devices. In this embodiment, the memory 61 is generally used for storing an operating system and various application software installed on the computer device 6, a computer readable instruction of a token bucket-based traffic data throttling method, and the like. Further, the memory 61 may also be used to temporarily store various types of data that have been output or are to be output.
The processor 62 may be a central processing unit (Central Processing Unit, CPU), controller, microcontroller, microprocessor, or other data processing chip in some embodiments. The processor 62 is typically used to control the overall operation of the computer device 6. In this embodiment, the processor 62 is configured to execute computer readable instructions stored in the memory 61 or process data, such as computer readable instructions for executing a token bucket based traffic data throttling method.
The network interface 63 may comprise a wireless network interface or a wired network interface, which network interface 63 is typically used for establishing a communication connection between the computer device 6 and other electronic devices.
The computer equipment provided by the application receives the request through the external interface of the company, classifies the request content and respectively endows the request with unique keys, establishes the token bucket, endows the token bucket with the unique keys, associates the unique keys of the token bucket with the unique keys of the service, and matches the token generation speed of the token bucket with the average speed of the service request.
The present application also provides another embodiment, namely, a computer readable storage medium, where computer readable instructions are stored, where the computer readable instructions can be executed by at least one processor, so that the at least one processor performs the steps of a token bucket based traffic data throttling method as described above.
The computer readable storage medium provided by the application receives the request through the external interface of the company, classifies the request content and respectively endows the request with unique keys, establishes the token bucket, endows the token bucket with the unique keys, associates the unique keys of the token bucket with the unique keys of the service, and matches the token generation speed of the token bucket with the average speed of the service request, can limit the service by establishing the token bucket, prevents the service from overlarge flow, protects the system, establishes the Map set, stores the key-value relation between the unique keys of the service and the service limiter into the Map set, saves the relation between the service request and the token bucket, is convenient for searching the special service limiting bucket, can respectively limit the service by endowing the unique keys of the service, can split the service based on the service with finer granularity, and ensures that the service limiting is more reasonable.
From the above description of the embodiments, it will be clear to those skilled in the art that the above-described embodiment method may be implemented by means of software plus a necessary general hardware platform, but of course may also be implemented by means of hardware, but in many cases the former is a preferred embodiment. Based on such understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art in the form of a software product stored in a storage medium (e.g. ROM/RAM, magnetic disk, optical disk) comprising several instructions for causing a terminal device (which may be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to perform the method of the embodiments of the present application.
It is apparent that the above-described embodiments are only some embodiments of the present application, but not all embodiments, and the preferred embodiments of the present application are shown in the drawings, which do not limit the scope of the patent claims. This application may be embodied in many different forms, but rather, embodiments are provided in order to provide a thorough and complete understanding of the present disclosure. Although the application has been described in detail with reference to the foregoing embodiments, it will be apparent to those skilled in the art that modifications may be made to the embodiments described in the foregoing description, or equivalents may be substituted for elements thereof. All equivalent structures made by the content of the specification and the drawings of the application are directly or indirectly applied to other related technical fields, and are also within the scope of the application.

Claims (10)

1. A method for traffic data throttling based on token buckets, comprising the steps of:
receiving a service request sent by a user terminal, wherein the service request at least carries a service path;
reading a preset Map set, wherein the Map set comprises service unique keys corresponding to each service path and token bucket restrictors corresponding to each service unique key;
acquiring a target service unique key corresponding to the service path and a target current limiter corresponding to the target service unique key from the preset Map set;
distributing a current limiting token to the service request according to the target current limiter;
when the service request needs to be responded, judging whether the service request has request content or not;
if the service request does not contain the request content, responding to the service request;
if the request content exists in the service request, judging whether a flow limiting token of the service request meets a flow limiting condition according to the token bucket algorithm and the token bucket flow limiter;
if the current limiting token meets the current limiting condition, delaying a preset time response;
and if the current limiting token does not meet the current limiting condition, responding to the service request.
2. The method for traffic data throttling as recited in claim 1, further comprising, prior to the step of reading the preset Map set, the steps of:
reading a service path carried in the service request;
dividing the service request into a main service request and a sub service request according to the flow of the service request of the same service path;
constructing a service unique key for a main service request of the same service path;
a unified service unique key is allocated for all secondary service requests.
3. The method for restricting traffic data based on token bucket according to claim 1, wherein the token bucket restrictor comprises a plurality of groups of main token buckets for restricting main traffic requests and a plurality of groups of sub token buckets for restricting sub traffic requests; before the step of reading the preset Map set, the method further comprises the following steps:
setting up capacity b of the token bucket;
setting the number r of tokens placed in the bucket per second according to the average speed of the user service request;
subtracting n tokens from the token bucket inner side when there is a request of n bytes;
if the service request carries out the operation of adding the tokens once before, judging whether the number of the tokens in the token bucket is larger than n;
If the number of tokens in the token bucket is greater than n, setting the size of the token bucket according to the rate of the service request, otherwise, refusing access;
where newly generated tokens will be discarded when the number of tokens in the token bucket is equal to b, the token bucket capacity b being proportional to the average rate of traffic requests.
4. A method for traffic data throttling based on token bucket according to claim 3, wherein: the flow limiting method of the token bucket flow limiter comprises the following steps:
acquiring a unique key of a service request;
traversing a Map set, and searching a token bucket matched with a service unique key from the Map set;
sending a token to the service request through a token bucket;
judging whether the service request carries a token or not, and limiting the service request which does not carry the token.
5. The method for traffic data throttling of claim 1, wherein said step of assigning a throttling token to said traffic request based on said target throttling device comprises the steps of:
and preferentially distributing the current limiting token for the service request delayed by the preset time response.
6. The method for traffic data throttling based on token bucket according to claim 1, wherein said step of responding to said traffic request comprises the steps of:
Judging whether the unprocessed business request is remained or not;
if the retained service request exists, adding the service request into a queuing sequence;
if the reserved service request does not exist, judging whether the number of tokens in the token bucket is smaller than the number of bytes of the service request;
if the number of tokens in the token bucket is smaller than the number of bytes of the service request, refusing to respond to the service request;
if the number of tokens in the token bucket is greater than or equal to the number of the service request bytes, normally responding to the service request bytes, and matching the tokens for the service request.
7. A token bucket based traffic data throttling device, comprising:
the request receiving module is used for receiving a service request sent by a user terminal, wherein the service request at least carries a service path;
the Map set reading module is used for reading a preset Map set, wherein the Map set comprises service unique keys corresponding to each service path and token bucket restrictors corresponding to each service unique key;
the current limiter acquisition module is used for acquiring a target service unique key corresponding to the service path and a target current limiter corresponding to the target service unique key from the preset Map set;
The token distribution module is used for distributing a flow limiting token to the service request according to the target flow limiter;
the request content judging module is used for judging whether the service request has request content or not when the service request needs to be responded;
the first response module is used for responding to the service request if the request content does not exist in the service request;
the flow limiting condition judging module is used for judging whether the flow limiting token of the service request meets the flow limiting condition according to the token bucket algorithm and the token bucket flow limiter if the request content exists in the service request;
a delay response module, configured to delay a preset time response if the current limiting token meets the current limiting condition;
and the second response module is used for responding to the service request if the current limiting token does not meet the current limiting condition.
8. The token bucket-based traffic data throttling apparatus of claim 7, wherein said apparatus further comprises:
the service path reading module is used for reading the service path carried in the service request;
the request dividing module is used for dividing the service requests into main service requests and auxiliary service requests according to the flow of the service requests of the same service path;
The unique key construction module is used for constructing a service unique key for the main service request of the same service path;
and the unique key distribution module is used for distributing uniform service unique keys for all the auxiliary service requests.
9. A computer device comprising a memory (61), a processor (62) and a network interface (63), the memory having stored therein computer readable instructions which when executed by the processor implement the steps of the current limiting method according to any of claims 1 to 6.
10. A computer readable storage medium having stored thereon computer readable instructions which when executed by a processor implement the steps of the current limiting method according to any of claims 1 to 6.
CN202310678509.0A 2023-06-08 2023-06-08 Service data flow limiting method and device, computer equipment and storage medium Pending CN116886626A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310678509.0A CN116886626A (en) 2023-06-08 2023-06-08 Service data flow limiting method and device, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310678509.0A CN116886626A (en) 2023-06-08 2023-06-08 Service data flow limiting method and device, computer equipment and storage medium

Publications (1)

Publication Number Publication Date
CN116886626A true CN116886626A (en) 2023-10-13

Family

ID=88257575

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310678509.0A Pending CN116886626A (en) 2023-06-08 2023-06-08 Service data flow limiting method and device, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN116886626A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117556452A (en) * 2024-01-10 2024-02-13 支付宝(杭州)信息技术有限公司 Access control method for database and related equipment

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117556452A (en) * 2024-01-10 2024-02-13 支付宝(杭州)信息技术有限公司 Access control method for database and related equipment

Similar Documents

Publication Publication Date Title
JP7127010B2 (en) Resource allocation methods, apparatus, electronic equipment, computer readable media and computer programs
US9747201B2 (en) Methods and systems for managing memory allocation
CN107943854B (en) Credit investigation service query method, apparatus and computer readable storage medium
CN112199442B (en) Method, device, computer equipment and storage medium for distributed batch downloading files
CN112182004B (en) Method, device, computer equipment and storage medium for checking data in real time
CN112835904A (en) Data processing method and data processing device
CN116886626A (en) Service data flow limiting method and device, computer equipment and storage medium
CN112468409A (en) Access control method, device, computer equipment and storage medium
CN111901490A (en) Resource sharing method, device, computer device and storage medium
CN112600761A (en) Resource allocation method, device and storage medium
CN113806300A (en) Data storage method, system, device, equipment and storage medium
CN111813517A (en) Task queue allocation method and device, computer equipment and medium
CN111142799A (en) Distributed storage method and device, network node and storage medium
CN114070847B (en) Method, device, equipment and storage medium for limiting current of server
CN108520401B (en) User list management method, device, platform and storage medium
CN110162395B (en) Memory allocation method and device
CN111259429A (en) Resource operation authority control method and device and electronic equipment
CN111291045A (en) Service isolation data transmission method and device, computer equipment and storage medium
CN116644144A (en) Extension number storage method, privacy number binding method and related devices
CN113254106B (en) Task execution method and device based on Flink, computer equipment and storage medium
CN116319810A (en) Flow control method, device, equipment, medium and product of distributed system
US11233847B1 (en) Management of allocated computing resources in networked environment
CN111161067A (en) Method and device for determining transaction route
US10956037B2 (en) Provisioning storage allocation using prioritized storage system capabilities
CN115291937A (en) Method, device, equipment and storage medium for integrating data of smart card

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination