CN114461308A - Method and system for reducing network API repeated request concurrency - Google Patents

Method and system for reducing network API repeated request concurrency Download PDF

Info

Publication number
CN114461308A
CN114461308A CN202210033262.2A CN202210033262A CN114461308A CN 114461308 A CN114461308 A CN 114461308A CN 202210033262 A CN202210033262 A CN 202210033262A CN 114461308 A CN114461308 A CN 114461308A
Authority
CN
China
Prior art keywords
request
reservation
reservation request
tokens
information
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210033262.2A
Other languages
Chinese (zh)
Inventor
黄立根
张增政
刘保胜
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangdong Hongsheng Technology Co ltd
Original Assignee
Guangdong Hongsheng Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Guangdong Hongsheng Technology Co ltd filed Critical Guangdong Hongsheng Technology Co ltd
Priority to CN202210033262.2A priority Critical patent/CN114461308A/en
Publication of CN114461308A publication Critical patent/CN114461308A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4482Procedural
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q10/00Administration; Management
    • G06Q10/02Reservations, e.g. for tickets, services or events
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L47/00Traffic control in data switching networks
    • H04L47/10Flow control; Congestion control
    • H04L47/215Flow control; Congestion control using token-bucket
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/548Queue

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Business, Economics & Management (AREA)
  • General Physics & Mathematics (AREA)
  • Tourism & Hospitality (AREA)
  • General Engineering & Computer Science (AREA)
  • Economics (AREA)
  • Marketing (AREA)
  • Operations Research (AREA)
  • Quality & Reliability (AREA)
  • Strategic Management (AREA)
  • Entrepreneurship & Innovation (AREA)
  • General Business, Economics & Management (AREA)
  • Development Economics (AREA)
  • Signal Processing (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Human Resources & Organizations (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

The invention discloses a method and a system for reducing network API repeated request concurrency, wherein the method comprises the following steps: generating a reservation request by using the vehicle ID information, wherein the reservation request carries an IP address; judging whether the same vehicle ID information exists to make a reservation request or in a reservation process: if yes, the reservation request is invalid and information is prompted; if not, judging whether the current queue has a token: if no token exists in the current queue, the reservation request is invalid and information is prompted; if the current queue has tokens, consuming one token in the queue to write an IP address carried by the reservation request, and judging whether the request times of the IP address in the preset time exceed the maximum request number: if yes, the reservation request is invalid and information is prompted; if not, the reservation request is accepted. The technical problems of network card pause, data delay and even program crash caused by interface errors caused by the fact that a background receives a large number of reservation requests are effectively solved.

Description

Method and system for reducing network API repeated request concurrency
Technical Field
The invention relates to the technical field of motor vehicle service reservation, in particular to a method and a system for reducing network Application Program Interface (API) repeated request concurrency.
Background
In the existing reservation service of the vehicle driving management micro-message small program, part of users use methods such as one person and multiple mobile phones or third-party tools to make reservation so as to create the same license plate, vehicle data such as a frame number and the like to enter a reservation service interface to make reservation and number robbery, so that a background receives an excessively high peak value network API request in a short period, a network is blocked, data is delayed, and even an interface is wrong, so that the program is crashed.
Disclosure of Invention
The invention aims to provide a method and a system for reducing concurrence of network API repeated requests, which are used for solving the technical problems of network jamming, data delay and even program crash caused by interface errors caused by receiving an excessively high peak value network API request in a short period of time in a background.
In order to achieve the purpose, the invention adopts the following technical scheme: a method of concurrently processing API requests, said method comprising the steps of:
generating a specified number of tokens in each specified time, adding the tokens into the queue, and if the number of the tokens in the queue exceeds a preset value, discarding the redundant tokens;
generating a reservation request by using the vehicle ID information, wherein the reservation request carries an IP address;
judging whether the same vehicle ID information exists to make a reservation request or is in a reservation process:
if yes, the reservation request is invalid and information is prompted;
if not, judging whether the current queue has a token:
if no token exists in the current queue, the reservation request is invalid and information is prompted;
if the current queue has tokens, consuming one token in the queue to write an IP address carried by the reservation request, and judging whether the request times of the IP address in the preset time exceed the maximum request number: if yes, the reservation request is invalid and information is prompted; if not, the reservation request is accepted.
An alternative embodiment determines whether the same vehicle ID information exists for a reservation request or is in the reservation process based on socket.
In an alternative embodiment, the token is a redis token.
In an alternative embodiment, the token generation speed is 100-200 tokens per second.
In an alternative embodiment, the predetermined value is 100 to 200.
In an optional embodiment, the preset time is 1 to 2 minutes, and the maximum number of requests is 5 to 10.
The second aspect of the invention discloses a system for concurrently processing an API request, which is applied to the method for concurrently processing the API request disclosed by the first aspect of the invention, wherein the system comprises a request reservation client, a node.js timer and a node.js background, the request reservation client is provided with a web.socket.io, the node.js background is provided with a socket.io, and the node.js background receives a socket request long connection of the request reservation client;
a js timer is used for generating tokens with specified quantity in each specified time and adding the tokens into the queue, and if the quantity of the tokens in the queue exceeds a preset value, redundant tokens are abandoned;
the request reservation client is used for acquiring vehicle ID information, generating a reservation request according to the vehicle ID information and sending the reservation request to the node.js background;
the js background is used for receiving a reservation request, and judging whether the same vehicle ID information exists to make the reservation request or is in a reservation process after the reservation request is received: if so, the reservation request is invalid, and a first prompt instruction is sent to the reservation request client; if not, judging whether the current queue has a token: if no token exists in the current queue, the reservation request is invalid, and a second prompt instruction is sent to the reservation request client; if the current queue has tokens, consuming one token in the queue to write an IP address carried by the reservation request, and judging whether the request times of the IP address in the preset time exceed the maximum request number: if so, the reservation request is invalid, and a third prompt instruction is sent to the reservation request client; if not, accepting a reservation request;
the request reservation client is also used for receiving the first prompt instruction, the second prompt instruction and the third prompt instruction so as to display corresponding prompt information.
Compared with the prior art, the embodiment of the invention has the following beneficial effects:
in the embodiment of the invention, tokens are generated and supplemented into the queue within a specified time, the number of the tokens in the queue can be supplemented, wherein the number of the tokens in the queue is used as an API peak value of the reservation request, and when the number of the tokens in the queue is zero, the reservation requests without the tokens are all invalid requests, so that the diversion of the reservation requests is realized.
If a plurality of users make reservations with the same vehicle ID information, the reservation request generated by the repeated vehicle ID information is directly judged to be invalid, the invalid reservation request is regarded as the termination of the reservation request of this time, so that the plurality of users can be prevented from simultaneously making reservation requests for robbery with the same vehicle ID information, one vehicle can make reservations by one person, the waste of the number of tokens in a queue is avoided, and the number of tokens in the queue can be used for reservation requests of other vehicle ID information.
It is worth mentioning that after the consumption token is written into the IP address carried by the reservation request, whether the request frequency of the IP address in the preset time exceeds the maximum request number is judged, so that the same IP address is prevented from being repeatedly applied in a short time, and the limitation on the IP address is realized.
In the invention, by shunting the reservation request, the reservation request can be effective and accepted only if the vehicle ID information in the reservation request is unique and the IP address meets the request requirement, thereby effectively solving the technical problems of network card pause, data delay and even interface error caused by receiving a large number of reservation requests by a background.
Drawings
FIG. 1 is a flow chart of one embodiment of the present invention.
Detailed Description
Reference will now be made in detail to embodiments of the present invention, examples of which are illustrated in the accompanying drawings, wherein like or similar reference numerals refer to the same or similar elements or elements having the same or similar function throughout. The embodiments described below with reference to the accompanying drawings are illustrative only for the purpose of explaining the present invention, and are not to be construed as limiting the present invention.
A method for concurrently processing API requests according to an embodiment of the present invention is described below with reference to fig. 1, where the method includes the following steps:
generating a specified number of tokens in each specified time, adding the tokens into the queue, and if the number of the tokens in the queue exceeds a preset value, discarding the redundant tokens;
generating a reservation request by utilizing the vehicle ID information, wherein the reservation request carries an IP address; the vehicle ID information may be one of a license plate number or a frame number.
Judging whether the same vehicle ID information exists to make a reservation request or is in a reservation process:
if yes, the reservation request is invalid and information is prompted;
if not, judging whether the current queue has a token:
if no token exists in the current queue, the reservation request is invalid and information is prompted;
if the current queue has tokens, consuming one token in the queue to write an IP address carried by the reservation request, and judging whether the request times of the IP address in the preset time exceed the maximum request number: if yes, the reservation request is invalid and information is prompted; if not, the reservation request is accepted.
In the embodiment of the invention, tokens are generated and supplemented into the queue within a specified time, the number of the tokens in the queue can be supplemented, wherein the number of the tokens in the queue is used as an API peak value of the reservation request, and when the number of the tokens in the queue is zero, the reservation requests without the tokens are all invalid requests, so that the diversion of the reservation requests is realized.
If a plurality of users make reservations with the same vehicle ID information, the reservation request generated by the repeated vehicle ID information is directly judged to be invalid, the invalid reservation request is regarded as the termination of the reservation request of this time, so that the plurality of users can be prevented from simultaneously making reservation requests for robbery with the same vehicle ID information, one vehicle can make reservations by one person, the waste of the number of tokens in a queue is avoided, and the number of tokens in the queue can be used for reservation requests of other vehicle ID information.
It is worth mentioning that after the consumption token is written into the IP address carried by the reservation request, whether the request frequency of the IP address in the preset time exceeds the maximum request number is judged, so that the same IP address is prevented from being repeatedly applied in a short time, and the limitation on the IP address is realized.
In the invention, by shunting the reservation request, the reservation request can be effective and accepted only if the vehicle ID information in the reservation request is unique and the IP address meets the request requirement, thereby effectively solving the technical problems of network card pause, data delay and even interface error caused by receiving a large number of reservation requests by a background.
Specifically, it is determined whether the same vehicle ID information exists for a reservation request or in a reservation process based on the socket.
Specifically, the system implementing the embodiment includes a request reservation client, a node.js timer and a node.js background, where the request reservation client is installed with a web app.socket.io, the node.js background is installed with a socket.io, and the node.js background receives a socket request long connection of the request reservation client; therefore, when the same vehicle ID information user enters the reservation interface, the socket Io sends out error information and prompts that only one vehicle can make reservation at the same time so as to prevent the user from entering the reservation interface.
In particular, the token is a redis token.
Specifically, the generation speed of the tokens is 100-200 tokens per second.
Specifically, in the embodiment, the token is a redis token, and 100 to 200 tokens are generated by a node. Of course, the generation speed of the token can be adjusted according to the processing efficiency of the background.
Specifically, the preset value is 100-200. Of course, the preset value can be adjusted according to the processing efficiency of the background.
Specifically, the preset time is 1-2 minutes, and the maximum request number is 5-10.
The invention also discloses a system for concurrently processing the API requests, which comprises a request reservation client, a node.js timer and a node.js background, wherein the request reservation client is provided with the web app.socket.io, the node.js background is provided with the socket.io, and the node.js background receives the socket request long connection of the request reservation client; preferably, in this embodiment, the client requesting reservation is a car management applet, and the user fills in the car ID information in the car management applet to make a reservation for number fetching.
A js timer is used for generating tokens with specified quantity in each specified time and adding the tokens into the queue, and if the quantity of the tokens in the queue exceeds a preset value, redundant tokens are abandoned;
the request reservation client is used for acquiring vehicle ID information, generating a reservation request according to the vehicle ID information and sending the reservation request to the node.js background;
the js background is used for receiving a reservation request, and judging whether the same vehicle ID information exists to make the reservation request or is in a reservation process after the reservation request is received: if so, the reservation request is invalid, and a first prompt instruction is sent to the reservation request client; if not, judging whether the current queue has a token: if no token exists in the current queue, the reservation request is invalid, and a second prompt instruction is sent to the reservation request client; if the current queue has tokens, consuming one token in the queue to write an IP address carried by the reservation request, and judging whether the request times of the IP address in the preset time exceed the maximum request number: if so, the reservation request is invalid, and a third prompt instruction is sent to the reservation request client; if not, accepting a reservation request;
the request reservation client is also used for receiving the first prompt instruction, the second prompt instruction and the third prompt instruction so as to display corresponding prompt information.
In the embodiment of the invention, the node.js timer generates tokens to be supplemented into the queue within a specified time, so that the number of the tokens in the queue can be supplemented, wherein the number of the tokens in the queue is used as an API peak value of the reservation request, and when the number of the tokens in the queue is zero, the current reservation request is an invalid request, thereby realizing the shunting of the reservation request.
If a plurality of users make reservations with the same vehicle ID information, the node.js background directly judges the reservation request generated by the repeated vehicle ID information as invalid, the invalid reservation request is regarded as the termination of the reservation request of this time, so that the plurality of users can be prevented from making reservation for robbing numbers by making reservations with the same vehicle ID information at the same time, one vehicle can make reservations, the waste of the number of tokens in a queue is avoided to be reduced, and the number of tokens in the queue can be used for making reservation applications for other vehicle ID information.
And after the js background writes the IP address carried by the reservation request through the consumption token, judging whether the request frequency of the IP address in the preset time exceeds the maximum request number or not so as to avoid repeated application of the same IP address in a short time, realize limitation on the IP address and effectively avoid concentration of the reservation request.
It should be noted that the content of the prompt information displayed by the client requesting for reservation according to the first prompt instruction, the second prompt instruction and the third prompt instruction is different, for example: when the request reservation client receives the first prompt instruction, the request reservation client prompts: one vehicle can only make a reservation request by one person, and does not need to repeat. When the request reservation client receives the second prompt instruction, the request reservation client prompts: when the current reservation request is full, please try again later. When the request reservation client receives the third prompt instruction, the request reservation client prompts: do not request frequent appointments, please try again later.
In the invention, by shunting the reservation request, the vehicle ID information in the reservation request is unique, and the reservation request can be effective and accepted only if the IP address meets the request requirement, thereby effectively solving the technical problems of program crash caused by network card pause, data delay and even interface error.
Other configurations and operations of a method and system for reducing network API repeat request concurrency according to embodiments of the present invention are known to those of ordinary skill in the art and will not be described in detail herein.
In the description herein, references to the description of the terms "embodiment," "example," etc., mean that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the invention. In this specification, the schematic representations of the terms used above do not necessarily refer to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples.
While embodiments of the invention have been shown and described, it will be understood by those of ordinary skill in the art that: various changes, modifications, substitutions and alterations can be made to the embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the claims and their equivalents.

Claims (7)

1. A method of concurrently processing API requests, comprising: the method comprises the following steps:
generating a specified number of tokens in each specified time, adding the tokens into the queue, and if the number of the tokens in the queue exceeds a preset value, discarding the redundant tokens;
generating a reservation request by utilizing the vehicle ID information, wherein the reservation request carries an IP address;
judging whether the same vehicle ID information exists to make a reservation request or is in a reservation process:
if yes, the reservation request is invalid and information is prompted;
if not, judging whether the current queue has a token:
if no token exists in the current queue, the reservation request is invalid and information is prompted;
if the current queue has tokens, consuming one token in the queue to write an IP address carried by the reservation request, and judging whether the request times of the IP address in the preset time exceed the maximum request number: if yes, the reservation request is invalid and information is prompted; if not, the reservation request is accepted.
2. The method of claim 1, wherein the API request is concurrently processed by: and judging whether the same vehicle ID information exists to make a reservation request or is in a reservation process based on the socket.
3. The method of claim 1, wherein the API request is concurrently processed by: the token is a redis token.
4. The method of claim 1, wherein the API request is concurrently processed by: the generation speed of the tokens is 100-200 tokens per second.
5. The method of claim 1, wherein the API request is concurrently processed by: the preset value is 100-200.
6. The method of claim 1, wherein the API request is concurrently processed by: the preset time is 1-2 minutes, and the maximum request number is 5-10.
7. A system for concurrently processing API requests, comprising: the method for concurrently processing the API requests as claimed in any one of claims 1 to 6, wherein the system includes a request reservation client, a node.js timer, and a node.js background, the request reservation client is installed with a web app.socket.io, the node.js background is installed with a socket.io, and the node.js background receives a socket request long connection of the request reservation client;
a js timer is used for generating tokens with specified quantity in each specified time and adding the tokens into the queue, and if the quantity of the tokens in the queue exceeds a preset value, redundant tokens are abandoned;
the request reservation client is used for acquiring vehicle ID information, generating a reservation request according to the vehicle ID information and sending the reservation request to the node.js background;
the js background is used for receiving a reservation request, and judging whether the same vehicle ID information exists to make the reservation request or is in a reservation process after the reservation request is received: if so, the reservation request is invalid, and a first prompt instruction is sent to the reservation request client; if not, judging whether the current queue has a token: if no token exists in the current queue, the reservation request is invalid, and a second prompt instruction is sent to the reservation request client; if the current queue has tokens, consuming one token in the queue to write an IP address carried by the reservation request, and judging whether the request times of the IP address in the preset time exceed the maximum request number: if yes, the reservation request is invalid, and a third prompt instruction is sent to the reservation request client; if not, accepting a reservation request;
the request reservation client is also used for receiving the first prompt instruction, the second prompt instruction and the third prompt instruction so as to display corresponding prompt information.
CN202210033262.2A 2022-01-12 2022-01-12 Method and system for reducing network API repeated request concurrency Pending CN114461308A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210033262.2A CN114461308A (en) 2022-01-12 2022-01-12 Method and system for reducing network API repeated request concurrency

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210033262.2A CN114461308A (en) 2022-01-12 2022-01-12 Method and system for reducing network API repeated request concurrency

Publications (1)

Publication Number Publication Date
CN114461308A true CN114461308A (en) 2022-05-10

Family

ID=81408744

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210033262.2A Pending CN114461308A (en) 2022-01-12 2022-01-12 Method and system for reducing network API repeated request concurrency

Country Status (1)

Country Link
CN (1) CN114461308A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115578099A (en) * 2022-12-09 2023-01-06 浙江保融科技股份有限公司 Preprocessing method based on foreign exchange price blocking

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115578099A (en) * 2022-12-09 2023-01-06 浙江保融科技股份有限公司 Preprocessing method based on foreign exchange price blocking

Similar Documents

Publication Publication Date Title
WO2019128535A1 (en) Message management method and device, and storage medium
CN111770157B (en) Business processing method and device, electronic equipment and storage medium
CN102668456A (en) Method and system for adapting a session timeout period
CN109766217B (en) Vehicle machine system fault repairing method and device
CN114461308A (en) Method and system for reducing network API repeated request concurrency
CN109040263B (en) Service processing method and device based on distributed system
CN110287146A (en) Using the method, equipment and computer storage medium of downloading
CN110266703A (en) Token method for refreshing, device, storage medium and controlling terminal
CN108111337B (en) Method and equipment for arbitrating main nodes in distributed system
US5946602A (en) Reduction of queuing delays by multiple subgroup assignments
CN106991484B (en) Secondary resource reservation method based on intelligent repeated reservation
CN107146123B (en) Order allocation method and system
CN114217977A (en) Resource allocation method, device, equipment and storage medium
CN109743386B (en) Session request sending method and device, electronic equipment and storage medium
CN112804163A (en) Flow data processing method, device and equipment
US9894493B2 (en) Telematics provisioning method
CN116319592A (en) Message distribution method, device, equipment and storage medium
CN114666615B (en) Resource allocation method, device, server, program, and storage medium
JP4238258B2 (en) Task management apparatus and task management method for in-vehicle electronic control unit
CN1761361A (en) Gprs packet data protocol activation method
US7904612B2 (en) Ticket mechanism for sharing computer resources
CN115331349A (en) Queuing method and device for bank outlets
CN109246387B (en) Method, device and storage medium for calculating conversion of account resources of remote conference
CN112637121A (en) Data port updating method and device, electronic equipment and readable storage medium
CN114416326A (en) Big data control method, device, control system and readable storage medium

Legal Events

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