API gateway request control method, device, equipment and readable storage medium

By using the hash balance method to generate a service priority token ring in the API gateway and processing service requests in the order of tokens, the problem of high service priority requests blocking low service priority requests is solved, and stable response and efficiency balance are achieved for each service priority request.

CN115695318BActive Publication Date: 2025-03-28ELECTRIC POWER RES INST CHINA SOUTHERN POWER GRID CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202211246043.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-11
Publication Date
2025-03-28
Estimated Expiration
2042-10-11

AI Technical Summary

Technical Problem

When existing API gateways handle high service priority requests, low service priority requests may be blocked and unable to respond to important business requests in a timely manner.

Method used

The hash balance method is used to generate a service priority token ring, and ensure that the tokens of each service priority are evenly distributed according to the preset token ring size and the priority weight of each service priority. Then, service requests are stored and extracted according to the token order on the service priority token ring to ensure that all service priority requests can receive a stable response.

Benefits of technology

It effectively avoids the problem of low service priority request blocking caused by excessive high service priority requests, ensures the stable response of API gateway to various service priority requests, and improves the success rate of key business transactions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115695318B_ABST
    Figure CN115695318B_ABST
Patent Text Reader

Abstract

The present application discloses a request control method, device, equipment and readable storage medium of an API gateway, the method comprising: generating a service priority token ring by using a hash balancing method according to a preset token ring size and a priority weight corresponding to each service priority, so that the token hashes of each service priority are evenly distributed on the service priority token ring; storing all service requests of the API gateway in the form of a service request queue, wherein each service request is stored in a service request subqueue matching the service priority in the service request queue according to its own request priority level value; extracting and responding to service requests from the service request subqueues with consistent service priorities in the service request queue in sequence according to the service priority order corresponding to the tokens on the service priority token ring. The present application can effectively balance the processing efficiency of each service request, so that service requests of each service priority of the API gateway can obtain stable service responses.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of microservice technology, and more specifically, to a request control method, apparatus, device, and readable storage medium for an API gateway. Background Art

[0002] Microservice architecture is currently the mainstream development model in the cloud-native environment. The Restful API gateway is the core component of the microservice architecture. It mainly completes the routing and access control of all microservice requests, and provides service governance capabilities such as isolation, circuit breaking, and service degradation. However, it does not provide service priority policy control capabilities, and cannot respond to service requests of different importance and urgency differently to ensure that important businesses can obtain resources and responses faster, thereby improving the success rate of key business transactions.

[0003] Although the HTTP2.0 protocol supports request priority and sets a priority level for each type of resource request, the server can respond to service requests in descending order of service priority based on the priority level information set by HTTP. However, a large number of high-priority service requests will block the interaction of low-priority service resources, causing low-priority requests to be unable to obtain services. Summary of the invention

[0004] In view of this, the present application provides a request control method, device, equipment and readable storage medium for an API gateway, which can effectively balance the processing efficiency of various service requests, effectively avoid the problem in the prior art that a large number of high service priority service requests or slow response of high service priority services lead to blocking of low service priority service requests, so that service requests of each service priority of the API gateway can obtain stable service responses.

[0005] A request control method for an API gateway, comprising:

[0006] According to the preset token ring size and the priority weight corresponding to each service priority, a service priority token ring is generated by using a hash balancing method so that the token hashes of each service priority are evenly distributed on the service priority token ring;

[0007] All service requests of the API gateway are stored in the form of a service request queue, wherein each service request is stored in a service request subqueue matching the service priority in the service request queue according to its own request priority level value;

[0008] According to the service priority order corresponding to the tokens on the service priority token ring, the service requests are sequentially extracted and responded to from the service request sub-queues with the same service priority in the service request queue.

[0009] Optionally, a hash balancing method is used to generate a service priority token ring, including:

[0010] The token spacings of the respective service priorities are calculated according to the priority weights corresponding to the respective service priorities;

[0011] According to the service priority order from low to high in importance, the tokens of the respective service priorities are set in the initial service priority token ring in turn until all the cells of the initial service priority token ring are filled, thereby obtaining the service priority token ring, in which the tokens of the same service priority are evenly placed and the spacing between them meets the spacing between tokens of the respective service priorities.

[0012] Optionally, the token spacings of the service priorities calculated according to the priority weights corresponding to the service priorities include:

[0013] The inverse of the priority weight corresponding to each service priority is determined as each token distance of each service priority.

[0014] Optionally, for a service priority, a process of setting a token in the service priority token ring includes:

[0015] Determine a token start unit corresponding to the service priority and a unit of each token spacing corresponding to the service priority in the service priority token ring;

[0016] Performing idle detection on the token start unit and each unit of the token spacing corresponding to the service priority to determine whether a token has been set in the unit;

[0017] The token of the service priority is set in an idle cell where no token is set, and in an idle cell next to a cell where a token is set.

[0018] Optionally, for a service request, according to its own request priority level value, it is stored in a matching service request subqueue in the service request queue, including:

[0019] Determine the service request subqueue that matches the service request according to the request priority level value corresponding to the service request and the interval range of each service request subqueue in the service request queue;

[0020] The service request is stored in a matching service request sub-queue in the service request queue.

[0021] Optionally, extracting and responding to the service requests from the service request sub-queues with the same service priority in the service request queue in sequence includes:

[0022] Determine the target priority token corresponding to the position of the pointer on the current service priority token ring, where the initial position of the pointer is 0;

[0023] Detecting whether a service request subqueue in the service request queue that is consistent with the priority of the target priority token is empty;

[0024] If the service request subqueue is not empty, extracting and responding to the target service request from the service request subqueue in the service request queue that has the same priority as the target priority token;

[0025] If the service request subqueue is empty or the extraction and response to the target service request is completed, the position of the pointer is increased by 1, and the process of determining the target priority token corresponding to the position of the pointer on the current service priority token ring is returned.

[0026] Optionally, after the position of the pointer is increased by 1, the method further includes:

[0027] If the position of the pointer increases by 1 and exceeds the token ring size, the position of the pointer is reset to zero.

[0028] A request control device for an API gateway, comprising:

[0029] A token ring unit, used to generate a service priority token ring by using a hash balancing method according to a preset token ring size and a priority weight corresponding to each service priority, so that the token hashes of each service priority are evenly distributed on the service priority token ring;

[0030] A request queue unit, used to store all service requests of the A.PI gateway in the form of a service request queue, wherein each of the service requests is stored in a service request subqueue matching the service priority in the service request queue according to its own request priority level value;

[0031] The request extraction unit is used to extract and respond to the service requests from the service request sub-queues with consistent service priorities in the service request queue in sequence according to the service priority order corresponding to the tokens on the service priority token ring.

[0032] A request control device for an API gateway, comprising a memory and a processor;

[0033] The memory is used to store programs;

[0034] The processor is used to execute the program to implement the various steps of the request control method of the API gateway as described above.

[0035] A readable storage medium stores a computer program thereon, and when the computer program is executed by a processor, the various steps of the request control method of the API gateway as described above are implemented.

[0036] It can be seen from the above technical solution that the request control method, device, equipment and readable storage medium of an API gateway provided in the embodiment of the present application use a hash balancing method to generate a service priority token ring according to the preset token ring size and the priority weight corresponding to each service priority, so that the token hashes of each service priority are evenly distributed on the service priority token ring. Therefore, the proportion of tokens of each service priority on the service priority token ring is the same as the priority weight corresponding to each service priority, and the token hashes of each service priority are evenly distributed on the service priority token ring. All service requests of the API gateway are stored in the form of a service request queue, wherein each of the service requests is stored in a service request subqueue matching the service priority in the service request queue according to its own request priority level value.

[0037] According to the order of service priorities corresponding to the tokens on the service priority token ring, the service requests are extracted and responded to from the service request subqueues with the same service priority in the service request queue in sequence. The order and proportion of the service requests extracted from the service request subqueues corresponding to each service priority are consistent with the order and proportion of the tokens of each service priority on the service priority token ring, and the proportion and order of the service priorities of each service request extracted according to the order of tokens on the service priority token ring are also consistent with the proportion and order of the tokens of each service priority on the service priority token ring. Therefore, service requests of any service priority of the API gateway can obtain stable service responses, thereby effectively balancing the processing efficiency of various service requests, and effectively avoiding the problem of low service priority service requests being blocked due to a large number of high service priority service requests in the prior art. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] In order to more clearly illustrate the embodiments of the present application 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 application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.

[0039] Figure 1 A flowchart of a request control method of an API gateway disclosed in this application;

[0040] Figure 2 A schematic diagram of a service priority token ring disclosed in the present application;

[0041] Figure 3 A schematic diagram of a service request queue disclosed in this application;

[0042] Figure 4 This is a structural block diagram of a request control device of an API gateway disclosed in this application;

[0043] Figure 5 This is a hardware structure block diagram of a request control device of an API gateway disclosed in this application. DETAILED DESCRIPTION

[0044] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0045] The present application can be used in many general or special computing device environments or configurations, such as personal computers, server computers, handheld or portable devices, tablet devices, multi-processor devices, distributed computing environments including any of the above devices or equipment, etc.

[0046] An embodiment of the present application provides a request control method for an API gateway, which can be applied to various microservice architectures and can also be applied to various computer terminals or smart terminals. The execution subject can be a processor or server of the computer terminal or smart terminal.

[0047] Next, the present application scheme is introduced. The present application proposes the following technical scheme, please see below for details.

[0048] Figure 1 This is a flowchart of a request control method of an API gateway disclosed in an embodiment of the present application, such as Figure 1 As shown, the method may include:

[0049] Step S1: Generate a service priority token ring using a hash balancing method according to a preset token ring size and a priority weight corresponding to each service priority.

[0050] Specifically, the token hashes of the various service priorities are evenly distributed on the service priority token ring. The present invention performs service priority hierarchical mapping according to the weight value (0-255) in the priority information in the HTTP2.0 header or the customized priority weight in HTTP1.0 / 1.1, arranges the hierarchical service priorities on the priority token ring of a preset token ring size in a balanced arrangement mode, and processes the service requests in the corresponding service priority queue through the priority token ring matching to achieve the priority strategy of service requests at all levels, while avoiding the phenomenon of service failure of low priority requests when high priority requests always exist.

[0051] Define the service priority of the service request according to the importance and urgency of the business, that is, the token priority. Figure 2 As shown, this example assumes that service requests, that is, tokens on the service priority token ring are divided into four service priorities: emergency service priority, core service priority, important service priority and general service priority. The priority weights of each service priority are 50%, 30%, 15% and 5% respectively. In actual business scenarios, the priority weights can be customized and evenly arranged in the service priority token ring composed of 100 units according to the service priority weights, so that various service priority tokens are evenly distributed on the token ring to meet the weight setting requirements, that is, emergency service tokens account for 50%, core service tokens account for 30%, important service tokens account for 15%, and general service tokens account for 5%.

[0052] Step S2: Store all service requests of the API gateway in the form of a service request queue.

[0053] Specifically, each of the service requests is stored in a service request subqueue matching the service priority in the service request queue according to its own request priority level value. For all service requests to the API gateway, they can be mapped to service priorities according to the request priority level value (0 to 255) according to the configuration settings.

[0054] For a service request, it is stored in the matching service request sub-queue in the service request queue according to its own request priority level value, including:

[0055] ① According to the request priority level value corresponding to the service request and the interval range of each service request sub-queue in the service request queue, determine the service request sub-queue that matches the service request.

[0056] ②Store the service request in the matching service request sub-queue in the service request queue.

[0057] like Figure 3As shown, if the request priority value of a service request is in the range of [0, 60), it is mapped as a general service priority request and stored in the general request queue. All service requests of the API gateway can be stored in the service request subqueues matching the service priority in the service request queue according to their respective request priority values.

[0058] Step S3: extract and respond to the service requests from the service request sub-queues with consistent service priorities in the service request queue in sequence according to the service priority order corresponding to the tokens on the service priority token ring.

[0059] Specifically, in actual applications, after the service priority token ring is generated, if the pre-set token ring size and the priority weights corresponding to each service priority have not changed, the service request sub-queue with the same service priority in the service request queue is extracted in turn according to the service priority order corresponding to the token on the service priority token ring, and the service request is responded to.

[0060] For example, Figure 2 Service request extraction and response are started from the current pointer. The current pointer is the initial pointer, and the pointer position is 0. At this time, the token corresponding to the pointer is the emergency service priority, so the service request is extracted from the emergency request queue. Then the pointer position moves to 1. At this time, the token corresponding to the pointer is still the emergency service priority, so the service request is extracted from the emergency request queue again. Then the pointer position moves to 2. At this time, the token corresponding to the pointer is the core service priority, so the service request is extracted from the core request queue.

[0061] It can be seen from the above technical solution that the request control method, device, equipment and readable storage medium of an API gateway provided in the embodiment of the present application use a hash balancing method to generate a service priority token ring according to the preset token ring size and the priority weight corresponding to each service priority, so that the token hashes of each service priority are evenly distributed on the service priority token ring. Therefore, the proportion of tokens of each service priority on the service priority token ring is the same as the priority weight corresponding to each service priority, and the token hashes of each service priority are evenly distributed on the service priority token ring. All service requests of the API gateway are stored in the form of a service request queue, wherein each of the service requests is stored in a service request subqueue matching the service priority in the service request queue according to its own request priority level value.

[0062] According to the order of service priorities corresponding to the tokens on the service priority token ring, the service requests are extracted and responded to from the service request subqueues with the same service priority in the service request queue in sequence. The order and proportion of the service requests extracted from the service request subqueues corresponding to each service priority are consistent with the order and proportion of the tokens of each service priority on the service priority token ring, and the proportion and order of the service priorities of each service request extracted according to the order of tokens on the service priority token ring are also consistent with the proportion and order of the tokens of each service priority on the service priority token ring. Therefore, service requests of any service priority of the API gateway can obtain stable service responses, thereby effectively balancing the processing efficiency of various service requests, and effectively avoiding the problem in the prior art that a large number of high service priority service requests or slow responses to high service priorities lead to blocking of low service priority service requests.

[0063] In some embodiments of the present application, the process of generating a service priority token ring by using a hash balancing method according to a preset token ring size and a priority weight corresponding to each service priority in step S1 is introduced, which may specifically include:

[0064] Step S11, calculating the token distances of the service priorities according to the priority weights corresponding to the service priorities.

[0065] Specifically, the present invention uses a hash balancing algorithm to allow service priority tokens to be hashed and distributed more evenly on the token ring to ensure that the corresponding service priority weights are met and at the same time ensure that the request processing interval of each service priority is minimized.

[0066] Optionally, the token spacings of the service priorities calculated according to the priority weights corresponding to the service priorities include:

[0067] The inverse of the priority weight corresponding to each service priority is determined as each token distance of each service priority.

[0068] For example, if the weight of general service priority is 5%, then the spacing between tokens of general service priority is 1 / 5%, that is, the token spacing is 20. The token starting unit corresponding to the general service priority in the initial service priority token ring, that is, the 20th unit starting from the initial pointer position (the pointer position is 0), and every 20 units thereafter are set to the general service priority.

[0069] Step S12: Set the tokens of each service priority in the initial service priority token ring in sequence according to the service priority order from low to high in importance, until all cells of the initial service priority token ring are filled, thereby obtaining the service priority token ring, in which tokens of the same service priority are evenly placed and the spacing between each pair meets the spacing between tokens of each service priority.

[0070] Specifically, for a service priority, the process of setting a token in the service priority token ring includes:

[0071] ① Determine the token starting unit corresponding to the service priority and the unit of each token spacing corresponding to the service priority in the service priority token ring.

[0072] ② Perform idle detection on the token starting unit and each unit with a token spacing corresponding to the service priority to determine whether a token has been set in the unit.

[0073] ③ Setting a token of the service priority in an idle cell that is not set with a token, and in an idle cell next to a cell that is set with a token.

[0074] For example, Figure 2 As shown, for a completely empty initial service priority token ring, the weight of the general service priority is 5%, then the spacing between each token of the general service priority is 1 / 5%, that is, the token spacing is 20, because the token starting unit corresponding to the general service priority in the initial service priority token ring, that is, the 20th unit starting from the initial pointer position (the pointer position is 0), and every 20 units are set to the general service priority.

[0075] Afterwards, based on the spacing of the important service priority tokens of 1 / 15%, that is, the token spacing is 6 (rounded to an integer value, not rounded to avoid ring crossing), the token corresponding to the important service priority in the initial service priority token ring, that is, the 6th unit starting from the initial pointer position (the pointer position is 0), and the units with a corresponding spacing of 6 units are set as the important service priority. Before setting the corresponding unit service priority token, check whether the corresponding unit has been set. If it has been set, move backward to the next free unit for setting. And set the token of the core service priority in the above manner.

[0076] like Figure 2 The 6th unit should be set as the core service priority token when setting the core service priority token, but because the important service priority token has been set in this unit before, it moves back to the next free unit, that is, the 7th unit to set the core service priority token.

[0077] Finally, all idle cells on the initial service priority token ring are set as tokens of the emergency priority, so that all cells of the initial service priority token ring are filled to obtain the service priority token ring.

[0078] It is understandable that when the size of the service priority token ring is larger, the proportion of each token in the generated service priority token ring will be closer to the preset weight of each service priority, thereby obtaining a more balanced service request extraction.

[0079] In some embodiments of the present application, the process of extracting and responding to the service request from the service request sub-queues with the same service priority in the service request queue in sequence according to the service priority order corresponding to the tokens on the service priority token ring in step S3 is introduced, which may specifically include:

[0080] Step S31, determine the target priority token corresponding to the position of the pointer on the current service priority token ring, where the initial position of the pointer is 0.

[0081] Step S32: Detect whether the service request subqueue in the service request queue that is consistent with the priority of the target priority token is empty.

[0082] Step S33: If the service request sub-queue is not empty, extract and respond to the target service request from the service request sub-queue in the service request queue that has the same priority as the target priority token.

[0083] Step S34: If the service request subqueue is empty or the target service request is extracted and responded to, the position of the pointer is increased by 1, and the process of determining the target priority token corresponding to the position of the pointer on the current service priority token ring is returned.

[0084] Specifically, Figure 2 As shown, the initial position of the pointer is 0. When the pointer is at the initial position, the token at the position of the pointer is the general service priority. At this time, it is detected whether the service request subqueue in the service request queue that is consistent with the priority of the target priority token is empty, that is, whether the general request queue is empty. If the general request queue is not empty, one of the service requests is extracted and responded to according to the first-in-first-out principle, and then the pointer position is increased by 1, and the process of determining the target priority token corresponding to the position of the pointer on the current service priority token ring is returned. If the general request queue is empty, the pointer position is increased by 1, and the process of determining the target priority token corresponding to the position of the pointer on the current service priority token ring is returned.

[0085] Optionally, after the position of the pointer is increased by 1, the method further includes:

[0086] Step S35: If the position of the pointer exceeds the token ring size after being added by 1, the position of the pointer is reset to zero.

[0087] Specifically, if the position of the pointer exceeds the size of the token ring after adding 1, that is, the pointer has already made one circle in the service priority token ring, it is necessary to reset the position of the pointer to zero and perform service request extraction and response again according to the priority order of the tokens on the service priority token ring.

[0088] The request control device of the API gateway provided in an embodiment of the present application is described below. The request control device of the API gateway described below and the request control method of the API gateway described above can be referenced to each other.

[0089] See also Figure 4 , Figure 4 This is a structural block diagram of a request control device of an API gateway disclosed in an embodiment of the present application.

[0090] like Figure 4 As shown, the request control device of the API gateway may include:

[0091] The token ring unit 110 is used to generate a service priority token ring by using a hash balancing method according to a preset token ring size and a priority weight corresponding to each service priority, so that the token hashes of each service priority are evenly distributed on the service priority token ring;

[0092] The request queue unit 120 is used to store all service requests of the API gateway in the form of a service request queue, wherein each service request is stored in a service request subqueue matching the service priority in the service request queue according to its own request priority level value;

[0093] The request extraction unit 130 is used to extract and respond to the service requests from the service request sub-queues with the same service priority in the service request queue in sequence according to the service priority order corresponding to the tokens on the service priority token ring.

[0094] It can be seen from the above technical solution that the request control method, device, equipment and readable storage medium of an API gateway provided in the embodiment of the present application use a hash balancing method to generate a service priority token ring according to the preset token ring size and the priority weight corresponding to each service priority, so that the token hashes of each service priority are evenly distributed on the service priority token ring. Therefore, the proportion of tokens of each service priority on the service priority token ring is the same as the priority weight corresponding to each service priority, and the token hashes of each service priority are evenly distributed on the service priority token ring. All service requests of the API gateway are stored in the form of a service request queue, wherein each of the service requests is stored in a service request subqueue matching the service priority in the service request queue according to its own request priority level value.

[0095] According to the order of service priorities corresponding to the tokens on the service priority token ring, the service requests are extracted and responded to from the service request subqueues with the same service priority in the service request queue in sequence. The order and proportion of the service requests extracted from the service request subqueues corresponding to each service priority are consistent with the order and proportion of the tokens of each service priority on the service priority token ring, and the proportion and order of the service priorities of each service request extracted according to the order of tokens on the service priority token ring are also consistent with the proportion and order of the tokens of each service priority on the service priority token ring. Therefore, service requests of any service priority of the API gateway can obtain stable service responses, thereby effectively balancing the processing efficiency of various service requests, and effectively avoiding the problem in the prior art that a large number of high service priority service requests or slow responses to high service priorities lead to blocking of low service priority service requests.

[0096] Optionally, the token ring unit generates a service priority token ring using a hash balancing method, including:

[0097] The token spacings of the respective service priorities are calculated according to the priority weights corresponding to the respective service priorities;

[0098] According to the service priority order from low to high in importance, the tokens of the respective service priorities are set in the initial service priority token ring in turn until all the cells of the initial service priority token ring are filled, thereby obtaining the service priority token ring, in which the tokens of the same service priority are evenly placed and the spacing between them meets the spacing between tokens of the respective service priorities.

[0099] Optionally, the token ring unit calculates the token spacings of the service priorities according to the priority weights corresponding to the service priorities, including:

[0100] The inverse of the priority weight corresponding to each service priority is determined as each token distance of each service priority.

[0101] Optionally, the token ring unit, for a service priority, sets a token in the service priority token ring, comprising:

[0102] Determine a token start unit corresponding to the service priority and a unit of each token spacing corresponding to the service priority in the service priority token ring;

[0103] Performing idle detection on the token start unit and each unit of the token spacing corresponding to the service priority to determine whether a token has been set in the unit;

[0104] The token of the service priority is set in an idle cell where no token is set, and in an idle cell next to a cell where a token is set.

[0105] Optionally, the request queue unit stores a service request in a matching service request subqueue in the service request queue according to its own request priority level value, including:

[0106] Determine the service request subqueue that matches the service request according to the request priority level value corresponding to the service request and the interval range of each service request subqueue in the service request queue;

[0107] The service request is stored in a matching service request sub-queue in the service request queue.

[0108] Optionally, the request extraction unit sequentially extracts and responds to the service requests from the service request sub-queues with the same service priority in the service request queue, including:

[0109] Determine the target priority token corresponding to the position of the pointer on the current service priority token ring, where the initial position of the pointer is 0;

[0110] Detecting whether a service request subqueue in the service request queue that is consistent with the priority of the target priority token is empty;

[0111] If the service request subqueue is not empty, extracting and responding to the target service request from the service request subqueue in the service request queue that has the same priority as the target priority token;

[0112] If the service request subqueue is empty or the extraction and response to the target service request is completed, the position of the pointer is increased by 1, and the process of determining the target priority token corresponding to the position of the pointer on the current service priority token ring is returned.

[0113] Optionally, the request extraction unit, after adding 1 to the position of the pointer, further includes:

[0114] If the position of the pointer increases by 1 and exceeds the token ring size, the position of the pointer is reset to zero.

[0115] The request control apparatus of the API gateway provided in the embodiment of the present application can be applied to the request control device of the API gateway. Figure 5 The hardware structure diagram of the request control device of the API gateway is shown in FIG. Figure 5 , the hardware structure of the request control device of the API gateway may include: at least one processor 1, at least one communication interface 2, at least one memory 3 and at least one communication bus 4;

[0116] In the embodiment of the present application, the number of the processor 1, the communication interface 2, the memory 3, and the communication bus 4 is at least one, and the processor 1, the communication interface 2, and the memory 3 communicate with each other through the communication bus 4;

[0117] The processor 1 may be a central processing unit CPU, or an application-specific integrated circuit ASIC (Application Specific Integrated Circuit), or one or more integrated circuits configured to implement the embodiments of the present invention, etc.;

[0118] The memory 3 may include a high-speed RAM memory, and may also include a non-volatile memory, such as at least one disk memory;

[0119] The memory stores a program, and the processor can call the program stored in the memory, wherein the program is used to:

[0120] According to the preset token ring size and the priority weight corresponding to each service priority, a service priority token ring is generated by using a hash balancing method so that the token hashes of each service priority are evenly distributed on the service priority token ring;

[0121] All service requests of the API gateway are stored in the form of a service request queue, wherein each service request is stored in a service request subqueue matching the service priority in the service request queue according to its own request priority level value;

[0122] According to the service priority order corresponding to the tokens on the service priority token ring, the service requests are sequentially extracted and responded to from the service request sub-queues with the same service priority in the service request queue.

[0123] Optionally, the detailed functions and extended functions of the program may refer to the above description.

[0124] The embodiment of the present application further provides a readable storage medium, which may store a program suitable for execution by a processor, wherein the program is used to:

[0125] According to the preset token ring size and the priority weight corresponding to each service priority, a service priority token ring is generated by using a hash balancing method so that the token hashes of each service priority are evenly distributed on the service priority token ring;

[0126] All service requests of the API gateway are stored in the form of a service request queue, wherein each service request is stored in a service request subqueue matching the service priority in the service request queue according to its own request priority level value;

[0127] According to the service priority order corresponding to the tokens on the service priority token ring, the service requests are sequentially extracted and responded to from the service request sub-queues with the same service priority in the service request queue.

[0128] Optionally, the detailed functions and extended functions of the program may refer to the above description.

[0129] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including 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, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0130] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0131] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those 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 application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A request control method for an API gateway, characterized in that: include: According to the preset token ring size and the priority weight corresponding to each service priority, a service priority token ring is generated by using a hash balancing method so that the token hashes of each service priority are evenly distributed on the service priority token ring; All service requests of the API gateway are stored in the form of a service request queue, wherein each service request is stored in a service request subqueue matching the service priority in the service request queue according to its own request priority level value; Extracting and responding to the service requests from the service request subqueues with the same service priority in the service request queue in sequence according to the service priority order corresponding to the tokens on the service priority token ring; The service priority token ring is generated by using the hash balancing method, including: The token spacings of the respective service priorities are calculated according to the priority weights corresponding to the respective service priorities; According to the service priority order from low to high in importance, the tokens of the respective service priorities are sequentially set in the initial service priority token ring until all cells of the initial service priority token ring are filled, thereby obtaining the service priority token ring, in which the tokens of the same service priority are evenly placed and the spacing between each of them meets the spacing between the tokens of the respective service priorities; For a service priority, a process of setting a token in the service priority token ring includes: Determine a token start unit corresponding to the service priority and a unit of each token spacing corresponding to the service priority in the service priority token ring; Performing idle detection on the token start unit and each unit of the token spacing corresponding to the service priority to determine whether a token has been set in the unit; The token of the service priority is set in an idle cell where no token is set, and in an idle cell next to a cell where a token is set.

2. The method according to claim 1, characterized in that: The token spacings of the service priorities calculated according to the priority weights corresponding to the service priorities include: The inverse of the priority weight corresponding to each service priority is determined as each token distance of each service priority.

3. The method according to claim 1, characterized in that For a service request, it is stored in the matching service request sub-queue in the service request queue according to its own request priority level value, including: Determine the service request subqueue that matches the service request according to the request priority level value corresponding to the service request and the interval range of each service request subqueue in the service request queue; The service request is stored in a matching service request sub-queue in the service request queue.

4. The method according to claim 1, characterized in that: Sequentially extracting and responding to the service requests from the service request sub-queues with the same service priority in the service request queue, including: Determine the target priority token corresponding to the position of the pointer on the current service priority token ring, where the initial position of the pointer is 0; Detecting whether a service request subqueue in the service request queue that is consistent with the priority of the target priority token is empty; If the service request subqueue is not empty, extracting and responding to the target service request from the service request subqueue in the service request queue that has the same priority as the target priority token; If the service request subqueue is empty or the extraction and response to the target service request is completed, the position of the pointer is increased by 1, and the process of determining the target priority token corresponding to the position of the pointer on the current service priority token ring is returned.

5. The method according to claim 4, characterized in that After the position of the pointer is increased by 1, it also includes: If the position of the pointer increases by 1 and exceeds the token ring size, the position of the pointer is reset to zero.

6. A request control device for an API gateway, characterized in that: include: A token ring unit, used to generate a service priority token ring by using a hash balancing method according to a preset token ring size and a priority weight corresponding to each service priority, so that the token hashes of each service priority are evenly distributed on the service priority token ring; A request queue unit is used to store all service requests of the API gateway in the form of a service request queue, wherein each service request is stored in a service request subqueue matching the service priority in the service request queue according to its own request priority level value; A request extraction unit, configured to extract and respond to the service request from the service request subqueues with the same service priority in the service request queue in sequence according to the service priority order corresponding to the tokens on the service priority token ring; The service priority token ring is generated by using the hash balancing method, including: The token spacings of the respective service priorities are calculated according to the priority weights corresponding to the respective service priorities; According to the service priority order from low to high in importance, the tokens of the respective service priorities are sequentially set in the initial service priority token ring until all cells of the initial service priority token ring are filled, thereby obtaining the service priority token ring, in which the tokens of the same service priority are evenly placed and the spacing between each of them meets the spacing between the tokens of the respective service priorities; For a service priority, a process of setting a token in the service priority token ring includes: Determine a token start unit corresponding to the service priority and a unit of each token spacing corresponding to the service priority in the service priority token ring; Performing idle detection on the token start unit and each unit of the token spacing corresponding to the service priority to determine whether a token has been set in the unit; The token of the service priority is set in an idle cell where no token is set, and in an idle cell next to a cell where a token is set.

7. A request control device for an API gateway, characterized in that: including memory and processor; The memory is used to store programs; The processor is used to execute the program to implement each step of the request control method of the API gateway as described in any one of claims 1-5.

8. A readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, each step of the request control method of the API gateway as described in any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • System for servicing plurality of queues responsive to queue service policy on a service sequence ordered to provide uniform and minimal queue interservice times

    US5870629A