CN115529353A - Method for realizing API gateway request forwarding scheduling - Google Patents
Method for realizing API gateway request forwarding scheduling Download PDFInfo
- Publication number
- CN115529353A CN115529353A CN202211151150.3A CN202211151150A CN115529353A CN 115529353 A CN115529353 A CN 115529353A CN 202211151150 A CN202211151150 A CN 202211151150A CN 115529353 A CN115529353 A CN 115529353A
- Authority
- CN
- China
- Prior art keywords
- task
- gateway
- request
- thread pool
- worker
- 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.)
- Withdrawn
Links
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L47/00—Traffic control in data switching networks
- H04L47/50—Queue scheduling
- H04L47/62—Queue scheduling characterised by scheduling criteria
- H04L47/622—Queue service order
- H04L47/6225—Fixed service order, e.g. Round Robin
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Computer And Data Communications (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
Abstract
The invention discloses a method for realizing API gateway request forwarding scheduling, which comprises the steps of buffering requests by creating a queue, constructing a task thread pool to consume the queue, scheduling request forwarding, increasing real-time monitoring of the task thread pool, predicting the number of requests in the next stage according to the working state of a gateway, and dynamically adjusting parameters of the thread pool. Therefore, the invention can respond to the new incoming request in time under the condition of ensuring high concurrency, and can effectively buffer the request task when the system resources are in shortage, thereby ensuring the fault tolerance and the stability of the gateway service.
Description
Technical Field
The invention relates to the field of network communication methods, in particular to a method for realizing API gateway request forwarding scheduling.
Background
At present, a known API gateway service is to open a third party API to the outside, a third party service system registers an API service provided by the third party service system to a gateway service platform, and the third party service system is opened to the outside through the gateway service, and the API gateway service platform performs functions of API management, authentication, flow control, fusing, log recording, and the like.
With the popularity of micro-services of the software development system, a unified API gateway is increasingly relied on to authenticate and forward and schedule requests. The conventional method of the existing API gateway is that after a request is received and corresponding verification filtering is carried out, a redirection request of http is directly used for sending the request to a real back-end request, so that the management of a corresponding gateway API unified inlet and the request to a real back-end server are achieved.
However, under the condition of large concurrency, the existing API gateway can generate corresponding request blocking, and further cannot service the API in time.
Disclosure of Invention
The invention aims to provide a method for realizing API gateway request forwarding scheduling, which solves the problem that the API gateway in the prior art cannot serve in time when the request amount is large.
In order to achieve the purpose, the technical scheme adopted by the invention is as follows:
a method for realizing API gateway request forwarding scheduling, a task thread pool is configured in advance according to requirements, a queue mechanism is set, and a high-concurrency high-performance gateway system is realized, comprising the following steps:
step S1, a task thread pool is created through the thread number in the configuration file of the API gateway, the system CPU core number, the memory capacity and other relevant configurations, and the task thread pool can keep a certain number of active threads, so that the fast putting-in use is convenient. And setting the maximum worker thread worker number and the maximum simultaneous work task number of the task thread pool. The task thread pool also has a statistical function, and can perform real-time statistics on the resource use condition of the current thread pool;
s2, when the network request reaches the gateway, the gateway filters and verifies the request according to the configuration file, packages the request which accords with the rule into a task object, and then adds the packaged task into a global task queue;
and S3, circularly accessing the task queue by the gateway, checking whether the task is to be processed or not, inquiring the task thread pool by the gateway if the task is to be processed, checking whether a worker is available at present or not, distributing the task to the worker for scheduling if the worker is available at present, and modifying the number of the workers currently available in the task thread pool. And if no available idle worker is available currently, suspending taking out the task from the task queue, and adding the new network request into the queue after the API gateway still receives the new network request and encapsulates the new network request into the task.
Furthermore, after the system processing capacity range is set in the configuration file, the API gateway carries out real-time statistics on the request quantity index based on a sliding window algorithm, if the quantity has an increasing trend, the worker quantity in the task thread pool is increased, and if the request quantity has a decreasing trend, the idle worker quantity in the task thread pool is reduced. By judging the trend of the request quantity, system resources can be prepared in advance before higher request quantity reaches the gateway, and the processing capacity and the processing speed of the system are improved.
The invention buffers large batch of requests by creating a queue, constructs a task thread pool to consume the queue, carries out scheduling of request forwarding, and sets the maximum worker and the maximum number of tasks capable of being processed in the task thread pool in an initialization way. And the real-time monitoring of the task thread pool is increased, the request quantity of the next stage is predicted according to the working state of the gateway, and the parameters of the thread pool are dynamically adjusted. Therefore, the invention can respond to the new incoming request in time under the condition of ensuring high concurrency, and can effectively buffer the request task when the system resources are in shortage, thereby ensuring the fault tolerance and the stability of the gateway service.
Drawings
FIG. 1 is a block diagram of a method flow of an embodiment of the present invention.
Detailed Description
The invention is further illustrated with reference to the following figures and examples.
As shown in fig. 1, a method for implementing API gateway request forwarding scheduling in this embodiment includes the following steps:
step S1, a task thread pool is created through the thread number in the configuration file of the API gateway, the system CPU core number, the memory capacity and other relevant configurations, and the task thread pool can keep a certain number of active threads, so that the fast putting-in use is convenient. And setting the maximum worker thread worker number and the maximum simultaneous work task number of the task thread pool. The task thread pool also has a statistical function, and can perform real-time statistics on the resource use condition of the current thread pool;
s2, after the network request reaches the gateway, the gateway filters and verifies the request according to the configuration file, and for the request which meets the rule, the gateway packages the request into a task object and then adds the packaged task to a global task queue;
and S3, circularly accessing the task queue by the gateway, checking whether the task is to be processed or not, inquiring the task thread pool by the gateway if the task is to be processed, checking whether a worker is available at present or not, distributing the task to the worker for scheduling execution if the worker is available at present, and modifying the number of the workers currently available in the task thread pool. And if no available idle worker is available currently, suspending taking out the task from the task queue, and adding the new network request into the queue after the API gateway still receives the new network request and encapsulates the new network request into the task.
The embodiments of the present invention are described only for the preferred embodiments of the present invention, and not for the limitation of the concept and scope of the present invention, and various modifications and improvements made to the technical solution of the present invention by those skilled in the art without departing from the design concept of the present invention shall fall into the protection scope of the present invention, and the technical content of the present invention which is claimed is fully set forth in the claims.
Claims (2)
1. A method for realizing API gateway request forwarding scheduling is characterized in that a task thread pool is configured in advance according to requirements, a queue mechanism is set, and a high-concurrency high-performance gateway system is realized, and the method comprises the following steps:
s1, establishing a task thread pool through the thread quantity related configuration in a configuration file of an API gateway, and setting the maximum worker thread worker quantity and the maximum simultaneous work task quantity of the task thread pool;
s2, after the network request reaches the gateway, the gateway filters and verifies the request according to the configuration file, and for the request which meets the rule, the gateway packages the request into a task object and then adds the packaged task to a global task queue;
s3, circularly accessing the task queue by the gateway, checking whether the task is to be processed or not, inquiring a task thread pool by the gateway if the task is to be processed, checking whether a worker is available at present or not, distributing the task to the worker for scheduling if the worker is available at present, and modifying the number of the workers which are available at present in the task thread pool; and if no available idle worker is available currently, suspending taking out the task from the task queue, and adding the new network request into the queue after the API gateway still receives the new network request and encapsulates the new network request into the task.
2. The method for realizing the request forwarding scheduling of the API gateway according to claim 1, wherein after a system processing capacity range is set in a configuration file, the API gateway performs real-time statistics on a request quantity index based on a sliding window algorithm, and if the quantity has a growth trend, the worker quantity in a task thread pool is increased; and if the number of the requests tends to decrease, reducing the number of idle workers in the task thread pool.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211151150.3A CN115529353A (en) | 2022-09-21 | 2022-09-21 | Method for realizing API gateway request forwarding scheduling |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211151150.3A CN115529353A (en) | 2022-09-21 | 2022-09-21 | Method for realizing API gateway request forwarding scheduling |
Publications (1)
Publication Number | Publication Date |
---|---|
CN115529353A true CN115529353A (en) | 2022-12-27 |
Family
ID=84700072
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202211151150.3A Withdrawn CN115529353A (en) | 2022-09-21 | 2022-09-21 | Method for realizing API gateway request forwarding scheduling |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN115529353A (en) |
-
2022
- 2022-09-21 CN CN202211151150.3A patent/CN115529353A/en not_active Withdrawn
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN109257293B (en) | Speed limiting method and device for network congestion and gateway server | |
EP2422495B1 (en) | Dynamic adjustment of connection setup request parameters | |
EP3588865B1 (en) | Event ingestion management | |
US8959237B2 (en) | Web services requests throttling | |
CN113381944B (en) | System current limiting method, apparatus, electronic device, medium, and program product | |
CN101547159B (en) | Method and device for preventing network congestion | |
US20040085984A1 (en) | System and method for receive queue provisioning | |
CN103297347B (en) | A kind of load balance process method and device | |
CN101459605A (en) | Method and device for flow control | |
CN113315720B (en) | Data flow control method, system and equipment | |
US8121129B2 (en) | Optimizing throughput of data in a communications network | |
CN110830388A (en) | Data scheduling method, device, network equipment and computer storage medium | |
CN116232804A (en) | API gateway based on micro-service architecture | |
CN114286447A (en) | Method, device and storage medium for adjusting scheduling priority | |
CN101272334B (en) | Method, device and equipment for processing QoS service by multi-core CPU | |
CN115529353A (en) | Method for realizing API gateway request forwarding scheduling | |
CN114979250B (en) | Message pushing method, device and equipment | |
CN113904994B (en) | Method for uniformly reporting big data of home gateway to platform | |
Jarma et al. | Dynamic service contract enforcement in service-oriented networks | |
CN115357363A (en) | Current limiting method and device, task response system, electronic equipment and storage medium | |
CN105743999A (en) | Distributed link access bandwidth control system | |
CN108243091B (en) | Information sharing device and information sharing method | |
WO2024131421A1 (en) | Adaptive dynamic traffic-limiting method and device for message middleware, and medium | |
CN113271258B (en) | Data transmission processing method, system and device | |
US7996845B2 (en) | Methods and apparatus to control application execution resource with a variable delay |
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 | ||
WW01 | Invention patent application withdrawn after publication |
Application publication date: 20221227 |
|
WW01 | Invention patent application withdrawn after publication |