CN108494703B - Access frequency control method, device and storage medium - Google Patents

Access frequency control method, device and storage medium Download PDF

Info

Publication number
CN108494703B
CN108494703B CN201810191962.8A CN201810191962A CN108494703B CN 108494703 B CN108494703 B CN 108494703B CN 201810191962 A CN201810191962 A CN 201810191962A CN 108494703 B CN108494703 B CN 108494703B
Authority
CN
China
Prior art keywords
token
service
frequency control
access
client
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.)
Active
Application number
CN201810191962.8A
Other languages
Chinese (zh)
Other versions
CN108494703A (en
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.)
Tencent Technology Shenzhen Co Ltd
Tencent Cloud Computing Beijing Co Ltd
Original Assignee
Tencent Technology Shenzhen Co Ltd
Tencent Cloud Computing Beijing Co 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 Tencent Technology Shenzhen Co Ltd, Tencent Cloud Computing Beijing Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN201810191962.8A priority Critical patent/CN108494703B/en
Publication of CN108494703A publication Critical patent/CN108494703A/en
Application granted granted Critical
Publication of CN108494703B publication Critical patent/CN108494703B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

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
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/60Scheduling or organising the servicing of application requests, e.g. requests for application data transmissions using the analysis and optimisation of the required network resources

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer And Data Communications (AREA)

Abstract

The embodiment of the invention discloses an access frequency control method, a device and a storage medium, wherein the embodiment of the invention receives a service access request sent by a client, wherein the service access request carries a client identifier; determining a token bucket identifier corresponding to the client identifier, and inquiring a local token bucket corresponding to the token bucket identifier; when the access frequency of the client is determined to be greater than a preset threshold value according to the tokens in the local token bucket, sending a token application request to the frequency control server cluster; and receiving a token returned by the frequency control server cluster based on the token application request, and providing access service for the service corresponding to the service access request according to the obtained token. According to the scheme, the tokens in the local token bucket corresponding to each client can be maintained according to the client identification, the pre-stored tokens in the token bucket are maintained through the frequency control server cluster, the access frequency of the clients is effectively controlled through the tokens in the token bucket, and the accuracy of controlling the access frequency is improved.

Description

Access frequency control method, device and storage medium
Technical Field
The present invention relates to the field of communications technologies, and in particular, to a method and an apparatus for controlling access frequency, and a storage medium.
Background
Generally, a service server in a network faces massive clients, wherein large-scale access caused by malicious attack, traffic surge or activity and the like is not lacked, and if access frequency of a certain client is not effectively controlled, the whole cluster of the service server is easily crashed, so that normal access of other clients is influenced.
In the prior art, when access frequency needs to be controlled, a frequency control module is generally deployed on a single service server in a service server cluster, and access restriction is made on a certain Internet Protocol (IP) or a client with some characteristics and the like by the frequency control module; or, the frequency control module is separately deployed in the service server cluster, and the frequency control module uniformly limits the access of all the clients.
In the research and practice process of the prior art, the inventor of the invention finds that the access frequency of a single service server is controlled, and when the cluster load is uneven, the access frequency is easily controlled to be inaccurate, so that the service is threatened, namely the execution of the service is influenced; the frequency control module separately arranged in the service server cluster faces the impact of a Query Per Second (QPS) with a high frequency, and when the QPS is very high or the network is abnormal or the frequency control module is abnormal, there is a risk of the service server crashing, so that the service server cannot effectively control the access frequency.
Disclosure of Invention
The embodiment of the invention provides an access frequency control method, an access frequency control device and a storage medium, and aims to improve the accuracy of controlling access frequency.
In order to solve the above technical problems, embodiments of the present invention provide the following technical solutions:
an access frequency control method comprising:
receiving a service access request sent by a client, wherein the service access request carries a client identifier;
determining a token bucket identifier corresponding to the client identifier, and querying a local token bucket corresponding to the token bucket identifier;
when the access frequency of the client is determined to be greater than a preset threshold value according to the tokens in the local token bucket, sending a token application request to a frequency control server cluster;
and receiving a token returned by the frequency control server cluster based on the token application request, and providing access service for the service corresponding to the service access request according to the obtained token.
An access frequency control device comprising:
the first receiving unit is used for receiving a service access request sent by a client, wherein the service access request carries a client identifier;
the determining unit is used for determining a token bucket identifier corresponding to the client identifier and inquiring a local token bucket corresponding to the token bucket identifier;
the sending unit is used for sending a token application request to the frequency control server cluster when the access frequency of the client is determined to be greater than a preset threshold value according to the tokens in the local token bucket;
and the control unit is used for receiving the token returned by the frequency control server cluster based on the token application request and providing access service for the service corresponding to the service access request according to the obtained token.
A storage medium storing a plurality of instructions adapted to be loaded by a processor to perform the steps of the above-mentioned access frequency control method.
When a service access request carrying a client identifier and sent by a client is received, the embodiment of the invention can determine the token bucket identifier corresponding to the client identifier and inquire the local token bucket corresponding to the token bucket identifier; when the access frequency of the client is determined to be greater than a preset threshold value according to the tokens in the local token bucket, sending a token application request to the frequency control server cluster; and then receiving a token returned by the frequency control server cluster based on the token application request, and providing access service for the service corresponding to the service access request according to the obtained token. According to the scheme, the tokens in the local token bucket corresponding to each client can be maintained according to the client identification, the pre-stored tokens in the token bucket are maintained through the frequency control server cluster, the access frequency of the clients is effectively controlled through the tokens in the token bucket, and the accuracy of controlling the access frequency is improved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the description below are only some embodiments of the present invention, and it is obvious for those skilled in the art that other drawings can be obtained based on these drawings without creative efforts.
Fig. 1 is a schematic view of a scenario of an access frequency control system according to an embodiment of the present invention;
fig. 2 is a schematic flowchart of an access frequency control method according to an embodiment of the present invention;
FIG. 3 is an architecture diagram of access frequency control provided by an embodiment of the present invention;
fig. 4 is another schematic flow chart of an access frequency control method according to an embodiment of the present invention;
FIG. 5 is a schematic diagram of token interaction for access frequency control provided by an embodiment of the present invention;
FIG. 6 is a schematic diagram of storage server cluster versus access frequency storage according to an embodiment of the present invention;
fig. 7 is a schematic structural diagram of an access frequency control apparatus according to an embodiment of the present invention;
fig. 8 is another schematic structural diagram of an access frequency control device according to an embodiment of the present invention;
fig. 9 is another schematic structural diagram of an access frequency control apparatus according to an embodiment of the present invention;
fig. 10 is another schematic structural diagram of an access frequency control apparatus according to an embodiment of the present invention;
fig. 11 is another schematic structural diagram of an access frequency control apparatus according to an embodiment of the present invention;
fig. 12 is a schematic structural diagram of a server according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The embodiment of the invention provides an access frequency control method, an access frequency control device and a storage medium.
Referring to fig. 1, fig. 1 is a schematic view of a scenario of an access frequency control system according to an embodiment of the present invention, where the access frequency control system may include an access frequency control device, and the access frequency control device may be specifically integrated in a server cluster, for example, a service server cluster, and is mainly used to receive a service access request sent by a client, where the service access request may carry a client identifier, and the client identifier may be a client name or a client number, and may be composed of numbers, letters, and/or characters. Then, determining a token bucket identifier corresponding to the client identifier, and inquiring a local token bucket corresponding to the token bucket identifier; when the access frequency of the client is determined to be larger than a preset threshold value according to the token in the local token bucket, sending a token application request to the frequency control server cluster; for example, when no token exists in the local token bucket, it is indicated that the access frequency of the client is high, and it is determined that the access frequency of the client is greater than a preset threshold, at this time, a token application request is sent to the frequency control server cluster. And finally, receiving a token returned by the frequency control server cluster based on the token application request, providing access service for the service corresponding to the service access request according to the obtained token, and the like.
In addition, the access frequency control system may further include a frequency control server cluster, where the frequency control server cluster is mainly configured to receive a token application request sent by the service server cluster, query a pre-stored token bucket according to the token application request, and return a token required by the token application request to the service server cluster when the token bucket exists.
It should be noted that the scenario diagram of the access frequency control system shown in fig. 1 is merely an example, and the access frequency control system and the scenario described in the embodiment of the present invention are for more clearly illustrating the technical solution of the embodiment of the present invention, and do not form a limitation on the technical solution provided in the embodiment of the present invention.
The following are detailed below.
In this embodiment, a description will be given from the perspective of an access frequency control device, which may be specifically integrated in a network device such as a server cluster or a gateway.
An access frequency control method comprising: receiving a service access request sent by a client, wherein the service access request carries a client identifier; determining a token bucket identifier corresponding to the client identifier, and inquiring a local token bucket corresponding to the token bucket identifier; when the access frequency of the client is determined to be greater than a preset threshold value according to the tokens in the local token bucket, sending a token application request to the frequency control server cluster; and receiving a token returned by the frequency control server cluster based on the token application request, and providing access service for the service corresponding to the service access request according to the obtained token.
Referring to fig. 2, fig. 2 is a flowchart illustrating an access frequency control method according to an embodiment of the invention. The access frequency control method may include:
in step S101, a service access request sent by a client is received, where the service access request carries a client identifier.
The client can be integrated on a terminal such as a mobile phone or a computer, when a certain service needs to be executed on the terminal, a service access request can be sent to the access frequency control device through the client, the access frequency control device receives the service access request, and the service access request can carry information such as a service identifier and a client identifier. The client identifier may be a client name or a client number, and may be composed of numbers, letters, and/or words, and the specific content is not limited herein. The type of the service access request may be flexibly set according to actual needs, for example, the service access request may be a mail service access request or a microblog service access request, and specific contents are not limited herein.
It should be noted that the access frequency control device may be a service server cluster (also referred to as a service cluster), where the service server cluster may include one or more service server clusters, where a plurality of service server clusters may include a plurality of service server clusters that provide different types of service services for clients, for example, a mail service server cluster or a microblog service server cluster, and correspondingly may provide mail service or microblog service for clients, respectively; each service server cluster can comprise a plurality of service servers of the same service type. The service server cluster may include one or more access servers and one or more frequency control proxy servers. When receiving a service access request sent by a client, a service server cluster may transfer the service access request to a certain access server, and the access server initiates a frequency control request to a frequency control proxy server (also referred to as a frequency control Agent), so that the frequency control proxy server controls the access frequency of the client according to the frequency control request.
In step S102, a token bucket identifier corresponding to the client identifier is determined, and a local token bucket corresponding to the token bucket identifier is queried.
In order to effectively control the access frequency of each client, the access frequency control device may maintain a mapping relationship between the client and the local token bucket by using an identifier in advance, that is, establish a mapping relationship between the client identifier and the token bucket identifier, so that each client has a local token bucket corresponding to the client. The token bucket identifier may be a token bucket name or a token bucket number, and may be composed of numbers, letters, and/or words, and the specific content is not limited herein.
The local token bucket may store tokens therein, and is mainly used to control access frequency of the client, for example, whether the client is allowed to access may be indicated by whether the token exists in the local token bucket, that is, if the token exists in the local token bucket, the client may be provided with access service, and if the token does not exist in the local token bucket, the client is not provided with access service. Each token in the local token bucket may represent a number of times access services are provided for the client, e.g., one token may provide one or more access services for the client; alternatively, each token in the local token bucket may represent a time period for providing access services to the client, e.g., one token may provide access services to the client in 1 or 3 seconds; alternatively, each token in the local token bucket may represent the number of times that access service is provided to the client per second, i.e., each token in the local token bucket may represent the number of times that the client is allowed to access per second (i.e., the access frequency of the client), and so on. It is understood that the rights that the token can represent can be flexibly set according to actual needs, and specific contents are not limited herein.
The work process of the local token bucket can comprise the following steps: generating tokens, consuming tokens, determining whether to provide access services for clients, and the like. The token generation may be periodically adding tokens to the local token bucket at a preset rate, so that the number of tokens in the local token bucket is continuously increased, and if the number of tokens in the local token bucket exceeds a preset number threshold, the redundant tokens may be discarded. The consumption token may be a token that is consumed in a local token bucket when providing access services for the client in order to count the client access frequency, which may be the number of accesses per second, or the number of accesses per minute, etc. Judging whether to provide the access service for the client side or not can be that when the number of tokens in the local token bucket can meet the requirement of the service corresponding to the service access request on the tokens, the access service can be provided for the client side, otherwise, the access service is not provided for the client side.
After receiving a service access request carrying a client identifier sent by a client, the access frequency control device may extract the client identifier from the service access request, and determine a token bucket identifier corresponding to the client identifier according to a mapping relationship between the client identifier and the token bucket identifier. And then obtaining a local token bucket corresponding to the token bucket identification, and inquiring the local token bucket, wherein the local token bucket can be a token bucket locally preset by the access frequency control device. That is, when the access frequency of the client is determined according to the tokens in the local token bucket, for example, when the tokens exist in the local token bucket, it may be determined that the access frequency of the client is less than or equal to a preset threshold; when no token exists in the local token bucket, it may be determined that the access frequency of the client is greater than a preset threshold.
In some embodiments, after the step of determining a token bucket identifier corresponding to the client identifier and querying the local token bucket corresponding to the token bucket identifier, the access frequency control method may further include:
when the token exists in the local token bucket, obtaining the token required by the service access request from the local token bucket; and providing access service for the service corresponding to the service access request according to the acquired token.
In the process of querying the local token bucket, when a token exists in the local token bucket, the access frequency control device indicates that the access frequency of the client is less than or equal to a preset threshold, and at this time, a token required by the service access request can be acquired from the local token bucket. The preset threshold value can be flexibly set according to actual needs, the number of tokens required by the service access request can be one or more, and when the number of tokens required by the service access request is multiple, the tokens required by the service access request can be acquired from the local token bucket when the token required by the service access request exists in the local token bucket. After the token is acquired, the access frequency control device may provide access service for the service corresponding to the service access request according to the acquired token.
It should be noted that, when each token in the token bucket represents the number of times of providing access service for the client in each period, and the frequency control device queries that a token exists in the local token bucket, it may determine whether the token in the local token bucket needs to be updated at the current time, for example, if the current time is still in the current token period, the token in the local token bucket is not updated; and if the current time already enters the next new token cycle, deducting the tokens required by the service access request from the local token bucket, and updating the tokens in the local token bucket. When the token is updated successfully, the access service can be provided for the client; and when the token updating fails, retrying for a preset number of times, if the token updating succeeds, providing access service for the client, if the token updating fails, not providing the access service for the client, and returning failure information to the client.
In step S103, when it is determined that the access frequency of the client is greater than the preset threshold according to the token in the local token bucket, a token application request is sent to the frequency control server cluster.
In the process of querying the local token bucket, when determining that the access frequency of the client is greater than the preset threshold according to the token in the local token bucket, the access frequency control device indicates that the access frequency of the client is greater, for example, when it is queried that no token exists in the local token bucket, it may be determined that the access frequency of the client is greater than the preset threshold; or, when the number of the tokens in the local token bucket is smaller than the preset number, it may be determined that the access frequency of the client is greater than a preset threshold; the preset number and the preset threshold value can be flexibly set according to actual needs, and specific contents are not limited here. When the access frequency of the client is determined to be greater than the preset threshold value according to the tokens in the local token bucket, in order to determine whether the access frequency of the client can be increased, the access frequency control device may send a token application request to the frequency control server cluster.
The frequency control server clusters may include one or more frequency control server clusters, the multiple frequency control server clusters may include frequency control server clusters that provide different types of frequency control services for the multiple service server clusters, each frequency control server cluster may include multiple frequency control servers of the same frequency control type, and one frequency control server may provide a frequency control service for one service server.
In some embodiments, the step of sending the token application request to the frequency control server cluster may include: judging whether the client identification is in a preset white list or not; and if the client identification is in a preset white list, sending a token application request to the frequency control server cluster.
Specifically, the access frequency control device may preset a black and white list, where the black list may store a client identifier corresponding to a client that limits access frequency, that is, for a client in the black list, only a token in a local token bucket may be used, and when no token exists in the local token bucket, a token application request may not be sent to the frequency control server cluster; the white list may store a client identifier corresponding to a client that may increase access frequency, that is, for a client in the white list, when no token exists in the local token bucket, a token application request may be sent to the frequency control server cluster.
It can be understood that the access frequency control device may also preset an unlimited access list and a prohibited access list, and the like, wherein clients in the unlimited access list may access without controlling their access frequency for unlimited times, and clients in the prohibited access list may not access.
When the access frequency of the client is determined to be greater than a preset threshold value according to the tokens in the local token bucket, the access frequency control device can judge whether the client identifier is in a preset white list; and if the client identification is in a preset white list, sending a token application request to the frequency control server cluster. And if the client identification is not in the preset white list, not sending a token application request to the frequency control server cluster, and refusing to provide access service for the client corresponding to the client identification.
Optionally, if the client identifier is in a preset white list, the step of sending a token application request to the frequency control server cluster may include: when the client identifier is in a preset white list, generating a token in a preset period; and when the produced token cannot meet the token required by the service access request, sending a token application request to the frequency control server cluster.
Specifically, the tokens in the local token bucket may be pre-allocated by the frequency control server cluster, or may be pre-produced by the local token bucket, and the number of tokens in the local token bucket corresponding to different clients may be flexibly set according to actual needs. When the client identifier is in the preset white list, it is indicated that the client corresponding to the client identifier can increase the access frequency, the access frequency control device can produce a preset number of tokens every preset period, and at this time, the access frequency control device produces tokens in the preset period. When the produced token cannot meet the token required by the service access request, the access frequency control device can send a token application request to the frequency control server cluster.
In some embodiments, after the step of sending a token application request to the frequency control server cluster when it is determined that the access frequency of the client is greater than the preset threshold according to the tokens in the local token bucket, the access frequency control method may further include:
when the frequency control server cluster queries that no token exists in a pre-stored token bucket, receiving token application failure information returned by the frequency control server cluster based on the token application request; and refusing to provide access service for the service corresponding to the service access request based on the token application failure information.
Specifically, after the access frequency control device sends a token application request to the frequency control server cluster, the frequency control server cluster may query whether a token exists in a pre-stored token bucket, where the token bucket is preset for the frequency control server cluster, the token bucket may store a token, and the representative meaning of the token in the token bucket and the working process of the token bucket are similar to those of a local token bucket, and are not described herein again. When the frequency control server cluster queries that no token exists in the token bucket, the current access frequency of each client is high, at the moment, the frequency control server cluster returns token application failure information to the access frequency control device based on the token application request, and the access frequency control device receives the token application failure information. And after receiving the token application failure information, the access frequency control device can refuse to provide access service for the service corresponding to the service access request. Therefore, the problem that the access frequency of the client is flexibly limited when the flow of the client suddenly increases (namely the access frequency suddenly increases) can be effectively solved, and the safety and the stability of the access frequency control device (namely a service server cluster) are protected.
It should be noted that, after receiving the token application request, the frequency control server cluster may extract a service server identifier that the service access request needs to access from the token application request, determine, according to a preset mapping relationship between the service server identifier and the frequency control server identifier, a frequency control server identifier corresponding to the service server identifier, and acquire, from the frequency control server cluster, a frequency control server corresponding to the frequency control server identifier. The frequency control server can inquire the tokens in a pre-stored token bucket, when the frequency control server inquires that no token exists in the token bucket, the frequency control server returns token application failure information to the access frequency control device, and when the frequency control server inquires that no token exists in the token bucket, the frequency control server returns the token required by the token application request to the access frequency control device.
In step S104, a token returned by the frequency control server cluster based on the token application request is received, and an access service is provided for a service corresponding to the service access request according to the obtained token.
After the access frequency control device sends a token application request to the frequency control server cluster, the frequency control server cluster can inquire whether a token exists in a pre-stored token bucket or not, and when the frequency control server cluster inquires that the token exists in the token bucket, the frequency control server cluster returns the token to the access frequency control device based on the token application request. And the access frequency control device receives the token returned by the frequency control server cluster and provides access service for the service corresponding to the service access request according to the obtained token. The load of the frequency control server cluster can be effectively shared by the local token bucket preset by the access frequency control device, so that a buffer is arranged between the access frequency control device and the frequency control server cluster, the access frequency of a client to the frequency control server cluster is reduced, the pressure of the frequency control server cluster can be greatly reduced, larger access impact can be supported, and meanwhile, when the frequency control server cluster has a problem, the access frequency control device can control the access frequency of the client through the local token bucket, so that the fault tolerance of the access frequency control device is reduced to the greatest extent.
It should be noted that the access frequency control device may be a service server cluster, the service server cluster may include an access server and a frequency control proxy server, and the frequency control server cluster may include a frequency control logic cluster and a storage server cluster (also referred to as a storage cluster), and the number of the access server and the frequency control proxy server in the service server cluster, and the number of the frequency control logic cluster and the storage server cluster in the frequency control server cluster may be flexibly set according to actual needs. For example, as shown in fig. 3, a client may send a service access request to a cluster of service servers, which load balances the service access request to access servers in the cluster of service servers. And after receiving the service access request, the access server sends a frequency control request to a frequency control proxy server in the service server cluster. After receiving the frequency control request, the frequency control proxy server queries the local token bucket. And when the access frequency of the client is determined to be greater than a preset threshold value according to the token in the local token bucket, the frequency control proxy server sends a token application request to a frequency control logic cluster in the frequency control server cluster. And after receiving the token application request, the frequency control logic cluster sends a token updating request to a storage server cluster in the frequency control server cluster. After receiving the token update request, the storage server cluster queries a pre-stored token bucket. And when the token exists in the token bucket inquired by the storage server cluster, deducting the token required by the token application request from the token bucket, and returning an updating result to the frequency control logic cluster. And after receiving the updating result, the frequency control logic cluster returns the token required by the token application request to the frequency control proxy server. And the frequency control proxy server stores the received token into a local token bucket, subtracts the token required by the service access request from the local token bucket, and returns a result of subtracting the token to the access server, so that the access server provides access service for the service corresponding to the service access request to process the service corresponding to the service access request.
In some embodiments, the step of providing an access service for the service corresponding to the service access request according to the obtained token may include:
storing the obtained token to a local token bucket; obtaining tokens required by the service access request from a local token bucket; and providing access service for the service corresponding to the service access request according to the token required by the acquired service access request.
Specifically, after receiving a token returned by the frequency control server cluster based on the token application request, the access frequency control device may store the obtained token in a local token bucket in order to facilitate statistics on the access frequency of the client; and then, obtaining tokens required by the service access request from the local token bucket, counting the access frequency of the client according to the tokens consumed in the local token bucket, and providing access service for the service corresponding to the service access request according to the obtained tokens required by the service access request, namely processing the service corresponding to the service access request.
Optionally, the step of obtaining the token required by the service access request from the local token bucket may include: judging whether the current moment is in the current token period; and if the current moment is not in the current token period, obtaining tokens required by the service access request from the local token bucket, and updating the number of the tokens in the local token bucket.
An expiration date may be set for the tokens in the local token bucket, and the expiration date of one token may be used one or more times, or used within a preset time period, etc. When the frequency control device obtains the tokens required by the service access request from the local token bucket, whether the number of the tokens in the local token bucket needs to be updated at the current moment can be judged, namely whether the current moment is in the current token period is judged, and if the current moment is in the current token period, the number of the tokens in the local token bucket does not need to be updated; and if the current time is within the next token period, deducting the tokens required by the service access request from the local token bucket, and updating the number of the tokens in the local token bucket. When the token quantity is updated successfully, the access service can be provided for the client; and when the token quantity updating fails, retrying preset times, if the token quantity updating fails, providing access service for the client, and if the token quantity updating fails, not providing the access service for the client, and returning failure information to the client.
As can be seen from the above, when receiving a service access request carrying a client identifier sent by a client, the embodiment of the present invention may determine a token bucket identifier corresponding to the client identifier, and query a local token bucket corresponding to the token bucket identifier; when the access frequency of the client is determined to be greater than a preset threshold value according to the tokens in the local token bucket, sending a token application request to the frequency control server cluster; and then receiving a token returned by the frequency control server cluster based on the token application request, and providing access service for the service corresponding to the service access request according to the obtained token. According to the scheme, the tokens in the local token bucket corresponding to each client can be maintained according to the client identification, the pre-stored tokens in the token bucket are maintained through the frequency control server cluster, the access frequency of the clients is effectively controlled through the tokens in the token bucket, and the accuracy of controlling the access frequency is improved.
The method described in the above embodiments is further illustrated in detail by way of example.
In this embodiment, the access frequency control device is taken as an example of a service server cluster (also referred to as a service cluster), and the service server cluster may include one or more service server clusters, where a plurality of service server clusters may include a plurality of service server clusters that provide different types of service services for clients, and each service server cluster may include a plurality of service servers of the same service type. The service server cluster may include one or more access servers and one or more frequency control proxy servers. The frequency control server cluster may include one or more frequency control server clusters, the multiple frequency control server clusters may include frequency control server clusters providing different types of frequency control services for the multiple traffic server clusters, each frequency control server cluster may include multiple frequency control servers of the same frequency control type, the frequency control server cluster may include a frequency control logic cluster and a storage server cluster (also referred to as a storage cluster), and the like, and the frequency control logic cluster and the storage server cluster may each include one or more frequency control servers.
For convenience of description, in the embodiment of the present invention, one of a client, one of an access server and a frequency control proxy server in a service server cluster, and one of a frequency control logic cluster and a storage server cluster in a frequency control server cluster are taken as examples, it is understood that this embodiment is only an example for convenience of description, and is not to be construed as a limitation on the number of the client, the service server cluster and an access server and a frequency control proxy server included therein, and the frequency control server cluster and a frequency control logic cluster and a storage server cluster included therein, but the access frequency control process is similar regardless of the number, and can be understood according to this example.
Referring to fig. 4, fig. 4 is a flowchart illustrating an access frequency control method according to an embodiment of the present invention. The method flow can comprise the following steps:
201. the client sends a service access request to the service server cluster, and the service server cluster balances the load of the service access request to the access servers in the service server cluster.
When a certain service needs to be executed, the client may send a service access request to the service server cluster, where the service access request may carry information such as a service identifier and a client identifier. The service identifier may be used to indicate a service type corresponding to the service access request, and the service type corresponding to the service access request may be flexibly set according to actual needs, for example, the service type may be a mail service access request or a microblog service access request, and specific contents are not limited herein. The service identifier may be a service name or a service number, and may be composed of numbers, letters, and/or words, and the specific content is not limited herein. The client identifier is used to indicate a client, and the client identifier may be a client name or a client number, and may be composed of numbers, letters, and/or words, and the specific content is not limited herein. After receiving the service access request, the service server cluster can balance the load of the service access request to the access servers in the service server cluster.
202. And after receiving the service access request, the access server sends a frequency control request to a frequency control proxy server in the service server cluster.
After receiving the service access request, the access server may send a frequency control request to a frequency control proxy server in the service server cluster, where the frequency control request may carry information such as a service identifier and a client identifier, so that the frequency control proxy server controls the access frequency of the client according to the frequency control request.
203. After receiving the frequency control request, the frequency control proxy server queries the local token bucket.
After receiving the frequency control request, the frequency control proxy server can extract the client identifier from the frequency control request, and determine the token bucket identifier corresponding to the client identifier according to the mapping relationship between the client identifier and the token bucket identifier which is established in advance. And then obtaining a local token bucket corresponding to the token bucket identification, and inquiring the local token bucket, wherein the local token bucket can be a token bucket preset locally by the frequency control proxy server.
If the token does not exist in the local token bucket, the access service is not provided for the client. Each token in the local token bucket may represent a number of times that the access service is provided for the client, or each token in the local token bucket may represent a time period that the access service is provided for the client, or each token in the local token bucket may represent a number of times that the access service is provided for the client per second (i.e., an access frequency of the client), etc. It is understood that the rights that the token can represent can be flexibly set according to actual needs, and specific contents are not limited herein.
In the process of querying the local token bucket, when a token exists in the local token bucket, the frequency control proxy server may obtain a token required by the service access request from the local token bucket. After the token is obtained, the frequency control proxy server deducts the token required by the service access request from the local token bucket and returns the deducted token to the access server, and the access server can provide access service for the service corresponding to the service access request according to the obtained token.
It should be noted that when each token in the token bucket represents the number of times of providing access service for the client in each period, for example, 1000 times of access per second, when the frequency control proxy server queries that there is a token in the local token bucket, if the current time is in the current token period, the token in the local token bucket may not be updated (i.e., the token is not subtracted); and if the current time has entered the next token cycle, deducting the tokens required by the service access request from the local token bucket, and updating the tokens in the local token bucket. For example, assuming that the client is allowed to access 1000 times per second, the current token cycle is 50 th second, if the current time is within 50 th second, the token is not deducted; if the current time goes to 51 seconds, the token is deducted. When the token is updated successfully, the access service can be provided for the client; and when the token updating fails, retrying for a preset number of times, if the token updating succeeds, providing access service for the client, if the token updating fails, not providing the access service for the client, and returning failure information to the client. For unused tokens, the frequency control proxy server may discard directly or may revert back to the local token bucket.
It should be noted that the frequency control proxy server may not only consume the tokens, but also may produce the tokens, for example, as shown in fig. 5, the frequency control proxy server may be used as a producer, may periodically produce the tokens at a preset rate, and stores the produced tokens in a local token bucket (i.e., the token bucket in fig. 5), where the local token bucket may be a shared memory of the frequency control proxy server, and the shared memory may be a data structure for storing the local token bucket; or, the frequency control proxy server periodically applies for a token from the frequency control server cluster, and writes the applied token into the shared memory. The frequency control user may be a device using the access frequency control method, such as an access server consuming tokens, and the frequency control user may consume the tokens in a multi-process or multi-thread mode. For example, when the access frequency of the client needs to be controlled, the frequency control user may request the frequency control from the shared memory in parallel or in series through the process 1, the process 2, the process 3, the process 4, and the like, so as to obtain a required token from the shared memory.
In particular, the process of consuming tokens may be as follows: and when the frequency control user needs to consume the token, applying for the token number from the shared memory, if the token number in the shared memory is 0, directly returning to the frequency control overrun of the frequency control user, and if the token number in the shared memory is not 0, applying for the token by the frequency control user and executing subsequent operation. If the number of the tokens is not 0, the shared memory needs to update the tokens, and if the tokens are updated successfully, the information of successful update of the client is returned; if the token updating fails, the client will retry for a certain number of times, if the token updating succeeds, the client updating success information is returned, and if the token updating fails, the client updating failure information is returned. If the token required by the request of frequency control does not exist, the frequency control user informs the frequency control proxy server to produce the token, the frequency control proxy server produces the token in a certain period, and the frequency control proxy server maintains the update of the token in the token period.
204. And when the access frequency of the client is determined to be greater than a preset threshold value according to the token in the local token bucket, the frequency control proxy server sends a token application request to a frequency control logic cluster in the frequency control server cluster.
In the process of inquiring the local token bucket, when determining that the access frequency of the client is greater than a preset threshold value according to the token in the local token bucket, the frequency control proxy server indicates that the access frequency of the client is greater, for example, when inquiring that no token exists in the local token bucket, the frequency control proxy server can determine that the access frequency of the client is greater than the preset threshold value; or, when the number of the tokens in the local token bucket is smaller than the preset number, it may be determined that the access frequency of the client is greater than a preset threshold; the preset number and the preset threshold value can be flexibly set according to actual needs, and specific contents are not limited here. When the access frequency of the client is determined to be greater than the preset threshold value according to the token in the local token bucket, the frequency control proxy server sends a token application request to a frequency control logic cluster in the frequency control server cluster, wherein the token application request can carry information such as the required token quantity, the service identification and the client identification.
It should be noted that the frequency control proxy server may also preset a black and white list, where a client in the black list can only use a token in the local token bucket, and when no token exists in the local token bucket, a token application request may not be sent to the frequency control server cluster; for clients in the white list, when no token exists in the local token bucket, a token application request may be sent to the frequency control server cluster.
When the access frequency of the client is determined to be greater than a preset threshold value according to the tokens in the local token bucket, the frequency control proxy server can judge whether the client identifier is in a preset white list; and if the client identification is in a preset white list, sending a token application request to a frequency control logic cluster in the frequency control server cluster. And if the client identification is not in the preset white list, refusing to provide access service for the client corresponding to the client identification.
205. And after receiving the token application request, the frequency control logic cluster sends a token updating request to a storage server cluster in the frequency control server cluster.
The storage server cluster is mainly responsible for storing the access frequency condition of the client within a time period, and the storage server cluster can store the access frequency of the client by adopting a Key-Value storage (namely KV storage) system. The frequency control logic cluster may be responsible for issuing tokens, storing frequency control times, managing frequency control policies, black and white list control, personalized control for clients (e.g., some clients may reduce access frequency, some clients may increase access frequency, some users may be prohibited from accessing, etc.), and managing interactions with the storage server cluster. After receiving the token application request, the frequency control logic cluster may send a token update request to a storage server cluster in the frequency control server cluster, where the token update request may carry information such as the number of tokens, a service identifier, and a client identifier, so as to obtain the token from the storage server cluster.
For example, as shown in fig. 6, for an access of a client a in a time period 1, the frequency control logic cluster may apply for a token 1 from the storage server cluster (and the storage server cluster) according to a token identifier 1 in the time period 1, that is, send a token 1 update request to the storage server cluster, at this time, the storage server cluster may store an access frequency situation of the client a in the time period 1 according to the token identifier 1, and the token identifier 1 may identify an access frequency of the client a in the time period 1. Similarly, the access in time period 2, the access in time period 3, the access in time period 4, the access in time period 5, and the like may be similar to the access in time period 1, and are not described herein again.
206. After receiving the token update request, the storage server cluster queries a pre-stored token bucket.
The storage server cluster can be pre-stored with a token bucket, the token bucket mainly controls the access frequency of the client by combining with a local token bucket of the frequency control proxy server, the storage server cluster can produce tokens at preset time intervals and store the tokens into the token bucket, if the tokens exist in the token bucket, access service can be provided for the client, and if the tokens do not exist in the token bucket, access service is not provided for the client. Each token in the token bucket may represent a number of times that the access service is provided for the client, or each token in the token bucket may represent a time period that the access service is provided for the client, or each token in the token bucket may represent a number of times that the access service is provided for the client per second (i.e., an access frequency of the client), etc. It is understood that the rights that the token can represent can be flexibly set according to actual needs, and specific contents are not limited herein.
After receiving the token update request, the storage server cluster may query a pre-stored token bucket to determine whether a token exists in the token bucket.
207. And when the token exists in the token bucket inquired by the storage server cluster, deducting the token required by the token application request from the token bucket, and returning an updating result to the frequency control logic cluster.
The storage server cluster may query whether a token exists in a pre-stored token bucket, and when the storage server cluster queries that the token exists in the token bucket, the storage server cluster may deduct a token required by the token application request from the token bucket and return an update result to the frequency control logic cluster, where the update result may carry the token required by the token update request, that is, return the token to the frequency control logic cluster based on the token update request. After receiving the token returned by the storage server cluster, the frequency control logic cluster may send the token to the frequency control proxy server.
When the storage server cluster queries that no token exists in the pre-stored token bucket, token application failure information can be returned to the frequency control logic cluster, the frequency control logic cluster sends the token application failure information to the access server through the frequency control proxy server, and the access server refuses to provide access service for the service corresponding to the service access request based on the received token application failure information.
For example, for the access frequency control of the client a, assuming that the control policy is to allow the client a to access 1000 times in 1 second, when the client a has 1001 accesses in 1 second, that is, 1001 accesses in unix timestamp 1510112115, in the storage server cluster, the storage structure of the client a may be key: 1510112115_1, value: 1001; when receiving a 1001 st service access request sent by the client a, the access frequency is returned to exceed the limit, and meanwhile, the access of the client a is denied, so that the purpose of accurate frequency control is achieved.
208. And after receiving the updating result, the frequency control logic cluster returns the token required by the token application request to the frequency control proxy server.
After receiving the update result, the frequency control logic cluster may extract the token from the update result, and return the token required by the token application request to the frequency control proxy server. The method has the advantages that the load of the frequency control server cluster can be effectively shared by the local token bucket preset by the frequency control proxy server, the access frequency of the client to the frequency control server cluster is reduced, the pressure of the frequency control server cluster can be greatly reduced, larger access impact can be supported, meanwhile, when the frequency control server cluster has problems, the service server cluster can control the access frequency of the client through the local token bucket, and the fault tolerance of the service server cluster is reduced to the greatest extent.
209. And the frequency control proxy server stores the received token into a local token bucket and deducts the token required by the service access request from the local token bucket.
After receiving the token required by the token application request returned by the frequency control logic cluster, the frequency control proxy server can store the obtained token in a local token bucket; and then, deducting tokens required by the service access request from the local token bucket, and counting the access frequency of the client according to the tokens consumed in the local token bucket.
The tokens in the local token bucket may be provided with a validity period, and the validity period of one token may be used one or more times, or used within a preset time period, etc. When the frequency control proxy server obtains the token required by the service access request from the local token bucket, if the current moment is in the current token period, the token in the local token bucket is not reduced; if the current time has entered the next token cycle, the tokens required for the service access request may be deducted from the local token bucket.
210. And the frequency control proxy server generates a frequency control result and returns the frequency control result to the access server.
The frequency control proxy server can generate a frequency control result according to the subtracted token, the frequency control result can carry information and the token allowing the client to access, and the like, and the frequency control result is returned to the access server.
211. And after receiving the frequency control result, the access server provides access service for the service corresponding to the service access request so as to process the service corresponding to the service access request.
After receiving the frequency control result, the access server can extract a token required by the service access request from the frequency control result when determining that the access service can be provided for the client according to the information carried in the frequency control result, and provide the access service for the service corresponding to the service access request through the token so as to process the service corresponding to the service access request.
212. And the access server returns a service processing result to the client.
After processing the service corresponding to the service access request, the access server may generate a service processing result and return the service processing result to the client.
The embodiment of the invention can effectively control the access frequency of different clients by using the token bucket when the business server cluster is accessed at high frequency, thereby protecting the security of the business server cluster and improving the accuracy of controlling the access frequency. In addition, the load of the frequency control server cluster can be effectively shared by using a local token bucket preset by the frequency control proxy server, so that a buffer is formed between the service server cluster and the frequency control server cluster, the access frequency of a client to the frequency control server cluster is reduced, and the pressure of the frequency control server cluster can be greatly reduced.
In order to better implement the access frequency control method provided by the embodiment of the present invention, an embodiment of the present invention further provides a device based on the access frequency control method. The terms are the same as those in the above access frequency control method, and details of implementation may refer to the description in the method embodiment.
Referring to fig. 7, fig. 7 is a schematic structural diagram of an access frequency control apparatus according to an embodiment of the present invention, where the access frequency control apparatus may include a first receiving unit 301, a determining unit 302, a sending unit 303, a control unit 304, and the like.
The first receiving unit 301 is configured to receive a service access request sent by a client, where the service access request carries a client identifier.
The client may be integrated on a terminal such as a mobile phone or a computer, and when a certain service needs to be executed on the terminal, a service access request may be sent to the access frequency control device through the client, and the first receiving unit 301 receives the service access request, where the service access request may carry information such as a service identifier and a client identifier. The client identifier may be a client name or a client number, and may be composed of numbers, letters, and/or words, and the specific content is not limited herein. The type of the service access request may be flexibly set according to actual needs, for example, the service access request may be a mail service access request or a microblog service access request, and specific contents are not limited herein.
A determining unit 302, configured to determine a token bucket identifier corresponding to the client identifier, and query a local token bucket corresponding to the token bucket identifier.
In order to effectively control the access frequency of each client, the access frequency control device may maintain a mapping relationship between the client and the local token bucket by using an identifier in advance, that is, establish a mapping relationship between the client identifier and the token bucket identifier, so that each client has a local token bucket corresponding to the client. The token bucket identifier may be a token bucket name or a token bucket number, and may be composed of numbers, letters, and/or words, and the specific content is not limited herein.
The local token bucket may store tokens therein, and is mainly used to control access frequency of the client, for example, whether the client is allowed to access may be indicated by whether the token exists in the local token bucket, that is, if the token exists in the local token bucket, the client may be provided with access service, and if the token does not exist in the local token bucket, the client is not provided with access service. Each token in the local token bucket may represent a number of times access services are provided for the client, e.g., one token may provide one or more access services for the client; alternatively, each token in the local token bucket may represent a time period for providing access services to the client, e.g., one token may provide access services to the client in 1 or 3 seconds; alternatively, each token in the local token bucket may represent the number of times that access service is provided to the client per second, i.e., each token in the local token bucket may represent the number of times that the client is allowed to access per second (i.e., the access frequency of the client), and so on. It is understood that the rights that the token can represent can be flexibly set according to actual needs, and specific contents are not limited herein.
The work process of the local token bucket can comprise the following steps: generating tokens, consuming tokens, determining whether to provide access services for clients, and the like. The token generation may be periodically adding tokens to the local token bucket at a preset rate, so that the number of tokens in the local token bucket is continuously increased, and if the number of tokens in the local token bucket exceeds a preset number threshold, the redundant tokens may be discarded. The consumption token may be a token that is consumed in a local token bucket when providing access services for the client in order to count the client access frequency, which may be the number of accesses per second, or the number of accesses per minute, etc. Judging whether to provide the access service for the client side or not can be that when the number of tokens in the local token bucket can meet the requirement of the service corresponding to the service access request on the tokens, the access service can be provided for the client side, otherwise, the access service is not provided for the client side.
After receiving a service access request carrying a client identifier sent by a client, the determining unit 302 may extract the client identifier from the service access request, and determine a token bucket identifier corresponding to the client identifier according to a mapping relationship between the client identifier and the token bucket identifier. And then obtaining a local token bucket corresponding to the token bucket identification, and inquiring the local token bucket, wherein the local token bucket can be a token bucket locally preset by the access frequency control device. That is, when the access frequency of the client is determined according to the tokens in the local token bucket, for example, when the tokens exist in the local token bucket, it may be determined that the access frequency of the client is less than or equal to a preset threshold; when no token exists in the local token bucket, it may be determined that the access frequency of the client is greater than a preset threshold.
In some embodiments, as shown in fig. 10, the access frequency control apparatus may further include an obtaining unit 305 and a providing unit 306, and the details may be as follows:
an obtaining unit 305, configured to obtain a token required by the service access request from the local token bucket when the token exists in the local token bucket;
and the providing unit 306 is configured to provide an access service for the service corresponding to the service access request according to the obtained token.
In the process of querying the local token bucket, when it is queried that there is a token in the local token bucket, it indicates that the access frequency of the client is less than or equal to the preset threshold, and at this time, the obtaining unit 305 may obtain the token required by the service access request from the local token bucket. The preset threshold may be flexibly set according to actual needs, the number of tokens required for the service access request may be one or more, and when the number of tokens required for the service access request is multiple, and when it is found that the token required for the service access request exists in the local token bucket, the obtaining unit 305 obtains the token required for the service access request from the local token bucket. After obtaining the token, the providing unit 306 may provide an access service for the service corresponding to the service access request according to the obtained token.
It should be noted that, when each token in the token bucket represents the number of times of providing access service for the client in each period, and the obtaining unit 305 finds that there is a token in the local token bucket, it may determine whether the token in the local token bucket needs to be updated at the current time, for example, if the current time is still in the current token period, the token in the local token bucket is not updated; and if the current time is within the next new token period, deducting the tokens required by the service access request from the local token bucket, and updating the tokens in the local token bucket. When the token update is successful, the providing unit 306 may provide an access service for the client; when the token update fails, the preset number of times may be retried, if the token update succeeds, the providing unit 306 provides the access service for the client, and if the token update fails, the providing unit does not provide the access service for the client, and returns failure information to the client.
A sending unit 303, configured to send a token application request to the frequency control server cluster when it is determined that the access frequency of the client is greater than the preset threshold according to the token in the local token bucket.
In the process of querying the local token bucket, when it is determined that the access frequency of the client is greater than the preset threshold according to the token in the local token bucket, it is indicated that the access frequency of the client is greater, for example, when it is queried that no token exists in the local token bucket, it may be determined that the access frequency of the client is greater than the preset threshold; or, when the number of the tokens in the local token bucket is smaller than the preset number, it may be determined that the access frequency of the client is greater than a preset threshold; the preset number and the preset threshold value can be flexibly set according to actual needs, and specific contents are not limited here. When determining that the access frequency of the client is greater than the preset threshold according to the tokens in the local token bucket, in order to determine whether the access frequency of the client can be increased, the sending unit 303 may send a token application request to the frequency control server cluster.
The frequency control server clusters may include one or more frequency control server clusters, the multiple frequency control server clusters may include frequency control server clusters that provide different types of frequency control services for the multiple service server clusters, each frequency control server cluster may include multiple frequency control servers of the same frequency control type, and one frequency control server may provide a frequency control service for one service server.
In some embodiments, as shown in fig. 9, the sending unit 303 may include a determining subunit 3031, a sending subunit 3032, and the like, which may specifically be as follows:
a determining subunit 3031, configured to determine whether the client identifier is in a preset white list;
a sending subunit 3032, configured to send a token application request to the frequency control server cluster if the client identifier is in the preset white list.
Specifically, the access frequency control device may preset a black and white list, where the black list may store a client identifier corresponding to a client that limits access frequency, that is, for a client in the black list, only a token in a local token bucket may be used, and when no token exists in the local token bucket, a token application request may not be sent to the frequency control server cluster; the white list may store a client identifier corresponding to a client that may increase access frequency, that is, for a client in the white list, when no token exists in the local token bucket, a token application request may be sent to the frequency control server cluster.
It can be understood that the access frequency control device may also preset an unlimited access list and a prohibited access list, and the like, wherein clients in the unlimited access list may access without controlling their access frequency for unlimited times, and clients in the prohibited access list may not access.
When determining that the access frequency of the client is greater than the preset threshold according to the tokens in the local token bucket, the determining subunit 3031 may determine whether the client identifier is in a preset white list; if the client identifier is in the preset white list, the sending subunit 3032 sends a token application request to the frequency control server cluster. And if the client identification is not in the preset white list, not sending a token application request to the frequency control server cluster, and refusing to provide access service for the client corresponding to the client identification.
Optionally, the transmitting subunit 3032 may specifically be configured to: when the client identifier is in a preset white list, generating a token in a preset period; and when the produced token can not meet the token required by the service access request, sending a token application request to the frequency control server cluster.
Specifically, the tokens in the local token bucket may be pre-allocated by the frequency control server cluster, or may be pre-produced by the local token bucket, and the number of tokens in the local token bucket corresponding to different clients may be flexibly set according to actual needs. When the client identifier is in the preset white list, it is indicated that the client corresponding to the client identifier can increase the access frequency, and can produce a preset number of tokens every preset period, at this time, the tokens are produced in the preset period. When the produced token cannot satisfy the token required by the service access request, the sending subunit 3032 may send a token application request to the frequency control server cluster.
In some embodiments, as shown in fig. 11, the access frequency control apparatus may further include a second receiving unit 307, a rejecting unit 308, and the like, which may specifically be as follows:
a second receiving unit 307, configured to receive token application failure information returned by the frequency control server cluster based on the token application request when the frequency control server cluster queries that no token exists in the pre-stored token bucket;
a rejecting unit 308, configured to reject to provide an access service for a service corresponding to the service access request based on the token application failure information.
Specifically, after sending a token application request to the frequency control server cluster, the frequency control server cluster may query whether a token exists in a pre-stored token bucket, where the token bucket is preset for the frequency control server cluster, the token bucket may store a token, and the representative meaning of the token in the token bucket and the working process of the token bucket are similar to those of a local token bucket, and are not described herein again. When the frequency control server cluster queries that no token exists in the token bucket, it indicates that the access frequency of each client is higher, and at this time, the frequency control server cluster returns token application failure information to the access frequency control device based on the token application request, and the second receiving unit 307 receives the token application failure information. After receiving the token application failure information, the rejecting unit 308 may reject to provide the access service for the service corresponding to the service access request. Therefore, the problem that the access frequency of the client is flexibly limited when the flow of the client suddenly increases (namely the access frequency suddenly increases) can be effectively solved, and the safety and the stability of the access frequency control device are protected.
It should be noted that, after receiving the token application request, the frequency control server cluster may extract a service server identifier that the service access request needs to access from the token application request, determine, according to a preset mapping relationship between the service server identifier and the frequency control server identifier, a frequency control server identifier corresponding to the service server identifier, and acquire, from the frequency control server cluster, a frequency control server corresponding to the frequency control server identifier. The frequency control server can inquire the tokens in a pre-stored token bucket, when the frequency control server inquires that no token exists in the token bucket, the frequency control server returns token application failure information to the access frequency control device, and when the frequency control server inquires that no token exists in the token bucket, the frequency control server returns the token required by the token application request to the access frequency control device.
And the control unit 304 is configured to receive a token returned by the frequency control server cluster based on the token application request, and provide an access service for a service corresponding to the service access request according to the obtained token.
After sending the token application request to the frequency control server cluster, the frequency control server cluster may query whether a token exists in a pre-stored token bucket, and when the frequency control server cluster queries that a token exists in the token bucket, the frequency control server cluster returns the token to the control unit 304 based on the token application request. The control unit 304 receives the token returned by the frequency control server cluster, and provides an access service for the service corresponding to the service access request according to the obtained token. The load of the frequency control server cluster can be effectively shared by the local token bucket preset by the access frequency control device, so that a buffer is arranged between the access frequency control device and the frequency control server cluster, the access frequency of a client to the frequency control server cluster is reduced, the pressure of the frequency control server cluster can be greatly reduced, larger access impact can be supported, and meanwhile, when the frequency control server cluster has a problem, the access frequency control device can control the access frequency of the client through the local token bucket, so that the fault tolerance of the access frequency control device is reduced to the greatest extent.
In some embodiments, as shown in fig. 8, the control unit 304 may include a storage subunit 3041, an obtaining subunit 3042, a providing subunit 3043, and the like, which may be specifically as follows:
a storage subunit 3041, configured to store the obtained token in a local token bucket;
an obtaining subunit 3042, configured to obtain a token required by the service access request from the local token bucket;
the providing subunit 3043 is configured to provide an access service for the service corresponding to the service access request according to the token required by the obtained service access request.
Specifically, after receiving a token returned by the frequency control server cluster based on the token application request, in order to facilitate statistics on the access frequency of the client, the storage subunit 3041 may store the obtained token in the local token bucket; then, the obtaining subunit 3042 obtains the token required by the service access request from the local token bucket, and counts the access frequency of the client according to the token consumed in the local token bucket, and the providing subunit 3043 may provide access service for the service corresponding to the service access request according to the obtained token required by the service access request, that is, process the service corresponding to the service access request.
Optionally, the obtaining subunit 3042 may specifically be configured to: judging whether the current moment is in the current token period; and if the current moment is not in the current token cycle, obtaining tokens required by the service access request from the local token bucket, and updating the number of the tokens in the local token bucket.
A validity period may be set for the tokens in the local token bucket, and the validity period of one token may be used one or more times, or used within a preset time period, etc. When the obtaining subunit 3042 obtains the token required by the service access request from the local token bucket, it may determine whether the current time needs to update the number of tokens in the local token bucket, that is, determine whether the current time is in the current token cycle, and if the current time is in the current token cycle, the number of tokens in the local token bucket does not need to be updated; and if the current time is within the next token period, deducting the tokens required by the service access request from the local token bucket, and updating the number of the tokens in the local token bucket. When the token quantity is updated successfully, the access service can be provided for the client; and when the token quantity updating fails, retrying for a preset number of times, if the token quantity updating succeeds, providing access service for the client, if the token quantity updating fails, not providing access service for the client, and returning failure information to the client.
As can be seen from the above, in the embodiment of the present invention, when the first receiving unit 301 receives a service access request carrying a client identifier sent by a client, the determining unit 302 may determine a token bucket identifier corresponding to the client identifier, and query a local token bucket corresponding to the token bucket identifier; when determining that the access frequency of the client is greater than a preset threshold according to the token in the local token bucket, the sending unit 303 sends a token application request to the frequency control server cluster; then, the control unit 304 receives a token returned by the frequency control server cluster based on the token application request, and provides an access service for a service corresponding to the service access request according to the obtained token. According to the scheme, the tokens in the local token bucket corresponding to each client can be maintained according to the client identification, the pre-stored tokens in the token bucket are maintained through the frequency control server cluster, the access frequency of the clients is effectively controlled through the tokens in the token bucket, and the accuracy of controlling the access frequency is improved.
An embodiment of the present invention further provides a server, where the server may be any service server in a service server cluster, as shown in fig. 12, which shows a schematic structural diagram of the server according to the embodiment of the present invention, specifically:
the server may include components such as a processor 401 of one or more processing cores, memory 402 of one or more computer-readable storage media, a power supply 403, and an input unit 404. Those skilled in the art will appreciate that the server architecture shown in FIG. 12 is not meant to be limiting, and may include more or fewer components than those shown, or some components may be combined, or a different arrangement of components. Wherein:
the processor 401 is a control center of the server, connects various parts of the entire server using various interfaces and lines, and performs various functions of the server and processes data by running or executing software programs and/or modules stored in the memory 402 and calling data stored in the memory 402, thereby performing overall monitoring of the server. Optionally, processor 401 may include one or more processing cores; preferably, the processor 401 may integrate an application processor, which mainly handles operating systems, user interfaces, application programs, etc., and a modem processor, which mainly handles wireless communications. It will be appreciated that the modem processor described above may not be integrated into the processor 401.
The memory 402 may be used to store software programs and modules, and the processor 401 executes various functional applications and data processing by operating the software programs and modules stored in the memory 402. The memory 402 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application program required by at least one function (such as a sound playing function, an image playing function, etc.), and the like; the storage data area may store data created according to the use of the server, and the like. Further, the memory 402 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other volatile solid state storage device. Accordingly, the memory 402 may also include a memory controller to provide the processor 401 access to the memory 402.
The server further includes a power supply 403 for supplying power to each component, and preferably, the power supply 403 may be logically connected to the processor 401 through a power management system, so as to implement functions of managing charging, discharging, and power consumption through the power management system. The power supply 403 may also include any component of one or more dc or ac power sources, recharging systems, power failure detection circuitry, power converters or inverters, power status indicators, and the like.
The server may also include an input unit 404, and the input unit 404 may be used to receive input numeric or character information and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control.
Although not shown, the server may further include a display unit and the like, which will not be described in detail herein. Specifically, in this embodiment, the processor 401 in the server loads the executable file corresponding to the process of one or more application programs into the memory 402 according to the following instructions, and the processor 401 runs the application program stored in the memory 402, thereby implementing various functions as follows:
receiving a service access request sent by a client, wherein the service access request carries a client identifier; determining a token bucket identifier corresponding to the client identifier, and inquiring a local token bucket corresponding to the token bucket identifier; when the access frequency of the client is determined to be greater than a preset threshold value according to the tokens in the local token bucket, sending a token application request to the frequency control server cluster; and receiving a token returned by the frequency control server cluster based on the token application request, and providing access service for the service corresponding to the service access request according to the obtained token.
As can be seen from the above, when receiving a service access request carrying a client identifier sent by a client, the embodiment of the present invention may determine a token bucket identifier corresponding to the client identifier, and query a local token bucket corresponding to the token bucket identifier; when the access frequency of the client is determined to be greater than a preset threshold value according to the tokens in the local token bucket, sending a token application request to the frequency control server cluster; and then receiving a token returned by the frequency control server cluster based on the token application request, and providing access service for the service corresponding to the service access request according to the obtained token. According to the scheme, the tokens in the local token bucket corresponding to each client can be maintained according to the client identification, the pre-stored tokens in the token bucket are maintained through the frequency control server cluster, the access frequency of the clients is effectively controlled through the tokens in the token bucket, and the accuracy of controlling the access frequency is improved.
In the above embodiments, the descriptions of the respective embodiments have respective emphasis, and parts that are not described in detail in a certain embodiment may refer to the above detailed description of the access frequency control method, and are not described herein again.
It will be understood by those skilled in the art that all or part of the steps of the methods of the above embodiments may be performed by instructions or by associated hardware controlled by the instructions, which may be stored in a computer readable storage medium and loaded and executed by a processor.
To this end, the present invention provides a storage medium, in which a plurality of instructions are stored, and the instructions can be loaded by a processor to execute the steps in any one of the access frequency control methods provided by the embodiments of the present invention. For example, the instructions may perform the steps of:
receiving a service access request sent by a client, wherein the service access request carries a client identifier; determining a token bucket identifier corresponding to the client identifier, and inquiring a local token bucket corresponding to the token bucket identifier; when the access frequency of the client is determined to be greater than a preset threshold value according to the tokens in the local token bucket, sending a token application request to the frequency control server cluster; and receiving a token returned by the frequency control server cluster based on the token application request, and providing access service for the service corresponding to the service access request according to the obtained token.
The above operations can be implemented in the foregoing embodiments, and are not described in detail herein.
Wherein the storage medium may include: read Only Memory (ROM), Random Access Memory (RAM), magnetic or optical disks, and the like.
Since the instructions stored in the storage medium may execute the steps in any access frequency control method provided in the embodiments of the present invention, beneficial effects that can be achieved by any access frequency control method provided in the embodiments of the present invention may be achieved, which are detailed in the foregoing embodiments and will not be described herein again.
The foregoing detailed description is directed to a method, an apparatus, and a storage medium for controlling access frequency according to embodiments of the present invention, and specific examples are applied herein to illustrate the principles and implementations of the present invention, and the above descriptions of the embodiments are only used to help understanding the method and the core idea of the present invention; meanwhile, for those skilled in the art, according to the idea of the present invention, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present invention.

Claims (13)

1. An access frequency control method, comprising:
receiving a service access request sent by a client, wherein the service access request carries a client identifier;
determining a token bucket identifier corresponding to the client identifier, and querying a local token bucket corresponding to the token bucket identifier;
when the access frequency of the client is determined to be greater than a preset threshold value according to the tokens in the local token bucket, judging whether the client identifier is in a preset white list;
if the client identification is in a preset white list, sending a token application request to a frequency control server cluster;
and receiving a token returned by the frequency control server cluster based on the token application request in a token bucket, and providing access service for the service corresponding to the service access request according to the obtained token.
2. The method according to claim 1, wherein the step of providing access service for the service corresponding to the service access request according to the obtained token comprises:
storing the obtained token to the local token bucket;
obtaining tokens required by the service access request from the local token bucket;
and providing access service for the service corresponding to the service access request according to the acquired token required by the service access request.
3. The method of claim 2, wherein the step of obtaining the token required for the service access request from the local token bucket comprises:
judging whether the current moment is in the current token period;
and if the current moment is not in the current token period, obtaining tokens required by the service access request from the local token bucket, and updating the number of the tokens in the local token bucket.
4. The method according to claim 1, wherein the step of sending a token application request to a frequency control server cluster if the client identifier is in a preset white list comprises:
when the client identification is in a preset white list, generating a token in a preset period;
and when the produced token cannot meet the token required by the service access request, sending a token application request to the frequency control server cluster.
5. The method of any of claims 1 to 4, wherein after the steps of determining a token bucket identifier corresponding to the client identifier and querying a local token bucket corresponding to the token bucket identifier, the method further comprises:
when the token exists in the local token bucket, obtaining the token required by the service access request from the local token bucket;
and providing access service for the service corresponding to the service access request according to the obtained token.
6. The access frequency control method according to any one of claims 1 to 4, wherein after the step of sending a token application request to the frequency control server cluster when it is determined that the access frequency of the client is greater than the preset threshold value according to the tokens in the local token bucket, the method further comprises:
when the frequency control server cluster does not have tokens in a pre-stored token bucket in inquiry, receiving token application failure information returned by the frequency control server cluster based on the token application request;
and refusing to provide access service for the service corresponding to the service access request based on the token application failure information.
7. An access frequency control apparatus, comprising:
the first receiving unit is used for receiving a service access request sent by a client, wherein the service access request carries a client identifier;
the determining unit is used for determining a token bucket identifier corresponding to the client identifier and inquiring a local token bucket corresponding to the token bucket identifier;
the sending unit is used for sending a token application request to the frequency control server cluster when the access frequency of the client is determined to be greater than a preset threshold value according to the tokens in the local token bucket;
the control unit is used for receiving the tokens returned by the frequency control server cluster based on the token application request and providing access service for the service corresponding to the service access request according to the obtained tokens;
wherein the transmitting unit includes:
the judging subunit is used for judging whether the client identifier is in a preset white list or not;
and the sending subunit is configured to send a token application request to the frequency control server cluster if the client identifier is in a preset white list.
8. The access frequency control device according to claim 7, wherein the control unit includes:
a storage subunit, configured to store the obtained token in the local token bucket;
an updating subunit, configured to obtain a token required by the service access request from the local token bucket;
and the providing subunit is used for providing access service for the service corresponding to the service access request according to the acquired token required by the service access request.
9. The access frequency control device according to claim 8, wherein the updating subunit is specifically configured to:
judging whether the current moment is in the current token period;
and if the current moment is not in the current token period, obtaining tokens required by the service access request from the local token bucket, and updating the number of the tokens in the local token bucket.
10. The access frequency control device according to claim 7, wherein the transmitting subunit is specifically configured to:
when the client identification is in a preset white list, generating a token in a preset period;
and when the produced token cannot meet the token required by the service access request, sending a token application request to the frequency control server cluster.
11. The access frequency control device according to any one of claims 7 to 10, characterized by further comprising:
an obtaining unit, configured to obtain a token required by the service access request from the local token bucket when the token exists in the local token bucket;
and the providing unit is used for providing access service for the service corresponding to the service access request according to the obtained token.
12. The access frequency control device according to any one of claims 7 to 10, characterized by further comprising:
the second receiving unit is used for receiving token application failure information returned by the frequency control server cluster based on the token application request when the frequency control server cluster queries that no token exists in a pre-stored token bucket;
and the rejecting unit is used for rejecting to provide access service for the service corresponding to the service access request based on the token application failure information.
13. A storage medium storing a plurality of instructions adapted to be loaded by a processor to perform the steps of the access frequency control method according to any one of claims 1 to 6.
CN201810191962.8A 2018-03-08 2018-03-08 Access frequency control method, device and storage medium Active CN108494703B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810191962.8A CN108494703B (en) 2018-03-08 2018-03-08 Access frequency control method, device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810191962.8A CN108494703B (en) 2018-03-08 2018-03-08 Access frequency control method, device and storage medium

Publications (2)

Publication Number Publication Date
CN108494703A CN108494703A (en) 2018-09-04
CN108494703B true CN108494703B (en) 2022-05-06

Family

ID=63338068

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810191962.8A Active CN108494703B (en) 2018-03-08 2018-03-08 Access frequency control method, device and storage medium

Country Status (1)

Country Link
CN (1) CN108494703B (en)

Families Citing this family (27)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109298939B (en) * 2018-09-26 2021-04-20 腾讯科技(深圳)有限公司 Access frequency control method, device and system of distributed system and server
CN111078391A (en) * 2018-10-22 2020-04-28 阿里巴巴集团控股有限公司 Service request processing method, device and equipment
CN111291367A (en) * 2018-12-06 2020-06-16 北京京东尚科信息技术有限公司 Access control method and system, electronic device and storage medium
CN109787915B (en) * 2018-12-14 2022-09-20 北京三快在线科技有限公司 Flow control method and device for network access, electronic equipment and storage medium
CN109587072A (en) * 2019-01-04 2019-04-05 中企动力科技股份有限公司 Distributed system overall situation speed limiting system and method
CN109981779B (en) * 2019-03-27 2022-02-22 掌阅科技股份有限公司 Service providing method, server and computer storage medium
CN110213173B (en) * 2019-06-06 2023-03-24 北京百度网讯科技有限公司 Flow control method and device, system, server and computer readable medium
CN110276182B (en) * 2019-06-10 2020-12-22 必成汇(成都)科技有限公司 API distributed current limiting realization method
CN111770126B (en) * 2019-06-28 2023-08-04 北京京东尚科信息技术有限公司 Service request processing method, device and storage medium
CN110417888A (en) * 2019-07-30 2019-11-05 中国工商银行股份有限公司 Flow control methods, volume control device and electronic equipment
CN110618878B (en) * 2019-08-12 2022-02-01 网联清算有限公司 Final state notification speed control method and device
CN110535785B (en) * 2019-08-29 2022-11-18 郑州阿帕斯科技有限公司 Control method and device for sending frequency and distributed system
CN110943934A (en) * 2019-11-19 2020-03-31 上海钧正网络科技有限公司 Service request processing method, system, terminal and readable storage medium
CN110971470B (en) * 2019-12-27 2023-06-27 思必驰科技股份有限公司 Weight-supported private cloud service cluster current limiting method and system
CN111343102B (en) * 2020-02-03 2023-09-26 中国银联股份有限公司 Flow rate control method, server, client server and system
CN111314238B (en) * 2020-02-03 2023-12-05 网银在线(北京)科技有限公司 Token management method and device, storage medium and electronic device
CN111352967B (en) * 2020-02-27 2024-02-06 携程旅游网络技术(上海)有限公司 Frequency control method, system, equipment and medium of sliding window algorithm
CN111404836B (en) * 2020-03-30 2023-09-12 北京小米移动软件有限公司 Data transmission control method, device, control center, server and medium
CN111641563B (en) * 2020-05-28 2022-11-01 深圳壹账通智能科技有限公司 Flow self-adaption method and system based on distributed scene
CN111782692B (en) * 2020-06-01 2024-04-16 京东科技控股股份有限公司 Frequency control method and device
CN112104567B (en) * 2020-09-03 2022-11-18 中国银联股份有限公司 Flow control method, device, equipment and medium
CN113051079B (en) * 2021-03-31 2022-03-01 淄博职业学院 Computer overload protection device
CN113783923A (en) * 2021-03-31 2021-12-10 北京沃东天骏信息技术有限公司 Web page anti-brush processing method, device, equipment and storage medium
CN114553791A (en) * 2022-01-19 2022-05-27 浙江百应科技有限公司 External interface current limiting method and device, electronic equipment and storage medium
CN114826774B (en) * 2022-06-02 2024-01-30 天翼数字生活科技有限公司 Log request control method, server side and system for terminal equipment
CN115442432B (en) * 2022-09-06 2024-06-07 上海浦东发展银行股份有限公司 Control method, device, equipment and storage medium
CN115277577B (en) * 2022-09-28 2023-04-28 平安银行股份有限公司 Data processing method, apparatus, computer device, and computer readable storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101834786A (en) * 2010-04-15 2010-09-15 华为技术有限公司 Queue scheduling method and device
CN104219169A (en) * 2014-09-30 2014-12-17 杭州华三通信技术有限公司 CBQ (Class Based Queuing) scheduling method and device
CN104580113A (en) * 2013-10-25 2015-04-29 腾讯科技(深圳)有限公司 Method and device for processing external request
CN107332861A (en) * 2017-08-11 2017-11-07 杭州亿方云网络科技有限公司 A kind of open platform architecture system based on OAuth agreements

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9218221B2 (en) * 2013-06-25 2015-12-22 Amazon Technologies, Inc. Token sharing mechanisms for burst-mode operations
CN107579926B (en) * 2017-10-20 2021-02-09 南京易捷思达软件科技有限公司 QoS setting method of Ceph cloud storage system based on token bucket algorithm

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101834786A (en) * 2010-04-15 2010-09-15 华为技术有限公司 Queue scheduling method and device
CN104580113A (en) * 2013-10-25 2015-04-29 腾讯科技(深圳)有限公司 Method and device for processing external request
CN104219169A (en) * 2014-09-30 2014-12-17 杭州华三通信技术有限公司 CBQ (Class Based Queuing) scheduling method and device
CN107332861A (en) * 2017-08-11 2017-11-07 杭州亿方云网络科技有限公司 A kind of open platform architecture system based on OAuth agreements

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
"redis之频率限制";一溪酒;《https://www.jianshu.com/p/c1b8cc61203e》;20171205;第1、2页 *

Also Published As

Publication number Publication date
CN108494703A (en) 2018-09-04

Similar Documents

Publication Publication Date Title
CN108494703B (en) Access frequency control method, device and storage medium
US8719297B2 (en) System for managing data collection processes
JP4760491B2 (en) Event processing system, event processing method, event processing apparatus, and event processing program
CN109064345A (en) Message treatment method, system and computer readable storage medium
CN111338773B (en) Distributed timing task scheduling method, scheduling system and server cluster
CN107547595B (en) Cloud resource scheduling system, method and device
WO2019237594A1 (en) Session persistence method and apparatus, and computer device and storage medium
JPWO2018220709A1 (en) Resource management system, management device, method and program
US20070265976A1 (en) License distribution in a packet data network
CN110471749A (en) Task processing method, device, computer readable storage medium and computer equipment
CN107196949A (en) The system for limiting same user account registration terminal quantity
CN115277577A (en) Data processing method, data processing device, computer equipment and computer readable storage medium
CN113238861A (en) Task execution method and device
CN113285884B (en) Flow control method and system
CN108520401B (en) User list management method, device, platform and storage medium
CN116150459A (en) Searching method, searching device, electronic equipment and storage medium
JP2005128866A (en) Computer unit and method for controlling computer unit
CN113905091A (en) Method and device for processing access request
CN111339114A (en) Data access method, device, equipment and storage medium
JP2004348192A (en) Job distribution control method
CN110677494B (en) Access response method and device
CN113904940A (en) Resource adjusting method and device, electronic equipment and computer readable storage medium
CN113765871A (en) Fortress management method and device
CN104580113B (en) A kind of method and device of processing external request
CN113886078B (en) Method and device for realizing quota unified management based on dynamic threshold mechanism, electronic equipment and computer readable storage medium

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
GR01 Patent grant
GR01 Patent grant