Access control method, device, storage medium and processor
By setting up the token bucket and fuse module in the server, the access request is controlled, and the current limit problem is solved when the platform interface access exceeds the limit, the service availability and stability are achieved, and the function unavailability problem caused by the current limit is avoided. .
Patent Information
- Application Number
- CN202210114708.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-30
- Publication Date
- 2024-11-29
- Estimated Expiration
- 2042-01-30
AI Technical Summary
When access to the platform interface exceeds the limit, the problem of triggering the interface's current limit measures, resulting in the inability to use the platform functions has not been effectively solved.
By setting up the token bucket and the fuse module in the server, we can determine whether there are tokens in the token bucket and judge the status of the fuse module, control the execution and retry of access requests, avoid exceeding the interface limit, and realize the fuse and transparent retry mechanism to ensure that Business availability and stability.
It effectively avoids access requests exceeding the interface limit, prevents long-term interruption of services, ensures the availability and stability of services, and solves the problem of unavailability of functions caused by current limiting measures.
Smart Images

Figure CN114615203B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of application program interface calling, and in particular to an access control method, device, storage medium and processor. Background Art
[0002] Currently, more and more platforms provide their internal functions through OpenAPI (also known as the application programming interface of the open platform) to facilitate the use of enterprises and ISVs (Independent Software Vendors), so that enterprises and ISVs can use some functions in third-party platforms. For example, cloud security access service SASE, as the most secure and convenient remote access service, also faces the need to support enterprise users to log in through third-party platform authentication.
[0003] However, due to the large number of enterprises and ISVs using third-party platforms, errors may occur in the programs of enterprises and ISVs, thus causing abnormal platform load. Therefore, third-party platforms will set some restrictions on interfaces to prevent errors in application programs from causing abnormal platform load. Specifically, when the interface limit is exceeded, calling the corresponding interface will receive the corresponding error code and can only be called again after waiting for a certain period of time. When faced with a sudden increase in business pressure, the open platform's flow control measures will be triggered, causing the application to be unavailable for a period of time.
[0004] Currently, no effective solution has been proposed to the above-mentioned problem that when the access to the platform interface exceeds the restriction conditions, the interface's current limiting measures are triggered, resulting in the inability to use the platform functions. Summary of the invention
[0005] The embodiments of the present invention provide an access control method, device, storage medium and processor to at least solve the technical problem that when the access to the platform interface exceeds the restriction condition, the interface current limiting measures are triggered, resulting in the inability to use the platform function.
[0006] According to one aspect of an embodiment of the present invention, there is provided an access control method, comprising: a server receiving an access request; determining whether a token is currently stored in a token bucket in the server; if a token is stored in the token bucket, allocating the token to the access request, and determining whether a fuse module in the server is currently in a blown state; if the fuse module is in a blown state, stopping execution of an access behavior corresponding to the access request; if the fuse module is not in a blown state, executing the access behavior corresponding to the access request, and receiving response information for the access request, wherein the blown state is used to indicate that the access request is in a limited current state; if the response information indicates that the access is successful, returning an access result, and if the response information indicates that the access fails, stopping execution of the access behavior corresponding to the access request.
[0007] According to one aspect of an embodiment of the present invention, there is provided an access control device, comprising: a first receiving unit, for receiving an access request on a server; a first judging unit, for judging whether a token is currently stored in a token bucket in the server; a first allocating unit, for allocating the token to the access request if the token is stored in the token bucket, and for judging whether a fuse module in the server is currently in a blown state; a first stopping unit, for stopping the execution of an access behavior corresponding to the access request if the fuse module is in a blown state; a first executing unit, for executing the access behavior corresponding to the access request if the fuse module is not in a blown state, and receiving response information for the access request, wherein the blown state is used to indicate that the access request is in a limited current state; a first returning unit, for returning an access result if the response information indicates that the access is successful, and for stopping the execution of the access behavior corresponding to the access request if the response information indicates that the access fails.
[0008] According to another aspect of an embodiment of the present invention, a storage medium is further provided. The storage medium includes a stored program, wherein when the program is running, the device where the storage medium is located is controlled to execute any one of the above access control methods.
[0009] According to another aspect of an embodiment of the present invention, a processor is further provided, wherein the processor is used to run a program, wherein the program executes any one of the access control methods described above when running.
[0010] In an embodiment of the present invention, a server is used to receive an access request; determine whether a token is currently stored in a token bucket in the server; if a token is stored in the token bucket, the token is allocated to the access request, and it is determined whether the fuse module in the server is currently in a fuse state; if the fuse module is in a fuse state, the access behavior corresponding to the access request is stopped; if the fuse module is not in a fuse state, the access behavior corresponding to the access request is executed, and a response message for the access request is received, wherein the fuse state is used to indicate that the access request is in a current-limited state; if the response message indicates that the access is successful, the access result is returned, and if the response message indicates that the access fails, the access behavior corresponding to the access request is stopped. By setting the token bucket current limit and adding the fuse and transparent retry mechanism, the number of accesses per unit time of the caller is controlled, and the purpose of avoiding the access request exceeding the interface limit is achieved, thereby achieving the technical effect of avoiding long-term interruption of the business and ensuring the availability and stability of the business, and then solving the technical problem that the current limiting measures of the interface are triggered when the access to the platform interface exceeds the restriction conditions, resulting in the inability to use the platform function. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0012] Figure 1 is a hardware structure block diagram of a computer terminal according to an embodiment of the present invention;
[0013] Figure 2 is a flowchart of an access control method provided according to Embodiment 1 of the present invention;
[0014] Figure 3 A schematic diagram of a cache module provided according to Embodiment 1 of the present invention;
[0015] Figure 4 A flowchart of a cache module operation provided according to the first embodiment of the present invention;
[0016] Figure 5a A schematic diagram of a token bucket provided according to Embodiment 1 of the present invention;
[0017] Figure 5b A schematic diagram of another token bucket provided according to Embodiment 1 of the present invention;
[0018] Figure 6 A flowchart of a token bucket operation provided according to Embodiment 1 of the present invention;
[0019] Figure 7A flowchart of the operation of a fuse module provided according to the first embodiment of the present invention;
[0020] Figure 8 A flowchart of an access control method provided according to Embodiment 2 of the present invention;
[0021] Fig. 9 is a schematic diagram of an access control device provided according to Embodiment 3 of the present invention;
[0022] Fig.10 is a structural block diagram of an optional computer terminal according to an embodiment of the present invention. DETAILED DESCRIPTION
[0023] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0024] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0025] In order to solve the technical problem in the related art that when the access to the platform interface exceeds the restriction condition, the interface current limiting measures are triggered, resulting in the inability to use the platform function, the following methods have appeared in the related art:
[0026] Method 1: Call OpenAPI. When the open platform returns an error related to current limiting, terminate the service access and return an error prompt to the user to guide the user to try again later. However, method 1 has the following disadvantages: 1. Terminating service access and returning an error prompt to the user will directly lead to the failure of the service access; 2. It is very easy to trigger the current limiting of the open platform, resulting in the overall unavailability of the service for a period of time; 3. Users who get the error return will try again, resulting in more API calls being restricted by the open platform, and the current limiting situation will be further aggravated.
[0027] Method 2: The current limiting of the open platform IP dimension can be alleviated by adding service export public IPs. When the service calls OpenAPI, it uses different export IPs to access the open platform in turn, and it can be expanded horizontally. However, method 2 has the following disadvantages: 1. It can only alleviate the current limiting of the open platform unified access layer on the IP dimension, and cannot solve the current limiting of the enterprise dimension and API dimension. 2. Multiple public IPs will increase the cost of the service provider.
[0028] In order to solve the above problems, the embodiments of the present application provide an access control method, device, storage medium and processor. The embodiments of the present application are introduced below:
[0029] First, some nouns or terms that appear in the description of the embodiments of the present application are subject to the following explanations:
[0030] OpenAPI: Open Application Programming Interface, also known as Open Platform Application Programming Interface.
[0031] API: Application Programming Interface, application program interface.
[0032] Current limiting: When the number of concurrent requests or the rate reaches a certain level, the requests will be waited, queued, downgraded, or refused service.
[0033] Fuse: In a software system, when a service is overloaded for some reason, a protective measure is adopted to prevent the entire system from failing.
[0034] Token bucket: used to control the amount of data sent to the network.
[0035] SASE: Secure Access Service Edge.
[0036] IdP: Identity Provider.
[0037] Embodiment 1
[0038] According to an embodiment of the present invention, an access control method embodiment is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0039] The method embodiment provided in the first embodiment of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Figure 1FIG. 1 shows a hardware structure block diagram of a computer terminal (or mobile device) for implementing an access control method. Figure 1 As shown, the computer terminal 10 (or mobile device 10) may include one or more (102a, 102b, ..., 102n are used to illustrate) processors 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 104 for storing data, and a transmission device for communication functions. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the I / O interface), a network interface, a power supply and / or a camera. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown.
[0040] It should be noted that the one or more processors 102 and / or other data processing circuits described above may generally be referred to herein as "data processing circuits". The data processing circuits may be embodied in whole or in part as software, hardware, firmware, or any other combination thereof. In addition, the data processing circuit may be a single independent processing module, or may be incorporated in whole or in part into any of the other components in the computer terminal 10 (or mobile device). As described in the embodiments of the present application, the data processing circuit acts as a processor control (e.g., selection of a variable resistor terminal path connected to an interface).
[0041] The memory 104 can be used to store software programs and modules of application software, such as program instructions / data storage devices corresponding to the access control method in the embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, that is, the access control method of the interface of the application corresponding to the above-mentioned application is implemented. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the computer terminal 10 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0042] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the computer terminal 10. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0043] The display may be, for example, a touch screen liquid crystal display (LCD) that enables a user to interact with a user interface of the computer terminal 10 (or mobile device).
[0044] Under the above operating environment, this application provides Figure 2 The access control method shown. Figure 2 4 is a flow chart of an access control method according to Embodiment 1 of the present invention.
[0045] Step S202: The server receives an access request.
[0046] Specifically, the server can be a cloud security access service SASE, and the application program interface can be an API on a third-party platform. SASE can support users to call the interface on the third-party platform to complete authentication and login, thereby providing remote access services. When a user sends an interface access request to a third-party platform, the access request will be intercepted by the server, and the access will be restricted according to the settings of the third-party platform, thereby ensuring that the interface is successfully called without triggering the restriction threshold of the third-party platform.
[0047] Step S204, determining whether there are currently tokens stored in the token bucket in the server.
[0048] Specifically, the tokens in the token bucket can be used to restrict access requests in the IP dimension. For example, the access request corresponding to IP1 can call the API on the platform a maximum of 1,000 times within 10 minutes, so the token bucket can produce and issue a maximum of 1,000 tokens within 10 minutes. Therefore, after the access request is intercepted by the server, it is necessary to first determine whether there are tokens in the token bucket. If there are tokens, subsequent operations can be performed.
[0049] Step S206: When a token is stored in the token bucket, the token is allocated to the access request, and it is determined whether the fuse module in the server is currently in a blown state.
[0050] Specifically, when there is a token stored in the token bucket, the access request obtains the token and executes the next step. Since the current limiting thresholds and retry time intervals of different enterprises, ISVs (Independent Software Vendors) and APIs are different, the current limiting thresholds of each API corresponding to each enterprise and ISV are different. When the access request sent by an enterprise or ISV exceeds the corresponding current limiting threshold, the server will fuse the API. Therefore, after the access request obtains the token, the server needs to determine whether the API corresponding to the access is in a blown state, and perform corresponding operations based on the blown state.
[0051] It should be noted that in order to cope with sudden access requests, the token generation rate can be adjusted according to the number of tokens in the bucket, but the token bucket cannot exceed the call threshold corresponding to each API within a unit time, resulting in the token bucket producing no more than the preset number of tokens within a fixed time.
[0052] Step S208: When the fuse module is in the blown state, stop executing the access behavior corresponding to the access request.
[0053] Specifically, when the token is successfully obtained and it is determined that the fuse module is in a blown state, the access request is suspended and adjustments are made according to the blown situation. For example, if the fuse module indicates that access can be made after waiting for 2 minutes, tasks that can wait for more than 2 minutes can be carried out, and tasks that cannot wait for more than 2 minutes can return an access error message.
[0054] It should be noted that the fuse module makes restrictions based on the response information of the open platform API. When the open platform API returns a current limiting error code, the fuse module determines that the open platform API can no longer receive access requests at this time, and calculates the cooling time based on the error code returned by the open platform API and changes its own state to the fuse state. No more requests to access the open platform are allowed during the cooling time.
[0055] In order to determine whether to return the access request, optionally, in the access control method provided in the embodiment of the present application, when the fuse module is in the blown state, after stopping executing the access behavior corresponding to the access request, the method also includes: when the fuse module is in the blown state, obtaining the current access waiting time, and determining whether the timeout time of the access request is less than the current access waiting time; when the timeout time of the access request is less than the current access waiting time, returning access error information; when the timeout time of the access request is greater than or equal to the current access waiting time, determining whether the number of access retries is greater than or equal to the preset number of access retries; when the number of access retries is greater than or equal to the preset number of access retries, returning access error information; when the number of access retries is less than the preset number of access retries, executing the access behavior corresponding to the access request after the current access waiting time.
[0056] Specifically, when the fuse module is in a blown state, the waiting time corresponding to the blown state is obtained, and the timeout time of the access request is obtained, and the timeout time is compared with the waiting time. When the timeout time is less than the waiting time, it indicates that the access request can wait, and the access request starts to wait, and re-accesses the open platform API after the waiting time. When the timeout time is greater than or equal to the waiting time, the access error information corresponding to the access request is returned.
[0057] It should be noted that before re-accessing the open platform API after the waiting time is over, it is necessary to compare the access retry count with the preset access retry count. When the access retry count is greater than or equal to the preset access retry count, the access error information corresponding to the access request is returned. When the access retry count is less than the preset access retry count, the open platform API is accessed to obtain the access result.
[0058] It should also be noted that when accessing the open platform API again, if the fuse module is still in the fuse state and the waiting time has changed, the access request still cannot be successfully accessed. At this time, it is necessary to re-compare the timeout time and the waiting time, and increase the number of access retries by 1.
[0059] For example, the timeout period of an access request can be 5 minutes, the number of retries is 0, the waiting time can be 2 minutes, and the preset number of access retries is 1. In this case, the access request starts waiting and completes the waiting after 2 minutes. If the number of retries is also less than the preset number of access retries, the open platform API is accessed again. However, if the fuse module is still in the fuse state and the waiting time is changed to 4 minutes, an access error message is returned.
[0060] Step S210, when the fuse module is not in a blown state, executing an access behavior corresponding to the access request, and receiving response information for the access request, wherein the blown state is used to indicate that the access request is in a current-limited state;
[0061] Specifically, when the fuse module is not in a blown state, the access behavior corresponding to the access request can be successfully executed, and the response information returned by the open platform API can be received, wherein the response information is used to determine whether the open platform API can return the access result corresponding to the access request.
[0062] Step S212: When the response information indicates that the access is successful, the access result is returned; when the response information indicates that the access fails, the access behavior corresponding to the access request is stopped.
[0063] Specifically, when receiving the response information returned by the open platform API, when the fuse module changes from the blown state to the unblown state, it may be limited again due to too many access requests in a short period of time. At this time, the returned response information is the platform current limit, causing the access request to wait again until the current limit state ends.
[0064] Optionally, when the response information indicates that the access has failed, after stopping executing the access behavior corresponding to the access request, the method also includes: determining the access waiting time based on the response information, and judging whether the timeout time of the access request is less than the access waiting time; when the timeout time of the access request is less than the access waiting time, returning an access error message; when the timeout time of the access request is greater than or equal to the access waiting time, judging whether the number of access retries is greater than or equal to the preset number of access retries; when the number of access retries is greater than or equal to the preset number of access retries, returning an access error message; when the number of access retries is less than the preset number of access retries, after the access waiting time has passed, executing the access behavior corresponding to the access request.
[0065] Specifically, when the returned response information is platform current limiting, it is necessary to determine whether the timeout period of the access request is less than the access waiting time. If it is greater than or equal to the waiting time, access the open platform API to obtain the access result.
[0066] It should be noted that before returning the response information again after the waiting time is over, it is necessary to compare the access retry count with the preset access retry count. When the access retry count is greater than or equal to the preset access retry count, the access error information corresponding to the access request is returned. When the access retry count is less than the preset access retry count, the open platform API is accessed to obtain the access result.
[0067] It should also be noted that when accessing the open platform API again, if the returned response information is still the platform flow control, and the waiting time has changed, the access request still cannot be successfully accessed. At this time, it is necessary to re-compare the timeout time and the waiting time, and increase the number of access retries by 1.
[0068] In order to improve the efficiency of obtaining access results corresponding to access requests and reduce the number of calls to the application program interface, optionally, in the access control method provided in the embodiment of the present application, before determining whether a token is currently stored in the token bucket in the server, the method also includes: determining whether there is an access result corresponding to the access request in the cache of the server, and returning the access result if there is an access result in the cache; if there is no access result in the cache, executing the step of determining whether a token is currently stored in the token bucket in the server.
[0069] Specifically, the cache may be a storage device for storing access results that have been obtained, for example, a server memory or a distributed cache system. Before determining whether a token is currently stored in the token bucket in the server, it is possible to first query whether the access result corresponding to the access request has been stored in the cache. If the access result corresponding to the access request has been stored in the cache, the access result in the cache may be directly called without obtaining the token in the token bucket. If the access result corresponding to the access request is not stored in the cache, the token acquisition and access result acquisition operations are performed.
[0070] In order to obtain access results from the cache, optionally, in the access control method provided in the embodiment of the present application, the cache includes a first-level cache and a second-level cache, the cache time of the first-level cache is greater than the cache time of the second-level cache, and it is determined whether there is an access result corresponding to the access request in the cache of the server, and if the access result exists in the cache, returning the access result includes: determining whether there is an access result in the first-level cache; if there is an access result in the first-level cache, returning the access result; if there is no access result in the first-level cache, determining whether there is an access result in the second-level cache; if the access result exists in the second-level cache, returning the access result.
[0071] Specifically, Figure 3 FIG. 1 is a schematic diagram of a cache module provided according to Embodiment 1 of the present invention. Figure 3 As shown, the first-level cache can be a server memory, and the second-level cache can be a distributed cache system, such as a redis distributed cache system. The cache time unit of the first-level cache can be seconds, for example, caching for 30 seconds, and deleting the corresponding access results after 30 seconds. The cache time unit of the second-level cache can be minutes, for example, caching for 30 minutes, and deleting the corresponding access results after 30 minutes.
[0072] Figure 4 FIG. 1 is a flow chart of a cache module operation according to the first embodiment of the present invention. Figure 4 As shown, when receiving an access request, the cache module first queries whether the access result corresponding to the access request is stored in the first-level cache. If the access result corresponding to the access request is already stored in the first-level cache, the access result is returned. If the access result corresponding to the access request is not stored in the first-level storage, the cache module queries whether the access result corresponding to the access request is stored in the second-level cache. If the access result corresponding to the access request is already stored in the second-level cache, the access result is returned. If the access result corresponding to the access request is not stored in the second-level storage, a request to obtain the access result is made to the application interface, and the access result is returned after successful acquisition. By obtaining the request result from the cache, the access frequency and access pressure of the interface are reduced.
[0073] In order to synchronously update the access results stored in the first-level cache and the second-level cache, optionally, in the access control method provided in the embodiment of the present application, when the access result exists in the second-level cache, after returning the access result, the method also includes: synchronizing the access result to the first-level cache; when the response information indicates that the access is successful, after returning the access result, the method also includes: synchronizing the access result to the first-level cache and the second-level cache.
[0074] Specifically, Figure 4 As shown, when the access result exists in the secondary cache, the access result is returned and the access result is synchronously stored in the primary cache, so that when a subsequent access request with the same access result is received, the corresponding access result can be directly obtained and returned in the primary cache.
[0075] Similarly, after obtaining the access results through the open platform API, the access results can be synchronously stored in the first-level cache and the second-level cache, so that when subsequent access requests with the same access results are received, the corresponding access results can be directly obtained and returned in the first-level cache and the second-level cache, thereby improving the return speed of the access results and reducing the access pressure of the open platform API.
[0076] In order to adjust the rate of token generation under access requests with different traffic volumes, optionally, in the access control method provided in the embodiment of the present application, when tokens are stored in the token bucket, after the tokens are allocated to the access requests, the method further includes: determining whether the number of tokens stored in the token bucket is greater than or equal to a token number threshold; when the number of tokens stored in the token bucket is greater than or equal to the token number threshold, issuing tokens to the token bucket at a pre-first rate; when the number of tokens stored in the token bucket is less than the token number threshold, issuing tokens to the token bucket at a second rate, wherein the second rate is greater than the first rate.
[0077] Specifically, the token quantity threshold may be a certain token quantity value in the token bucket. Since the number of access requests in different time periods is different, and the token bucket may be a dual-speed token bucket, the token bucket may adjust the token production speed according to the number of requests. When the number of access requests is large, the tokens in the token bucket are consumed quickly, resulting in the number of remaining tokens in the token bucket being lower than the token quantity threshold. In this case, the token bucket needs to produce tokens quickly, that is, produce at the second rate. When the number of access requests is small, the tokens in the token bucket are consumed slowly, resulting in the number of remaining tokens in the token bucket being greater than or equal to the token quantity threshold. In this case, the token bucket may produce tokens at a normal rate, that is, produce at the first rate.
[0078] For example, Figure 5a A schematic diagram of a token bucket provided according to Embodiment 1 of the present invention is shown in FIG. Figure 5a As shown, the token quantity threshold of the token bucket can be 40%. When the number of access requests is large, the tokens in the token bucket are consumed quickly, resulting in the number of remaining tokens in the token bucket being less than 40%. At this time, the token bucket can generate tokens according to PR (Peak Rate) to cope with the sudden increase in access request traffic. Figure 5b FIG. 1 is a schematic diagram of another token bucket provided according to Embodiment 1 of the present invention. Figure 5b As shown, when the number of access requests is small, the tokens in the token bucket are consumed slowly, resulting in the number of remaining tokens in the token bucket being greater than or equal to 40%. At this time, the token bucket can generate tokens according to the committed rate (CR). This embodiment achieves the effect of normal token supply under different access request flows by adjusting the token bucket's token production rate.
[0079] In order to avoid the increase of server workload due to the resending of a large number of access requests that have not obtained tokens, optionally, in the access control method provided in the embodiment of the present application, after determining whether the token bucket in the server currently stores tokens, the method further includes: returning an access error message if no tokens are stored in the token bucket; or sending an advance token to the access request if no tokens are stored in the token bucket, and after the effective time of the advance token arrives, executing the step of determining whether the fuse module in the server is currently in a blown state.
[0080] Specifically, since the number of tokens issued in the token bucket within a fixed time period is fixed, when an access request cannot obtain a token because the token has been issued or has not been produced, the access request that cannot wait can directly return an access error message, or an advance token can be issued to the access request that can wait, where each advance token has an effective time. After the advance token reaches the effective time, the access request can again determine whether the fuse module in the server is currently in a blown state, and obtain the access result if it is not blown.
[0081] Figure 6 Flow chart of a token bucket operation provided according to the first embodiment of the present invention, as shown in FIG. Figure 6 As shown, when the token bucket receives an access request, it can determine whether there is a token in the token bucket. If there is a token, send an access request to the corresponding API, that is, proceed to the next step to determine whether the fuse module in the server is currently in a blown state. If there is no token in the token bucket, obtain an advance token. After obtaining the advance token, wait. When the effective time arrives, send an access request to the corresponding API, that is, proceed to the next step to determine whether the fuse module in the server is currently in a blown state. If the advance token is not obtained, return an access error message.
[0082] Figure 7 FIG. 1 is a flow chart of the operation of a fuse module according to the first embodiment of the present invention. Figure 7 As shown, when the fuse module receives an access request, it first determines the status of the fuse module. When the fuse module is in the blown state, it obtains the fuse waiting time and determines whether it can wait. If it cannot wait, it returns an access error message. If it can wait, it waits and determines the current blown state after the fuse time is reached. When the fuse module is in the unblown state, it obtains the return result to determine whether the open platform API is limited.
[0083] In the case of current limiting, obtain the current limiting waiting time and determine whether waiting is possible. If waiting is not possible, return access error information. If waiting is possible, wait and determine the current open platform status after the current limiting waiting time is reached. If the current open platform status is not current limited, obtain the access result corresponding to the access request.
[0084] Example 2
[0085] According to an embodiment of the present invention, a flowchart of another access control method is also provided. Figure 8 As shown, the method includes:
[0086] When the server receives an access request, it determines whether the corresponding access result is stored in the cache module. If it is stored, the access result is returned. If not, the token in the token bucket is obtained. If there is no token in the token bucket, it waits or returns an access error message. If there is a token in the token bucket, it obtains the token and enters the fuse module.
[0087] When the fuse module receives an access request, it first determines the status of the fuse module. When the fuse module is in the fuse state, it obtains the fuse waiting time and determines whether it can wait. If it cannot wait, it returns an access error message. If it can wait, it waits and tries again after the fuse time is reached.
[0088] When the fuse module is in an unblown state, obtain the returned result to determine whether the open platform API is subject to current limiting. If so, obtain the current limiting waiting time and determine whether waiting is possible. If not, return an access error message. If possible, wait. After the current limiting waiting time is reached, determine the current open platform status. If the current open platform status is not subject to current limiting, obtain the access result corresponding to the access request.
[0089] This embodiment controls the total number of calls to the third-party platform API by the caller per unit time by setting a secondary cache mechanism and token bucket current limiting and adding a fuse and transparent retry mechanism, and returns information to automatically calculate the waiting time when the open platform fuses and limits the current, and automatically and transparently retries after the waiting time is reached, thereby avoiding long-term business interruption caused by the third-party open platform access layer limiting the IP dimension, and avoiding long-term business interruption caused by continuous sending of requests when the third-party platform limits the enterprise or API dimension, thereby achieving the purpose of avoiding the request frequency exceeding the frequency limit of the platform interface, thereby achieving the technical effect of avoiding long-term business interruption and ensuring the availability and stability of the business, and further solving the technical problem that when the access to the platform interface exceeds the restriction conditions, the interface current limiting measures are triggered, resulting in the inability to use the platform functions.
[0090] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should know that the present invention is not limited by the described action sequence, because according to the present invention, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present invention.
[0091] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods of various embodiments of the present invention.
[0092] Example 3
[0093] According to an embodiment of the present invention, an access control device for implementing the above access control method is also provided. Fig. 9 As shown, the device comprises:
[0094] A first receiving unit 91 is used for the server to receive an access request;
[0095] A first determination unit 92, used to determine whether a token is currently stored in a token bucket in the server;
[0096] A first allocation unit 93 is used to allocate a token to an access request when a token is stored in the token bucket, and to determine whether a fuse module in the server is currently in a blown state;
[0097] A first stopping unit 94, configured to stop executing the access behavior corresponding to the access request when the fuse module is in a fuse state;
[0098] A first execution unit 95, configured to execute the access behavior corresponding to the access request and receive response information for the access request when the fuse module is not in a fuse state, wherein the fuse state is used to indicate that the access request is in a current-limited state;
[0099] The first returning unit 96 is used to return the access result when the response information indicates that the access is successful, and to stop executing the access behavior corresponding to the access request when the response information indicates that the access fails.
[0100] Optionally, in the access control device provided in the embodiment of the present application, the device also includes: a second judgment unit, used to determine whether there is an access result corresponding to the access request in the cache of the server, and return the access result if the access result exists in the cache; a second execution unit, used to execute the step of determining whether a token is currently stored in the token bucket in the server if the access result does not exist in the cache.
[0101] Optionally, in the access control device provided in the embodiment of the present application, the cache includes a first-level cache and a second-level cache, the cache time of the first-level cache is greater than that of the second-level cache, and the second judgment unit includes: a first judgment module, used to judge whether there is an access result in the first-level cache; a first return module, used to return the access result if there is an access result in the first-level cache; a second judgment module, used to judge whether there is an access result in the second-level cache if there is no access result in the first-level cache; a second return module, used to return the access result if there is an access result in the second-level cache.
[0102] Optionally, in the access control device provided in an embodiment of the present application, when the access result exists in the secondary cache, after returning the access result, the method further includes: synchronizing the access result to the primary cache; when the response information indicates that the access is successful, after returning the access result, the method further includes: synchronizing the access result to the primary cache and the secondary cache.
[0103] Optionally, in the access control device provided in the embodiment of the present application, the device also includes: a third judgment unit, used to judge whether the number of tokens stored in the token bucket is greater than or equal to a token number threshold; a first issuance unit, used to issue tokens to the token bucket at a first rate when the number of tokens stored in the token bucket is greater than or equal to the token number threshold; a second issuance unit, used to issue tokens to the token bucket at a second rate when the number of tokens stored in the token bucket is less than the token number threshold, wherein the second rate is greater than the first rate.
[0104] Optionally, in the access control device provided in the embodiment of the present application, the device also includes: a second return unit, used to return an access error message when no token is stored in the token bucket; or, when no token is stored in the token bucket, send an advance token to the access request, and after the effective time of the advance token arrives, execute the step of determining whether the fuse module in the server is currently in a blown state.
[0105] Optionally, in the access control device provided in the embodiment of the present application, the device also includes: a first acquisition unit, used to acquire the current access waiting time when the fuse module is in a blown state, and determine whether the timeout time of the access request is less than the current access waiting time; a third return unit, used to return access error information when the timeout time of the access request is less than the current access waiting time; a fourth judgment unit, used to determine whether the number of access retries is greater than or equal to the preset number of access retries when the timeout time of the access request is greater than or equal to the current access waiting time; a fourth return unit, used to return access error information when the number of access retries is greater than or equal to the preset number of access retries; a third execution unit, used to execute the access behavior corresponding to the access request after the current access waiting time when the number of access retries is less than the preset number of access retries.
[0106] Optionally, in the access control device provided in the embodiment of the present application, the device also includes: a second acquisition unit, used to determine the access waiting time according to the response information, and to determine whether the timeout time of the access request is less than the access waiting time; a fifth return unit, used to return access error information when the timeout time of the access request is less than the access waiting time; a fifth judgment unit, used to determine whether the number of access retries is greater than or equal to the preset number of access retries when the timeout time of the access request is greater than or equal to the access waiting time; a sixth return unit, used to return access error information when the number of access retries is greater than or equal to the preset number of access retries; and a fourth execution unit, used to execute the access behavior corresponding to the access request after the access waiting time has passed when the number of access retries is less than the preset number of access retries.
[0107] It should be noted that the first receiving unit 91, the first judging unit 92, the first allocating unit 93, the first stopping unit 94, the first executing unit 95, and the first returning unit 96 correspond to steps S202 to S212 in the first embodiment, and the six modules and the corresponding steps have the same examples and application scenarios, but are not limited to the contents disclosed in the first embodiment. It should be noted that the above modules, as part of the device, can be run in the computer terminal 10 provided in the first embodiment.
[0108] Example 4
[0109] The embodiment of the present invention can provide a computer terminal, which can be any computer terminal device in a computer terminal group. Optionally, in this embodiment, the computer terminal can also be replaced by a terminal device such as a mobile terminal.
[0110] Optionally, in this embodiment, the computer terminal may be located in at least one network device among a plurality of network devices of the computer network.
[0111] In this embodiment, the above-mentioned computer terminal can execute the program code of the following steps in the access control method of the application: the server receives an access request; determines whether a token is currently stored in the token bucket in the server; if a token is stored in the token bucket, allocates the token to the access request, and determines whether the fuse module in the server is currently in a blown state; if the fuse module is in a blown state, stops executing the access behavior corresponding to the access request; if the fuse module is not in a blown state, executes the access behavior corresponding to the access request, and receives response information for the access request, wherein the blown state is used to indicate that the access request is in a limited flow state; if the response information indicates that the access is successful, returns the access result, and if the response information indicates that the access fails, stops executing the access behavior corresponding to the access request.
[0112] Optionally, Fig.10 is a structural block diagram of a computer terminal according to an embodiment of the present invention. Fig.10 As shown, the computer terminal A may include: one or more (only one is shown in the figure) processors, a memory, and a transmission device.
[0113] Among them, the memory can be used to store software programs and modules, such as the program instructions / modules corresponding to the access control method and device in the embodiment of the present invention. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory, that is, realizing the above-mentioned access control method. The memory may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include a memory remotely arranged relative to the processor, and these remote memories can be connected to the terminal A via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0114] The processor can call the information and application stored in the memory through the transmission device to perform the following steps:
[0115] The server receives an access request; determines whether a token is currently stored in a token bucket in the server; if a token is stored in the token bucket, allocates the token to the access request, and determines whether a fuse module in the server is currently in a blown state; if the fuse module is in a blown state, stops executing the access behavior corresponding to the access request; if the fuse module is not in a blown state, executes the access behavior corresponding to the access request, and receives response information for the access request, wherein the blown state is used to indicate that the access request is in a limited state; if the response information indicates that the access is successful, returns the access result, and if the response information indicates that the access fails, stops executing the access behavior corresponding to the access request.
[0116] The embodiment of the present invention provides an access control scheme. The server receives an access request; determines whether a token is currently stored in a token bucket in the server; when a token is stored in the token bucket, the token is allocated to the access request, and determines whether a fuse module in the server is currently in a fuse state; when the fuse module is in a fuse state, the access behavior corresponding to the access request is stopped; when the fuse module is not in a fuse state, the access behavior corresponding to the access request is executed, and response information for the access request is received, wherein the fuse state is used to indicate that the access request is in a current-limited state; when the response information indicates that the access is successful, the access result is returned; when the response information indicates that the access fails, the access behavior corresponding to the access request is stopped, and the number of accesses per unit time of the caller is controlled by setting a token bucket current limit and adding a fuse and transparent retry mechanism, so as to achieve the purpose of avoiding the access request from exceeding the interface limit, thereby solving the technical problem that the current-limiting measures of the interface are triggered when the access to the platform interface exceeds the limit condition, resulting in the inability to use the platform function.
[0117] It can be understood by those skilled in the art that Fig.10 The structure shown is for illustration only, and the computer terminal may also be a smart phone (such as an Android phone, an iOS phone, etc.), a tablet computer, a handheld computer, a mobile Internet device (Mobile Internet Devices, MID), a PAD, or other terminal devices. Fig.10 The structure of the electronic device is not limited. For example, the computer terminal 10 may also include Fig.10 More or fewer components (such as network interfaces, display devices, etc.) shown in, or having Fig.10 Different configurations are shown.
[0118] A person of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the hardware related to the terminal device through a program, and the program can be stored in a computer-readable storage medium, and the storage medium may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0119] Example 5
[0120] The embodiment of the present invention further provides a storage medium. Optionally, in this embodiment, the storage medium can be used to store the program code executed by the access control method provided in the first embodiment.
[0121] Optionally, in this embodiment, the above storage medium may be located in any computer terminal in a computer terminal group in a computer network, or in any mobile terminal in a mobile terminal group.
[0122] Optionally, in this embodiment, the storage medium is configured to store program code for executing the following steps: the server receives an access request; determines whether a token is currently stored in a token bucket in the server; if a token is stored in the token bucket, allocates the token to the access request, and determines whether a fuse module in the server is currently in a blown state; if the fuse module is in a blown state, stops executing the access behavior corresponding to the access request; if the fuse module is not in a blown state, executes the access behavior corresponding to the access request, and receives response information for the access request, wherein the blown state is used to indicate that the access request is in a limited state; if the response information indicates that the access is successful, returns the access result, and if the response information indicates that the access fails, stops executing the access behavior corresponding to the access request.
[0123] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0124] In the above embodiments of the present invention, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0125] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0126] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0127] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0128] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk and other media that can store program codes.
[0129] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. An access control method, characterized in that: include: The server receives an access request for an application program interface, where the application program interface is an application program interface on a third-party platform. When a user sends the access request to the third-party platform, the access request is intercepted by the server, and the server restricts the access request according to the settings of the third-party platform, thereby calling the application program interface without triggering a restriction threshold of the third-party platform. Determine whether a token bucket in the server currently stores a token, wherein the token in the token bucket is used to restrict access requests in the IP dimension; In the case where the token is stored in the token bucket, the token is allocated to the access request, and it is determined whether the fuse module in the server is currently in a fuse state, wherein the fuse module is used to restrict access requests in the application program interface dimension; When the fuse module is in the fuse state, stopping executing the access behavior corresponding to the access request; When the fuse module is not in the blown state, executing the access behavior corresponding to the access request, and receiving response information for the access request, wherein the blown state is used to indicate that the access request is in a current-limited state; When the response information indicates that the access is successful, the access result is returned; when the response information indicates that the access fails, the access behavior corresponding to the access request is stopped.
2. The access control method according to claim 1, characterized in that: Before determining whether a token is currently stored in the token bucket in the server, the method further includes: Determine whether there is an access result corresponding to the access request in the cache of the server, and return the access result if the access result exists in the cache; In the case that the access result does not exist in the cache, the step of determining whether a token is currently stored in the token bucket in the server is performed.
3. The access control method according to claim 2, characterized in that: The cache includes a first-level cache and a second-level cache, the cache time of the first-level cache is greater than the cache time of the second-level cache, judging whether there is an access result corresponding to the access request in the cache of the server, and returning the access result if there is the access result in the cache, including: Determine whether the access result exists in the first-level cache; If the access result exists in the first-level cache, returning the access result; If the access result does not exist in the first-level cache, determining whether the access result exists in the second-level cache; If the access result exists in the secondary cache, the access result is returned.
4. The access control method according to claim 3, characterized in that: In the case where the access result exists in the secondary cache, after returning the access result, the method further includes: synchronizing the access result to the primary cache; In the case where the response information indicates that the access is successful, after returning the access result, the method further includes: synchronizing the access result to the first-level cache and the second-level cache.
5. The access control method according to claim 1, characterized in that: In the case where the token is stored in the token bucket, after allocating the token to the access request, the method further includes: Determine whether the number of tokens stored in the token bucket is greater than or equal to a token number threshold; When the number of tokens stored in the token bucket is greater than or equal to the token number threshold, issuing tokens to the token bucket at a pre-first rate; When the number of tokens stored in the token bucket is less than the token number threshold, tokens are issued to the token bucket at a second rate, wherein the second rate is greater than the first rate.
6. The access control method according to claim 1, characterized in that: After determining whether a token is currently stored in the token bucket in the server, the method further includes: If no token is stored in the token bucket, an access error message is returned; or, In the case where no token is stored in the token bucket, a prepaid token is sent to the access request, and after the effective time of the prepaid token arrives, a step of determining whether the fuse module in the server is currently in a blown state is performed.
7. The access control method according to claim 1, characterized in that: When the fuse module is in the blown state, after stopping executing the access behavior corresponding to the access request, the method further includes: When the fuse module is in a blown state, obtaining a current access waiting time, and determining whether a timeout time of the access request is less than the current access waiting time; When the timeout period of the access request is less than the current access waiting time, an access error message is returned; In the case where the timeout period of the access request is greater than or equal to the current access waiting time, determining whether the number of access retries is greater than or equal to a preset number of access retries; When the access retry number is greater than or equal to the preset access retry number, returning access error information; When the access retry number is less than the preset access retry number, after the current access waiting time has elapsed, the access behavior corresponding to the access request is executed.
8. The access control method according to claim 1, characterized in that: In the case where the response information indicates that the access fails, after stopping the access behavior corresponding to the access request, the method further includes: Determine the access waiting time according to the response information, and judge whether the timeout time of the access request is less than the access waiting time; When the timeout period of the access request is less than the access waiting time, returning access error information; In the case where the timeout period of the access request is greater than or equal to the access waiting time, determining whether the number of access retries is greater than or equal to a preset number of access retries; When the access retry number is greater than or equal to the preset access retry number, returning access error information; When the access retry number is less than the preset access retry number, after the access waiting time has elapsed, the access behavior corresponding to the access request is executed.
9. An access control device, characterized in that: include: A first receiving unit is used for a server to receive an access request for an application program interface, where the application program interface is an application program interface on a third-party platform. When a user sends the access request to the third-party platform, the access request is intercepted by the server, and the server restricts the access request according to the settings of the third-party platform, so as to call the application program interface without triggering a restriction threshold of the third-party platform; A first judgment unit is used to judge whether a token bucket in the server currently stores a token, wherein the token in the token bucket is used to restrict access requests in the IP dimension; a first allocation unit, configured to allocate the token to the access request when the token is stored in the token bucket, and to determine whether a fuse module in the server is currently in a fuse state, wherein the fuse module is configured to restrict access requests in the application program interface dimension; A first stopping unit, configured to stop executing the access behavior corresponding to the access request when the fuse module is in the fuse state; a first execution unit, configured to execute the access behavior corresponding to the access request and receive response information for the access request when the fuse module is not in the fuse state, wherein the fuse state is used to indicate that the access request is in a current-limited state; The first returning unit is configured to return an access result if the response information indicates that the access is successful, and to stop executing the access behavior corresponding to the access request if the response information indicates that the access fails.
10. A storage medium, characterized in that: The storage medium includes a stored program, wherein when the program is executed, the device where the storage medium is located is controlled to execute the access control method according to any one of claims 1 to 8.
11. A processor, characterized in that: The processor is used to run a program, wherein the program executes the access control method described in any one of claims 1 to 8 when running.
Citation Information
Patent Citations
Flow monitoring method and device, computer device and storage medium
CN109194584A
Access request processing method and device based on terminal-server architecture
CN110391880A
Flow limiting method and device based on token bucket
CN110545246A
Access control method and system and storage medium
CN110809011A
Distributed flow limiting method for high concurrency requests
CN110995611A
