Application APP current limiting method, system and related equipment
By receiving and processing API requests in the application APP, using the current limiting API expiration time array and current limiting strategy, it can effectively truncate and scientific diversion of requested server traffic, solving the problem that existing current limiting methods cannot effectively limit the current, and improving the system's processing capability and user experience.
Patent Information
- Application Number
- CN202211272989.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-18
- Publication Date
- 2025-03-28
- Estimated Expiration
- 2042-10-18
AI Technical Summary
The existing flow restriction method cannot effectively truncate the traffic of the requested server, nor can it be scientifically diverted, resulting in a simultaneous downtime of the front and back ends in the promotional activities of the e-commerce industry, affecting user experience and reputation.
When the application APP communicates with the backend, it receives the user's API request and determines whether to limit the API request based on the pre-established array of current limit API expiration time in the front-end database. If the interactive data is exceptional data, get the current limiting policy and update the current limiting API expiration time array to achieve current limiting and shunting.
Effectively truncate the traffic of the requested server, prevent system downtime, scientific diversion, improve system processing capabilities and user experience, and reduce promotion costs.
Smart Images

Figure CN115643214B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of current limiting control technology, and in particular to a current limiting method, system and related equipment for an application program (APP). Background Art
[0002] At present, the e-commerce industry often conducts some large-scale promotional activities, such as flash sales of goods, or new customer acquisition activities by sponsoring a certain evening party. In this process, many times more traffic than usual will be generated in a short period of time. For any e-commerce product, improper handling can easily cause simultaneous downtime of the front-end and back-end. In addition, it will cause user dissatisfaction, reduce reputation, and incur huge promotion costs.
[0003] In related technologies, a common method of limiting traffic is to optimize the code of the backend server and physically expand its capacity so that it can withstand large amounts of traffic. However, the expansion of the server is limited by cost and other factors and also has its upper limit.
[0004] In addition, another method of limiting traffic is to limit and divert traffic at the front end of the traffic entrance, so that some users can use it normally, while other restricted users can also have a more friendly experience, so that the entire system will not crash. However, the diversion cannot be performed more scientifically.
[0005] It can be seen from this that the existing current limiting methods cannot effectively cut off the traffic requesting the server, nor can they scientifically divert the traffic. Summary of the invention
[0006] In view of this, an embodiment of the present invention provides an application APP flow limiting method, system and related equipment to achieve the purpose of effectively cutting off the flow of requesting servers and scientifically diverting the flow.
[0007] To achieve the above objectives, the embodiments of the present invention provide the following technical solutions:
[0008] A first aspect of an embodiment of the present invention discloses a method for limiting the flow of an application program APP, the method comprising:
[0009] When the application APP interacts with the backend for data communication, an application program interface API request sent by the user through the application APP is received, and the API request at least includes an API name and an API expiration time;
[0010] According to the API request, obtain the current limiting API expiration time array in the pre-established front-end database;
[0011] Determine whether the current limiting API expiration time array limits the API request;
[0012] If there is no restriction, receiving the interaction data sent by the backend according to the API request;
[0013] If the interaction data is normal data, respond to the user operation;
[0014] If the interaction data is abnormal data, obtain the current limiting strategy in the front-end database, and the abnormal data includes an error code corresponding to the API name;
[0015] Determine whether the error code is in the current limiting strategy;
[0016] If yes, according to the error code, find the current limiting scenario code in the current limiting strategy, and read the current limiting delay time in the current limiting scenario code;
[0017] Update the current limiting API expiration time array and provide a friendly prompt;
[0018] If not, an interface error message prompt is given according to the error code.
[0019] Optionally, when the application program APP performs data communication interaction with the backend, before receiving an application program interface API request sent by the application program APP, the method further includes:
[0020] When starting the application APP, obtaining a current limiting strategy in a pre-established server, and reading a current limiting strategy switch corresponding to the current limiting strategy;
[0021] If the current limiting strategy switch is in the on state, using the current limiting strategy to update the local current limiting strategy in the front-end database;
[0022] If the current limiting strategy switch is in the off state, clear the local current limiting strategy;
[0023] The latest version of the current limiting strategy is obtained through the MQTT long link, and the local current limiting strategy is updated using the latest version of the current limiting strategy.
[0024] Optionally, also include:
[0025] If restricted, determine whether the API expiration time has expired;
[0026] If yes, delete the API name and respond to the next API request normally;
[0027] If not, the API request is restricted and a friendly prompt is given.
[0028] Optionally, the determining whether the current limiting API expiration time array limits the API request includes:
[0029] Compare the API name and API expiration time in the API request with the API name and API current limiting expiration timestamp in the current limiting API expiration time array respectively;
[0030] If the API name and API expiration time in the API request do not exist in the current limiting API expiration time array, determine that the current limiting API expiration time array does not limit the API request;
[0031] If the API name and API expiration time in the API request exist in the current-limiting API expiration time array, determine that the current-limiting API expiration time array limits the API request.
[0032] A second aspect of an embodiment of the present invention discloses an application APP current limiting system, the system comprising:
[0033] A first receiving module is used to receive an application program interface API request sent by a user through the application program APP when the application program APP performs data communication interaction with the backend, wherein the API request at least includes an API name and an API expiration time;
[0034] A first acquisition module is used to acquire a current limiting API expiration time array in a pre-established front-end database according to the API request;
[0035] A first judgment module is used to judge whether the current limiting API expiration time array limits the API request, if not, execute the second receiving module, if so, execute the third judgment module;
[0036] The second receiving module is used to receive the interaction data sent by the backend according to the API request;
[0037] A response module, used for responding to the user operation if the interaction data is normal data;
[0038] A second acquisition module is used to acquire the current limiting strategy in the front-end database if the interaction data is abnormal data, and the abnormal data includes an error code corresponding to the API name;
[0039] A second judgment module is used to judge whether the error code is in the current limiting strategy, if so, execute the search and read module, if not, execute the error prompt module;
[0040] The search and reading module is used to search for the current limiting scenario code in the current limiting strategy according to the error code, and read the current limiting delay time in the current limiting scenario code;
[0041] A first update module is used to update the current limiting API expiration time array and provide a friendly prompt;
[0042] The error prompt module is used to provide an interface error information prompt according to the error code.
[0043] Optionally, when the first receiving module is used for data communication interaction between the application program APP and the backend, before receiving the application program interface API request sent by the application program APP, it also includes:
[0044] A reading module, used to obtain a current limiting strategy in a pre-established server when starting an application APP, and read a current limiting strategy switch corresponding to the current limiting strategy;
[0045] A second updating module is used to update the local current limiting strategy in the front-end database using the current limiting strategy if the current limiting strategy switch is in the on state;
[0046] A clearing module, used to clear the local current limiting strategy if the current limiting strategy switch is in the off state;
[0047] The third updating module is used to obtain the latest version of the current limiting strategy through the MQTT long link, and use the latest version of the current limiting strategy to update the local current limiting strategy.
[0048] Optionally, also include:
[0049] The third judgment module is used to judge whether the API expiration time has expired;
[0050] A deletion module, used for deleting the API name if yes, and responding normally to the next API request;
[0051] The restriction module is used to restrict the API request and provide a friendly prompt.
[0052] Optionally, the first judgment module includes:
[0053] A comparison unit, used to compare the API name and API expiration time in the API request with the API name and API current limiting expiration timestamp in the current limiting API expiration time array respectively;
[0054] A first determining unit is configured to determine that the API request is not restricted by the current limiting API expiration time array if the API name and the API expiration time in the API request do not exist in the current limiting API expiration time array;
[0055] The second determining unit is configured to determine that the API request is limited by the current-limiting API expiration time array if the API name and the API expiration time in the API request exist in the current-limiting API expiration time array.
[0056] A third aspect of an embodiment of the present invention discloses an electronic device, the electronic device comprising a processor;
[0057] The memory is used to store computer programs;
[0058] The processor is used to implement the application APP flow limiting method as described in any one of the first aspects of the embodiments of the present invention when calling and executing the computer program stored in the memory.
[0059] A fourth aspect of an embodiment of the present invention discloses a computer storage medium, in which computer executable instructions are stored. When the computer executable instructions are loaded and executed by a processor, an application APP flow limiting method as described in any one of the first aspect of the embodiment of the present invention is implemented.
[0060] Based on the above-mentioned embodiment of the present invention, an application APP current limiting method, system and related equipment are provided, the method comprising: when the application APP interacts with the back end for data communication, receiving an application program interface API request sent by a user through the application APP, the API request at least including an API name and an API expiration time; according to the API request, obtaining a current limiting API expiration time array in a pre-established front-end database; judging whether the current limiting API expiration time array limits the API request; if not, receiving interaction data sent by the back end according to the API request; if the interaction data is normal data, responding to the user operation; if the interaction data is abnormal data, obtaining a current limiting strategy in the front-end database, the abnormal data including an error code corresponding to the API name; judging whether the error code is in the current limiting strategy; if so, searching for a current limiting scenario code in the current limiting strategy according to the error code, and reading the current limiting delay time in the current limiting scenario code; updating the current limiting API expiration time array, and providing a friendly prompt; if not, providing an interface error information prompt according to the error code. In this solution, when an API request is received, the current limiting API expiration time array is obtained according to the API request. After determining that the current limiting API expiration time array does not limit the API request, the interaction data sent by the backend is received. If the interaction data is abnormal data, after determining that the error code is in the current limiting strategy, the current limiting API expiration time array is updated, thereby effectively cutting off the traffic requesting the server and scientifically diverting it. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0062] Figure 1 A schematic diagram of a flow chart of a method for limiting current of an application program APP provided in an embodiment of the present invention;
[0063] Figure 2 A schematic diagram of a flow chart of updating a storage current limiting strategy provided by an embodiment of the present invention;
[0064] Figure 3 A principle block diagram of a current limiting strategy update storage provided by an embodiment of the present invention;
[0065] Figure 4 A schematic diagram of a flow chart for determining whether a current limiting API expiration time array limits API requests provided by an embodiment of the present invention;
[0066] Figure 5 A principle block diagram of application current limiting provided by an embodiment of the present invention;
[0067] Figure 6 A schematic diagram of the structure of an application APP current limiting system provided by an embodiment of the present invention;
[0068] Figure 7 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0069] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions 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 are within the scope of protection of the present invention.
[0070] In this application, the terms "comprises", "comprising" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprising a ..." does not exclude the presence of other identical elements in the process, method, article or device comprising the element.
[0071] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of this application 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 numbers used in this way can be interchanged where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein.
[0072] As can be seen from the background technology, the existing flow limiting method cannot effectively cut off the flow of requesting servers, nor can it scientifically divert the flow.
[0073] Therefore, an embodiment of the present invention provides an application APP current limiting method, system and related equipment. In this solution, when an API request is received, the current limiting API expiration time array is obtained according to the API request. After determining that the current limiting API expiration time array does not limit the API request, the interaction data sent by the backend is received. If the interaction data is abnormal data, after determining that the error code is in the current limiting strategy, the current limiting API expiration time array is updated, thereby effectively cutting off the traffic requesting the server and scientifically diverting the traffic.
[0074] like Figure 1 The figure is a flow chart of an application APP flow limiting method provided in an embodiment of the present invention.
[0075] It should be noted that the application APP current limiting method can be an APP current limiting method based on a long link.
[0076] The APP flow limiting method of this application mainly includes the following steps:
[0077] Step S101: When the application program APP interacts with the backend for data communication, an application program interface API request sent by the user through the application program APP is received.
[0078] In step S101, the API request at least includes an API name and an API expiration time.
[0079] In the process of specifically implementing step S101, when the application APP interacts with the backend for data communication, in a regular application program interface API request, an application program interface API request sent by any user through the application APP is received.
[0080] Optionally, step S101 is performed before receiving an application program interface API request sent by the application program APP when the application program APP is communicating with the backend, such as Figure 2 As shown, a schematic diagram of a process of updating a storage current limiting strategy provided by an embodiment of the present invention mainly includes the following steps:
[0081] Step S201: when starting the application APP, obtain the current limiting strategy in the pre-established server, and read the current limiting strategy switch corresponding to the current limiting strategy.
[0082] In step S201, the current limiting strategy includes but is not limited to a current limiting strategy switch, a current limiting API array, and current limiting scenario data.
[0083] The current limiting API array includes but is not limited to the scenario code, API name, and interface current limiting error code.
[0084] The current limiting scenario data includes but is not limited to the scenario name, scenario code, current limiting prompt, normal device current limiting duration, and abnormal device current limiting duration.
[0085] In the embodiment of the present invention, the current limiting strategy refers to a strategy model.
[0086] Example model data for the policy model is as follows:
[0087]
[0088]
[0089]
[0090] Step S202: Determine whether the current limiting strategy switch is in the on state, if so, execute step S203, if not, execute step S204.
[0091] In step 202, the state of the current limiting strategy switch includes an open state and a closed state.
[0092] Step S203: Use the current limiting strategy to update the local current limiting strategy in the front-end database.
[0093] In the specific implementation of step S203, when it is determined that the read current limiting strategy switch is in the on state, the current limiting strategy is used to update the local current limiting strategy in the front-end database.
[0094] Step S204: Clear the local current limiting strategy.
[0095] In the specific implementation of step S204, when it is determined that the read current limiting strategy switch is in the off state, the local current limiting strategy in the front-end database is cleared.
[0096] Based on the above content, it can be understood that when the APP is started, the current limiting strategy is read, and whether to store the current limiting strategy in the front-end database is determined according to the state of the current limiting strategy switch corresponding to the current limiting strategy.
[0097] In other words, when the APP is started, a flow limiting strategy is read from the server and stored in the front-end database in advance, so that it can take effect directly without going through the back-end when the network is congested.
[0098] That is to say, after the APP is started, adjust the current limiting strategy switch and interface current limiting strategy as needed.
[0099] It should be noted that the server can control the current limiting strategy switch according to its current concurrent pressure. In actual applications, it is only necessary to turn on the current limiting strategy switch when the current concurrent pressure is high.
[0100] Optionally, in a specific embodiment, the embodiment of the present invention provides another method for updating and storing the current limiting strategy, which mainly includes: obtaining the latest version of the current limiting strategy through the MQTT long link, and using the latest version of the current limiting strategy to update the local current limiting strategy.
[0101] In other words, the current limiting strategy is updated through the MQTT long link.
[0102] It is understandable that after the APP is started, the current limiting strategy is pushed to the APP through the MQTT long link. In other words, the APP receives the latest version of the current limiting strategy. During this process, the backend adjusts the current limiting strategy according to the current concurrent pressure. If the current concurrent pressure decreases, the current limiting strategy switch is turned off and the normal API request response is performed.
[0103] It should be noted that the MQTT long link is established in advance by the APP, that is, it is established when the APP is started. In addition, the MQTT long link can also be used for other services.
[0104] To better understand the process of updating the storage current limiting policy, such as Figure 3 As shown, it is a principle block diagram of a current limiting strategy update storage provided by an embodiment of the present invention.
[0105] exist Figure 3 In the APP, the current limiting strategy is updated and stored in two ways. One is active call, and the timing is when the APP is started. The specific implementation process is: when the APP is started, the current limiting strategy is read from the server, and the current limiting strategy switch corresponding to the current limiting strategy is read. If the current limiting strategy switch is on, the current limiting strategy is used to update the local current limiting strategy in the front-end database, that is, to overwrite the local current limiting strategy data. If the current limiting strategy switch is off, the local current limiting strategy is cleared.
[0106] The other is passive update, which is actively pushed directly through long links such as MQTT. The specific implementation process is: obtain the latest version of the current limiting strategy through the MQTT long link, and use the latest version of the current limiting strategy to update the local current limiting strategy.
[0107] In order to achieve the purpose of timely updating the flow limiting strategy, for example, after the end of the event, you need to immediately close all flow limiting strategies, etc., you can maintain a long link in the APP, receive the push information of the long link, and overwrite and update the flow limiting strategy of the APP, so that it has the ability to dynamically adjust.
[0108] Step S102: According to the API request, obtain the current limiting API expiration time array in the pre-established front-end database.
[0109] In step S102, the current limiting API expiration time array includes but is not limited to the API name, the API current limiting expiration timestamp and the current limiting prompt.
[0110] In the embodiment of the present invention, the current limiting API expiration time array refers to a current limiting API model.
[0111] The sample model data for the current limiting API model is as follows:
[0112]
[0113]
[0114] It should be noted that the data of the current limiting API model is generated from the data of the policy model.
[0115] In the process of specifically implementing step S102, another set of data is read from a pre-established front-end database according to the received API request, that is, an array of current limiting API expiration times in the pre-established front-end database is obtained.
[0116] Step S103: Determine whether the current limiting API expiration time array limits API requests. If not, execute step S104; if so, execute step S112.
[0117] Optionally, the process of executing step S103 to determine whether the current limiting API expiration time array limits the API request is as follows: Figure 4 As shown, it is a schematic diagram of a process for determining whether the current limiting API expiration time array limits API requests provided by an embodiment of the present invention, which mainly includes the following steps:
[0118] Step S401: Compare the API name and API expiration time in the API request with the API name and API current limiting expiration timestamp in the current limiting API expiration time array respectively.
[0119] In the process of implementing step S401, the API request and the current limiting API expiration time array are compared, specifically, the API name in the API request is compared with the API name in the current limiting API expiration time array, and the API expiration time in the API request is compared with the API current limiting expiration timestamp in the current limiting API expiration time array.
[0120] In actual applications, the API name in the API request is matched with the local policy data (i.e., the current limiting API expiration time array) to find the API expiration time, and then determine whether the API is expired. Specifically, the expiration is found through the name in the current limiting API expiration time array (current limiting API model), and then the timestamp is compared to determine whether the API is expired. In other words, the expiration timestamp expiration is used to calculate whether the API is expired.
[0121] Among them, the timestamp is just data, the purpose of which is to determine whether the front-end current limit of the API has expired.
[0122] Step S402: Determine whether the API name and API expiration time in the API request exist in the current limiting API expiration time array. If so, execute step S403; if not, execute step S404.
[0123] Step S403: Determine the current limiting API expiration time array to limit API requests.
[0124] In the process of specifically implementing step S403, when it is determined that the API name and API expiration time in the API request exist in the current-limiting API expiration time array, it is determined that the current-limiting API expiration time array limits the API request, that is, it is determined that the current-limiting API expiration time array limits the API name and API expiration time.
[0125] Step S404: Determine that the current limiting API expiration time array does not limit API requests.
[0126] In the process of specifically implementing step S404, when it is determined that the API name and API expiration time in the API request do not exist in the current-limiting API expiration time array, it is determined that the current-limiting API expiration time array does not limit the API request, that is, it is determined that the current-limiting API expiration time array does not restrict the API name and API expiration time.
[0127] Step S104: receiving the interaction data sent by the backend according to the API request.
[0128] In the embodiment of the present invention, the interaction data is divided into normal data and abnormal data.
[0129] In practical applications, the type of interaction data is determined according to the agreed protocol.
[0130] For example, the data sent by the interface also has a code field. For example, when the code is 0, it is normal data; when it is other values, it is abnormal data.
[0131] In the process of specifically implementing step S104, when it is determined that the current limiting API expiration time array does not restrict the API request, that is, when it is determined that the API in the API request is not in the current limiting API expiration time array, a normal API request is made, that is, a normal data request is made to the backend without any restriction, or in other words, normal interaction is performed with the backend, and the interaction data sent by the backend according to the API request is received, that is, the backend responds to the API request and sends the interaction data according to the API request.
[0132] Step S105: Determine whether the interaction data is normal data, if so, execute step S106, if not, execute step S107.
[0133] In the process of implementing step S105, it is determined whether the interaction data is normal data. If so, step S106 is executed. If not, it indicates that the interaction data is abnormal data, and step S107 is executed.
[0134] Step S106: respond to user operation.
[0135] In the specific implementation of step S106 , when it is determined that the interaction data sent by the backend is normal data, the user operation is responded to.
[0136] Step S107: Obtain the current limiting strategy in the front-end database.
[0137] In step S107, the abnormal data includes an error code corresponding to the API name.
[0138] It should be noted that this error code corresponds to the error_code in the policy model.
[0139] In the specific implementation of step S107, when it is determined that the interaction data sent by the backend is abnormal data, the current limiting strategy in the frontend database is obtained.
[0140] Step S108: Determine whether the error code is in the current limiting strategy. If so, execute step S109; if not, execute step S111.
[0141] Step S109: According to the error code, find the current limiting scenario code in the current limiting strategy, and read the current limiting delay time in the current limiting scenario code.
[0142] Step S110: Update the current limiting API expiration time array and provide a friendly prompt.
[0143] In the embodiment of the present invention, the friendly reminder words include but are not limited to: "The activity is in full swing, please try again later."
[0144] In the process of specifically implementing steps S109 to S110, when it is determined that the error code is in the current limiting strategy, the current limiting scenario code in the current limiting strategy is searched according to the error code, and the current limiting delay time in the current limiting scenario code is read, and then, the current limiting API expiration time array is updated, that is, the name of the current limiting scenario information, the current limiting prompt, and the API current limiting expiration timestamp are added to the current limiting API expiration time array, and a friendly prompt is given.
[0145] It can be understood that when it is determined that the error code is in the current limiting strategy, the scene code scene_code is found according to the error code error_code, and then the corresponding scene_code in the scene_list is found according to the scene code scene_code, and the name, msg, expiration time (calculated by expiration) and other data are stored in the current limiting API model, that is, the current limiting API expiration time array is added, or in other words, the current limiting API expiration time array is updated to prepare for current limiting the next time the user requests, and then still give the user a friendly prompt.
[0146] Take steps S105 to S110 as an example. For example, if the APP needs to obtain the data in list A, it needs to make a backend interface request. If the data sent by the backend interface is code=0, it is considered that the normal business interaction is completed. If the code is 2666, it is abnormal data. According to 2666, the scene_code is 100, and then according to 100, the corresponding data with scene_code of 100 in the sent scene_list is found, such as name, msg, and the expiration time is calculated. It is added to the current limiting API model.
[0147] It should be noted that if the user repeatedly makes this API request within a short period of time, the restriction can be implemented by repeating steps S101 to S110.
[0148] Step S111: Prompt interface error information according to the error code.
[0149] In the process of implementing step S111, when it is determined that the error code is not in the current limiting strategy, the interface error information prompt is performed normally according to the error code, and there is no need to update the current limiting API expiration time array.
[0150] Step S112: Determine whether the API expiration time has expired, if so, execute step S113, if not, execute step S114.
[0151] In the process of implementing step S112, when it is determined that the current-limiting API expiration time array limits the API request, that is, when it is determined that the API in the API request is in the current-limiting API expiration time array, determine whether the API expiration time has expired. If so, execute step S113, if not, execute step S114.
[0152] Step S113: Delete the API name and respond to the next API request normally.
[0153] In the process of implementing step S113, when it is determined that the API in the API request is in the current-limiting API expiration time array and has expired, the API name is deleted and the next API request is responded to normally. That is, this API is eliminated, the API request is regarded as an unlimited request, and then the API request is performed normally.
[0154] It should be noted that because the local current limiting policy has expired, the restriction of this API (API refers to the request interface of a certain business) has become invalid and this API needs to be deleted. Therefore, it is necessary to communicate with the backend to obtain the latest response instructions from the backend.
[0155] Step S114: Restrict API requests and provide friendly prompts.
[0156] In the process of implementing step S114, when it is determined that the API in the API request is in the current limiting API expiration time array and has not expired, the front end intercepts it and directly prompts the user with friendly prompts such as "The event is in full swing, please try again later". In other words, the API request is restricted, that is, the relevant code of the network request is not run next, and the prompt of the local current limiting policy is directly read for friendly prompts.
[0157] It is understandable that limiting API requests can prevent them from accessing the server, alleviating the pressure on the backend and enabling the backend to operate normally.
[0158] To better understand the process of using application current limiting control methods, such as Figure 5 As shown, it is a principle block diagram of application current limiting provided by an embodiment of the present invention.
[0159] exist Figure 5 In the example, when making a normal API request, first determine whether the current limiting API expiration time array has restricted the API. In other words, compare the current limiting API expiration time array, mainly comparing its API name and expiration time.
[0160] If there is no limit, make an interface request; if the data sent by the backend is normal data, respond to the user operation; if the data sent by the backend is abnormal data, determine whether the error code in the abnormal data is in the current limiting strategy. If not, respond to the error prompt of the interface; if it is in the current limiting strategy, add the error code to the current limiting API array, that is, update the current limiting API expiration time array and expiration timestamp, so as to prepare for current limiting the next time the user requests, and then still give the user a friendly prompt.
[0161] It should be noted that making an interface request refers to data communication and interaction between the APP and the backend; the common request method is to initiate a network request to the backend through the agreed http protocol, obtain the required business data, and display or respond on the frontend.
[0162] If there is a restriction, determine whether the API has expired. If the API has expired, remove the API from the request and treat it as an unlimited request. Repeat the specific process of not restricting the API in the current limiting API expiration time array. If the API has not expired, directly restrict its request and prevent it from accessing the server, thereby reducing the pressure on the backend and enabling the backend to operate normally. At the same time, provide a friendly prompt to the user, that is, provide the friendly prompt in the current limiting API expiration time array to achieve the purpose of current limiting.
[0163] Based on the above description, it can be understood that the present invention distinguishes and intercepts normal and abnormal users through the front-end flow limiting strategy, effectively cuts off the flow of requesting servers, and ensures the normal operation of operations. In other words, it realizes large flow limitation and diversion on the APP front end.
[0164] Based on an application APP current limiting method provided by an embodiment of the present invention, when an API request is received, the current limiting API expiration time array is obtained according to the API request. After determining that the current limiting API expiration time array does not limit the API request, the interaction data sent by the backend is received. If the interaction data is abnormal data, after determining that the error code is in the current limiting strategy, the current limiting API expiration time array is updated, thereby effectively cutting off the traffic requesting the server and scientifically diverting the traffic.
[0165] Corresponding to the method for limiting the flow of an application APP shown in the above embodiment of the present invention, the embodiment of the present invention also provides a system for limiting the flow of an application APP, such as Figure 6 As shown, the application APP current limiting system includes: a first receiving module 601, a first acquisition module 602, a first judgment module 603, a second receiving module 604, a response module 605, a second acquisition module 606, a second judgment module 607, a search and read module 608, a first update module 609 and an error prompt module 610.
[0166] The first receiving module 601 is used to receive an application program interface API request sent by a user through an application program APP when the application program APP performs data communication interaction with a backend.
[0167] The API request at least includes the API name and the API expiration time.
[0168] The first acquisition module 602 is used to acquire a current limiting API expiration time array in a pre-established front-end database according to an API request.
[0169] The first judgment module 603 is used to judge whether the current limiting API expiration time array limits the API request. If not, the second receiving module 604 is executed. If so, the third judgment module is executed.
[0170] The second receiving module 604 is used to receive the interaction data sent by the backend according to the API request.
[0171] The response module 605 is used to respond to the user operation if the interaction data is normal data.
[0172] The second acquisition module 606 is used to acquire the current limiting strategy in the front-end database if the interaction data is abnormal data.
[0173] The abnormal data includes the error code corresponding to the API name.
[0174] The second judgment module 607 is used to judge whether the error code is in the current limiting strategy. If so, the search and reading module 608 is executed; if not, the error prompt module 610 is executed.
[0175] The search and reading module 608 is used to search for the current limiting scenario code in the current limiting strategy according to the error code, and read the current limiting delay time in the current limiting scenario code.
[0176] The first updating module 609 is used to update the current limiting API expiration time array and provide a friendly prompt.
[0177] The error prompt module 610 is used to provide an interface error information prompt according to the error code.
[0178] Optional, based on the above Figure 6 The application APP current limiting system shown is combined with Figure 6 In the first receiving module 601, when the application APP performs data communication interaction with the back end, before receiving the application interface API request sent by the user through the application APP, the application APP current limiting system further sets a reading module, a second update module, a clearing module and a third update module.
[0179] The reading module is used to obtain the current limiting strategy in the pre-established server when starting the application APP, and read the current limiting strategy switch corresponding to the current limiting strategy.
[0180] The second updating module is used to update the local current limiting strategy in the front-end database using the current limiting strategy if the current limiting strategy switch is in the on state.
[0181] The clear module is used to clear the local current limiting strategy if the current limiting strategy switch is in the off state.
[0182] The third update module is used to obtain the latest version of the current limiting strategy through the MQTT long link, and use the latest version of the current limiting strategy to update the local current limiting strategy.
[0183] Optional, based on the above Figure 6 The application APP current limiting system shown is combined with Figure 6 The application APP current limiting system further sets up a third judgment module, a deletion module and a restriction module.
[0184] The third judgment module is used to judge whether the API expiration time has expired.
[0185] The deletion module is used to delete the API name if yes, and respond normally to the next API request.
[0186] The restriction module is used to restrict API requests and provide friendly prompts.
[0187] Optional, based on the above Figure 6 The first judging module 603 shown includes:
[0188] The comparison unit is used to compare the API name and API expiration time in the API request with the API name and API current limiting expiration time timestamp in the current limiting API expiration time array respectively.
[0189] The first determining unit is used to determine that the current-limiting API expiration time array does not limit the API request if the API name and API expiration time in the API request do not exist in the current-limiting API expiration time array.
[0190] The second determining unit is used to determine that the current-limiting API expiration time array limits the API request if the API name and API expiration time in the API request exist in the current-limiting API expiration time array.
[0191] It should be noted that the specific principles and execution processes of each module in the application APP current limiting system disclosed in the above-mentioned embodiment of the present invention are the same as the application APP current limiting method implemented in the above-mentioned present invention. Please refer to the corresponding parts of the application APP current limiting method disclosed in the above-mentioned embodiment of the present invention, and will not be repeated here.
[0192] An application APP current limiting system provided based on an embodiment of the present invention, when receiving an API request, obtains the current limiting API expiration time array according to the API request, and after determining that the current limiting API expiration time array does not limit the API request, receives the interaction data sent by the backend, if the interaction data is abnormal data, after determining that the error code is in the current limiting strategy, updates the current limiting API expiration time array, thereby effectively cutting off the traffic requesting the server and scientifically diverting the traffic.
[0193] Based on the application APP current limiting system disclosed in the above embodiment of the present invention, the above modules can be implemented by a hardware device composed of a processor and a memory. Specifically, the above modules are stored in the memory as program units, and the processor executes the above program units stored in the memory to implement the application APP current limiting.
[0194] The processor includes a kernel, which retrieves the corresponding program unit from the memory. One or more kernels can be set, and the application APP current limiting can be achieved by adjusting the kernel parameters.
[0195] An embodiment of the present invention provides a computer storage medium, which includes a storage medium for storing an application APP current limiting program, wherein when the program is executed by a processor, an application APP current limiting method as described in any one of the above method embodiments is implemented.
[0196] An embodiment of the present invention provides a processor, which is used to run a program, wherein the application APP current limiting method disclosed in the above method embodiment is executed when the program is running.
[0197] An embodiment of the present invention provides an electronic device, such as Figure 7 , which is a schematic diagram of the structure of an electronic device 70 provided in an embodiment of the present invention.
[0198] The electronic device in the embodiment of the present invention may be a server, a PC, a PAD, a mobile phone, etc.
[0199] The electronic device includes at least one processor 701 , at least one memory 702 connected to the processor, and a bus 703 .
[0200] The processor 701 and the memory 702 communicate with each other via the bus 703. The processor 701 is used to execute the program stored in the memory 702.
[0201] Memory 702 is used to store a program, which is at least used for: when the application APP interacts with the back end for data communication, receiving an application interface API request sent by the user through the application APP, the API request at least including the API name and API expiration time; according to the API request, obtaining a current limiting API expiration time array in a pre-established front-end database; judging whether the current limiting API expiration time array restricts the API request; if not, receiving the interaction data sent by the back end according to the API request; if the interaction data is normal data, responding to the user operation; if the interaction data is abnormal data, obtaining the current limiting strategy in the front-end database, the abnormal data including the error code corresponding to the API name; judging whether the error code is in the current limiting strategy; if so, according to the error code, searching for the current limiting scenario code in the current limiting strategy, and reading the current limiting delay time in the current limiting scenario code; updating the current limiting API expiration time array, and providing a friendly prompt; if not, providing an interface error information prompt according to the error code.
[0202] The present application also provides a computer program product, which, when executed on an electronic device, is suitable for executing a program for initializing the following method steps:
[0203] When the application APP interacts with the backend for data communication, an application program interface API request sent by the user through the application APP is received, and the API request contains at least the API name and API expiration time; according to the API request, a current limiting API expiration time array in a pre-established front-end database is obtained; it is determined whether the current limiting API expiration time array limits the API request; if not, the interaction data sent by the backend according to the API request is received; if the interaction data is normal data, the user operation is responded to; if the interaction data is abnormal data, the current limiting strategy in the front-end database is obtained, and the abnormal data includes the error code corresponding to the API name; it is determined whether the error code is in the current limiting strategy; if so, according to the error code, the current limiting scenario code in the current limiting strategy is searched, and the current limiting delay time in the current limiting scenario code is read; the current limiting API expiration time array is updated, and a friendly prompt is given; if not, an interface error message prompt is given according to the error code.
[0204] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0205] In a typical configuration, the device includes one or more processors (CPU), memory and bus. The device may also include input / output interface, network interface and the like.
[0206] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip. The memory is an example of a computer-readable medium.
[0207] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0208] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can refer to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system or system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can refer to the partial description of the method embodiment. The system and system embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without creative work.
[0209] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0210] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for limiting the flow of an application program APP, characterized in that: The method comprises: When the application APP interacts with the backend for data communication, an application program interface API request sent by the user through the application APP is received, and the API request at least includes an API name and an API expiration time; According to the API request, obtain the current limiting API expiration time array in the pre-established front-end database; Determine whether the current limiting API expiration time array limits the API request; If there is no restriction, receiving the interaction data sent by the backend according to the API request; If the interaction data is normal data, respond to the user operation; If the interaction data is abnormal data, obtain the current limiting strategy in the front-end database, and the abnormal data includes an error code corresponding to the API name; Determine whether the error code is in the current limiting strategy; If yes, according to the error code, find the current limiting scenario code in the current limiting strategy, and read the current limiting delay time in the current limiting scenario code; Update the current limiting API expiration time array and provide a friendly prompt; If not, an interface error message prompt is given according to the error code.
2. The method according to claim 1, characterized in that When the application program APP performs data communication interaction with the backend, before receiving an application program interface API request sent by the application program APP, the method further includes: When starting the application APP, obtaining a current limiting strategy in a pre-established server, and reading a current limiting strategy switch corresponding to the current limiting strategy; If the current limiting strategy switch is in the on state, using the current limiting strategy to update the local current limiting strategy in the front-end database; If the current limiting strategy switch is in the off state, clear the local current limiting strategy; The latest version of the current limiting strategy is obtained through the MQTT long link, and the local current limiting strategy is updated using the latest version of the current limiting strategy.
3. The method according to claim 1, characterized in that Also includes: If restricted, determine whether the API expiration time has expired; If yes, delete the API name and respond to the next API request normally; If not, the API request is restricted and a friendly prompt is given.
4. The method according to claim 1, characterized in that: The determining whether the current limiting API expiration time array limits the API request includes: Compare the API name and API expiration time in the API request with the API name and API current limiting expiration timestamp in the current limiting API expiration time array respectively; If the API name and API expiration time in the API request do not exist in the current limiting API expiration time array, determine that the current limiting API expiration time array does not limit the API request; If the API name and API expiration time in the API request exist in the current-limiting API expiration time array, determine that the current-limiting API expiration time array limits the API request.
5. An application APP current limiting system, characterized in that: The system comprises: A first receiving module is used to receive an application program interface API request sent by a user through the application program APP when the application program APP performs data communication interaction with the backend, wherein the API request at least includes an API name and an API expiration time; A first acquisition module is used to acquire a current limiting API expiration time array in a pre-established front-end database according to the API request; A first judgment module is used to judge whether the current limiting API expiration time array limits the API request, if not, execute the second receiving module, if so, execute the third judgment module; The second receiving module is used to receive the interaction data sent by the backend according to the API request; A response module, used for responding to user operations if the interaction data is normal data; A second acquisition module is used to acquire the current limiting strategy in the front-end database if the interaction data is abnormal data, and the abnormal data includes an error code corresponding to the API name; A second judgment module is used to judge whether the error code is in the current limiting strategy, if so, execute the search and read module, if not, execute the error prompt module; The search and reading module is used to search for the current limiting scenario code in the current limiting strategy according to the error code, and read the current limiting delay time in the current limiting scenario code; A first update module is used to update the current limiting API expiration time array and provide a friendly prompt; The error prompt module is used to provide an interface error information prompt according to the error code.
6. The system according to claim 5, characterized in that When the first receiving module is used for data communication interaction between the application program APP and the backend, before receiving the application program interface API request sent by the application program APP, it also includes: A reading module, used to obtain a current limiting strategy in a pre-established server when starting an application APP, and read a current limiting strategy switch corresponding to the current limiting strategy; A second updating module is used to update the local current limiting strategy in the front-end database using the current limiting strategy if the current limiting strategy switch is in the on state; A clearing module, used to clear the local current limiting strategy if the current limiting strategy switch is in the off state; The third updating module is used to obtain the latest version of the current limiting strategy through the MQTT long link, and use the latest version of the current limiting strategy to update the local current limiting strategy.
7. The system according to claim 5, characterized in that Also includes: The third judgment module is used to judge whether the API expiration time has expired; A deletion module, used for deleting the API name if yes, and responding normally to the next API request; The restriction module is used to restrict the API request and provide a friendly prompt.
8. The system according to claim 5, characterized in that The first judgment module includes: A comparison unit, used to compare the API name and API expiration time in the API request with the API name and API current limiting expiration timestamp in the current limiting API expiration time array respectively; A first determining unit is configured to determine that the API request is not restricted by the current limiting API expiration time array if the API name and the API expiration time in the API request do not exist in the current limiting API expiration time array; The second determining unit is configured to determine that the API request is limited by the current-limiting API expiration time array if the API name and the API expiration time in the API request exist in the current-limiting API expiration time array.
9. An electronic device, characterized in that: The electronic device comprises a processor and a memory; The memory is used to store computer programs; The processor is used to implement the application APP flow limiting method as described in any one of claims 1 to 4 when calling and executing the computer program stored in the memory.
10. A computer storage medium, characterized in that: The computer storage medium stores computer executable instructions, and when the computer executable instructions are loaded and executed by the processor, the application APP flow limiting method as described in any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
API distributed current limiting implementation method
CN110276182A
Intelligent gateway dynamic flow limiting implementation method
CN113595925A