Method, device and equipment for adjusting timeout time of gateway interface

By dynamically calculating the host resources and log information of the gateway and upstream service instances, the timeout time of each service instance is adjusted, which solves the problem of inaccurate timeout time configuration in the existing technology and improves the stability and performance of the system.

CN118827375BActive Publication Date: 2025-12-09CHINA MOBILE M2M +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311600365.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-11-27
Publication Date
2025-12-09
Estimated Expiration
2043-11-27

AI Technical Summary

Technical Problem

Existing technologies do not take into account the resource consumption of upstream service instances and middleware when adjusting the connection establishment timeout and response timeout between the gateway and upstream services. This results in inaccurate response times, which may cause upstream service instances to be overwhelmed or the gateway interface to remain in a timeout state.

Method used

By acquiring real-time host resource information and business request log information of each service instance on the gateway and upstream servers, the interface timeout time of each service instance is dynamically calculated and adjusted, taking into account the specific resource consumption and response of each service instance, thus avoiding inaccuracies caused by unified configuration.

Benefits of technology

The system dynamically adjusts the timeout between the gateway service instance and the upstream server service instance, preventing the service instance from being overwhelmed or the interface from timing out due to excessively large or small timeouts, thus improving the stability and performance of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118827375B_ABST
    Figure CN118827375B_ABST
Patent Text Reader

Abstract

The application discloses a kind of gateway interface's timeout time adjustment method, device and equipment, by real-time acquisition each service instance of the host resource information of the gateway, each service instance of the host resource information of the upstream server and the log information of the service request responded by each service instance of the gateway, and store in preset memory queue;Every first preset time length obtains the host resource information and the log information in recent second preset time length, respectively calculate the established connection timeout time and response timeout time between each service instance of the gateway and each service instance of the upstream server, and correspondingly send to each service instance of the gateway, carry out the timeout configuration of the interface of each service instance of the gateway, using the application, it can be according to the host resource condition and log information in each service instance of gateway and upstream server, dynamically adjust the interface timeout time of each service instance of gateway.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computer, in particular to a method, device and equipment for adjusting timeout time of gateway interface. BACKGROUND

[0002] In the web backend development technology, micro-service technology tends to be popular. The core of micro-service technology is to split a traditional monolithic application into a small micro-service according to business, and then provide a unified service entrance to the outside through a gateway. When a client requests an upstream service, the request first reaches the gateway, the gateway processes the request for authentication, log recording, etc., and then routes the request to the upstream service instance, and the upstream service instance processes the request and then the gateway forwards the response request to the client.

[0003] When the network environment fluctuates, the gateway may establish a connection timeout when forwarding the request to the upstream service instance, resulting in abnormal forwarding of the request. When the host resources of the upstream service instance are occupied by a large amount of requests, the gateway forwards the request to the upstream service instance, and the upstream service instance fails to process the request in time due to insufficient host resources, resulting in a response timeout. When the gateway has a connection timeout and a response timeout, the gateway or the client may trigger a retry mechanism, and then the request volume may increase rapidly, and the host resources of the gateway instance or the upstream service instance may be eventually consumed, resulting in unavailable services and production accidents. Therefore, it is necessary to reasonably set the connection timeout and response timeout of the gateway.

[0004] However, the inventors have found that the prior art at least has the following problems: the prior art mainly has the following disadvantages when adjusting the connection timeout time and the response timeout time between the gateway and the upstream service: the resource consumption of the upstream service instance and the middleware is not considered, the response time of the request is relatively short when the resources are sufficient, and the response timeout time is calculated by increasing or decreasing the average value of the timeout time of all service instances of the gateway, which is not accurate, and may result in an excessively large or small response timeout, which may cause the upstream service instance to be crushed or the gateway interface to be in a timeout state. In addition, the case where multiple service instances are deployed in the gateway and the upstream server is not considered, the interface response timeout time is configured at the server level, and is not specified to each service instance, and if the interface response timeout time of each service instance is the same, the service instance with less host resources may be in an interface response timeout state. SUMMARY

[0005] The purpose of the embodiments of the present application is to provide a method, device and equipment for adjusting the timeout time of the gateway interface, which can dynamically adjust the interface timeout time of each service instance of the gateway according to the host resource situation of each service instance in the gateway and the upstream server and the log information of the response business request.

[0006] To achieve the above object, the embodiment of the present application provides a method for adjusting timeout time of gateway interface, applied to a micro-service system, wherein the micro-service system comprises a gateway and an upstream server, and the gateway and the upstream server each comprise a plurality of service instances; the method comprises:

[0007] acquiring host resource information of each service instance of the gateway, host resource information of each service instance of the upstream server and log information of service requests responded by each service instance of the gateway in real time, and storing the information in a preset memory queue;

[0008] acquiring the host resource information and the log information in the memory queue every first preset time length within a second preset time length;

[0009] calculating, through the host resource information and the log information, connection timeout time and response timeout time between each service instance of the gateway and each service instance of the upstream server;

[0010] sending the connection timeout time and the response timeout time to each service instance of the gateway correspondingly, for timeout configuration of interfaces of each service instance of the gateway.

[0011] As an improvement of the above scheme, the log information comprises identity information of a service instance of the gateway responding to the service request, identity information of a service instance of the upstream server connected by the service instance of the gateway, connection time and response time.

[0012] As an improvement of the above scheme, the calculating, through the host resource information and the log information, connection timeout time and response timeout time between each service instance of the gateway and each service instance of the upstream server comprises:

[0013] calculating, according to the log information, minimum response time, average response time, minimum connection time and average connection time of each service instance of the gateway;

[0014] calculating, according to the host resource information of each service instance of the gateway, host resource consumption value of each service instance of the gateway;

[0015] calculating, according to the host resource information of each service instance of the upstream server, host resource consumption value of each service instance of the upstream server;

[0016] According to the minimum connection establishment time, the average connection establishment time of each service instance of the gateway and the host resource consumption value of each service instance of the gateway, the connection establishment timeout time between each service instance of the gateway and each service instance of the upstream server is calculated respectively;

[0017] According to the minimum response time, the average response time of each service instance of the gateway and the host resource consumption value of each service instance of the upstream server, the response timeout time between each service instance of the gateway and each service instance of the upstream server is calculated respectively.

[0018] As an improvement of the above scheme, the connection establishment timeout time between each service instance of the gateway and each service instance of the upstream server is calculated according to the minimum connection establishment time, the average connection establishment time of each service instance of the gateway and the host resource consumption value of each service instance of the gateway, which comprises:

[0019] The minimum value of the minimum connection establishment time and the average connection establishment time of each service instance of the gateway is determined as the minimum connection establishment time respectively;

[0020] According to the host resource consumption value of each service instance of the gateway, the host resource remaining value of each service instance of the gateway is calculated respectively;

[0021] According to the minimum connection establishment time and the host resource remaining value of each service instance of the gateway, the connection establishment timeout time between each service instance of the gateway and each service instance of the upstream server is calculated respectively.

[0022] As an improvement of the above scheme, the response timeout time between each service instance of the gateway and each service instance of the upstream server is calculated according to the minimum response time, the average response time of each service instance of the gateway and the host resource consumption value of each service instance of the upstream server, which comprises:

[0023] The minimum value of the minimum response time and the average response time of each service instance of the gateway is determined as the minimum response time respectively;

[0024] According to the host resource consumption value of each service instance of the upstream server, the host resource remaining value of each service instance of the upstream server is calculated respectively;

[0025] According to the minimum response time of each service instance of the gateway, the host resource remaining value of each service instance of the upstream server and a preset time coefficient, the response timeout time between each service instance of the gateway and each service instance of the upstream server is calculated respectively.

[0026] As an improvement of the above scheme, the real-time acquisition of the host resource information of each service instance of the gateway, the host resource information of each service instance of the upstream server and the log information of the service request responded by each service instance of the gateway, and the storage in the preset memory queue, comprise:

[0027] Real-time acquisition of messages from each topic queue in the preset message queue to obtain the host resource information of each service instance of the gateway, the host resource information of each service instance of the upstream server and the log information of the service request responded by each service instance of the gateway, and store in the preset memory queue;

[0028] Wherein, the first recording plug-in is arranged on each service instance of the gateway, which is used to record the host resource information of each service instance of the gateway, and send to the first topic queue in the preset message queue corresponding to the service instance of the gateway;

[0029] The second recording plug-in is arranged on each service instance of the gateway, which is used to record the log information of each service instance of the gateway, and send to the second topic queue in the preset message queue corresponding to the service instance of the gateway;

[0030] The third recording plug-in is arranged on each service instance of the upstream server, which is used to record the host resource information of each service instance of the upstream server, and send to the third topic queue in the preset message queue corresponding to the service instance of the upstream server.

[0031] As an improvement of the above scheme, the service update interface is arranged on each service instance of the gateway, which is used to acquire the connection timeout time and the response timeout time, and cache through the cache unit; when the service instance of the gateway responds to the service request, the corresponding connection timeout time and response timeout time can be acquired from the cache unit for timeout configuration.

[0032] As an improvement of the above scheme, the method further comprises:

[0033] Every third preset time length, the log information in the recent fourth preset time length is acquired from the memory queue;

[0034] According to the log information, the number of times that the connection time of each service instance of the gateway is greater than the corresponding configured connection timeout time is counted as the first continuous timeout number; and the number of times that the response time of each service instance of the gateway is greater than the corresponding configured response timeout time is counted as the second continuous timeout number;

[0035] When the first consecutive timeout count exceeds a preset first count threshold, a corresponding first alarm message is generated and reported.

[0036] When the first consecutive timeout count exceeds the preset second count threshold, a corresponding second alarm message is generated and reported.

[0037] This invention also provides a device for adjusting the timeout of a gateway interface, applied to a microservice system. The microservice system includes a gateway and an upstream server, each of which includes multiple service instances. The device includes:

[0038] The information storage module is used to acquire in real time the host resource information of each service instance of the gateway, the host resource information of each service instance of the upstream server, and the log information of the business requests responded to by each service instance of the gateway, and store them in a preset memory queue.

[0039] The information acquisition module is used to acquire the host resource information and the log information within the most recent second preset time period from the memory queue every first preset time period;

[0040] The timeout calculation module is used to calculate the connection establishment timeout and response timeout for each service instance of the gateway using the host resource information and the log information, respectively.

[0041] The timeout sending module is used to send the connection establishment timeout and the response timeout to each service instance of the gateway, and to configure the timeout of the interface of each service instance of the gateway.

[0042] This invention also provides a device for adjusting the timeout of a gateway interface, including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, it implements the method for adjusting the timeout of the gateway interface as described in any of the preceding embodiments.

[0043] Compared with the prior art, the adjustment method, device and equipment for the timeout time of the gateway interface disclosed by the application, by acquiring the log information and host resource information of the response service request of each service instance of the gateway and each service instance of the upstream server in the recent period of time every interval, and calculating the appropriate connection establishment timeout time and response timeout time between each service instance interface of the gateway and each service instance of the upstream server, the connection establishment timeout time and response timeout time of the service instance of the gateway to the service instance of the corresponding different upstream server are dynamically adjusted every time the service request is responded. The log information and host resource information of each service instance of the gateway and the upstream server are considered, and the traditional server level timeout time configuration is changed to the configuration of each service instance interface, the timeout time set by different service instances of the gateway and different service instances of the upstream server is different, which avoids the inaccurate situation caused by the same timeout time configuration of each service instance of the gateway, avoids the situation that the upstream service instance is collapsed or the gateway interface is always in the timeout state due to the too large or too small timeout time, and also avoids the situation that the service instance with less host resource is always in the interface response timeout state. BRIEF DESCRIPTION OF DRAWINGS

[0044] Figure 1 is a flow diagram of the adjustment method for the timeout time of the gateway interface provided by the embodiment of the application;

[0045] Figure 2 is a structure diagram of the micro-service system in the embodiment of the application;

[0046] Figure 3 is a structure diagram of the adjustment device for the timeout time of the gateway interface provided by the embodiment of the application;

[0047] Figure 4 is a structure diagram of the adjustment equipment for the timeout time of the gateway interface provided by the embodiment of the application. DETAILED DESCRIPTION

[0048] The technical solutions in the embodiments of the application will be described clearly and completely below with reference to the drawings in the embodiments of the application. Obviously, the described embodiments are only part of the embodiments of the application, rather than all the embodiments of the application. Based on the embodiments in the application, all other embodiments obtained by those skilled in the art without creative labor fall within the protection scope of the application.

[0049] In the description of the present application, it needs to be understood that the terms "center", "upper", "lower", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inner", "outer" and the like indicate the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present application and simplifying the description, and do not indicate or imply that the device or element referred to must have a particular orientation, be constructed and operated in a particular orientation, and therefore cannot be understood as a limitation of the present application.

[0050] The terms "first", "second" are only for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the technical features indicated. Therefore, the features defined with "first", "second" can explicitly or implicitly include one or more of the features. In the description of the present application, unless otherwise specified, the meaning of "a plurality of" is two or more.

[0051] In the description of the present application, it needs to be explained that unless otherwise explicitly specified and limited, the terms "mounting", "connecting", "connecting" should be understood broadly, for example, it can be fixedly connected, or it can be detachably connected, or integrally connected; it can be mechanically connected, or it can be electrically connected; it can be directly connected, or it can be indirectly connected through an intermediate medium, or it can be the communication inside two elements. For those skilled in the art, the specific meaning of the above terms in the present application can be understood according to the specific circumstances.

[0052] Referring to Figure 1 It is a flowchart of the adjustment method of the timeout time of the gateway interface provided by the embodiment of the present application. The embodiment of the present application provides an adjustment method of the timeout time of the gateway interface. The adjustment method is applied to a micro-service system. The micro-service system includes a gateway and an upstream server. The gateway and the upstream server respectively include a plurality of service instances.

[0053] The adjustment method of the timeout time of the gateway interface specifically includes steps S11 to S14:

[0054] S11, real-time acquisition of host resource information of each service instance of the gateway, host resource information of each service instance of the upstream server and log information of service requests responded by each service instance of the gateway, and storage in a preset memory queue;

[0055] S12, every first preset time length from the memory queue to acquire the host resource information and the log information in the last second preset time length;

[0056] S13, calculate the connection establishment timeout time and the response timeout time between each service instance of the gateway and each service instance of the upstream server respectively through the host resource information and the log information;

[0057] S14, send the connection establishment timeout time and the response timeout time to each service instance of the gateway correspondingly, for timeout configuration of the interface of each service instance of the gateway.

[0058] It should be noted that, referring to Figure 2 , which is a structural schematic diagram of the micro-service system in the embodiment of the application. When the client requests the upstream server, the business request will first arrive at the gateway, and the gateway will route the business request to the upstream server after authentication and log recording of the request and other processing. After the upstream server is processed, the gateway forwards the response request to the client.

[0059] The micro-service system includes a plurality of upstream servers, for example Figure 2 Service A, service B and service C in the micro-service system, the upstream server further includes a plurality of service instances 1-n, and the gateway includes a plurality of service instances 1-n. In addition, the micro-service system further includes a registration center. When the client initiates a business request to the upstream server, the gateway layer obtains the service instance list of the current request upstream server from the registration center after the business request arrives at the gateway layer, selects a service instance address in the upstream server from the service instance list according to the load balancing strategy configured by the gateway, and completes the forwarding of the business request. The micro-service system further includes a configuration center for unified management of configuration information.

[0060] Preferably, the gateway is an apisix gateway.

[0061] In actual application, the connection establishment timeout time and the response timeout time need to be set for the service instance of the gateway. The connection establishment timeout time refers to when the client makes a business request, the gateway establishes a connection with the upstream server when forwarding the business request. If the upstream server cannot respond to the connection request, the client needs to wait for the connection establishment timeout time before returning the error information. Similarly, after the gateway establishes a connection with the upstream server, the business request is forwarded to the upstream server. If the upstream server cannot respond to the business request, the client needs to wait for the response timeout time before returning the error information. Reasonable setting of the connection timeout time can improve the performance and stability of the application program.

[0062] In the embodiment of the present application, in order to realize the setting of the connection establishment timeout and the response timeout of the service instance of the gateway, each service instance in the computing service is set to execute the timeout adjustment method of the gateway interface of the embodiment of the present application. Specifically, the computing service obtains the host resource information of each service instance of the gateway, the host resource information of each service instance of the upstream server and the log information of the service request responded by each service instance of the gateway in real time, and stores them in a preset memory queue.

[0063] The first preset time length is set to 1 minute and the second preset time length is set to 15 minutes. In the process of adjusting the timeout of the service instance of the gateway, the computing service obtains the host resource information and the log information in the last 15 minutes from the memory queue every 1 minute, calculates the corresponding connection establishment timeout and response timeout between each service instance of the gateway and different service instances of the upstream server, and sends the connection establishment timeout and the response timeout to each service instance of the gateway. When any service instance of the gateway receives a service request, the service instance of the upstream server to which the service request needs to be forwarded is determined, and the interface timeout is configured according to the connection establishment timeout and the response timeout corresponding to the service instance of the gateway and the service instance of the upstream server.

[0064] By using the technical means of the embodiment of the present application, the computing service cluster is realized. Each computing service instance in the cluster obtains the log information and the host resource information of the service request responded by each service instance of the gateway and each service instance of the upstream server in the last period of time every certain time length, and calculates the appropriate connection establishment timeout and response timeout between each service instance interface of the gateway and each service instance of the upstream server, so as to realize the dynamic adjustment of the connection establishment timeout and the response timeout of each service instance of the gateway when responding to a service request and the connection establishment timeout and the response timeout of the corresponding different service instance of the upstream server. The embodiment of the present application considers the log information and the host resource information of each service instance of the gateway and the upstream server, and changes the traditional server-level timeout configuration to the configuration of each service instance interface. The timeout set by different service instances of the gateway and different service instances of the upstream server is different, which avoids the inaccurate situation caused by the same timeout configuration of each service instance of the gateway, avoids the situation that the upstream service instance is collapsed or the gateway interface is always in the timeout state due to the too large or too small timeout, and also avoids the situation that the service instance with less host resource is always in the interface response timeout.

[0065] As a preferred embodiment, the embodiment of the present application is further implemented on the basis of the above-mentioned embodiment, wherein the log information comprises identity information of a service instance of the gateway responding to the service request, identity information of a service instance of an upstream server connected to the service instance of the gateway, connection establishment time and response time. Optionally, the log information further comprises service request address and other information.

[0066] As a preferred embodiment, the embodiment of the present application optimizes the calculation means of the connection establishment timeout time and the response timeout time, and step S13, i.e., the calculation of the connection establishment timeout time and the response timeout time between each service instance of the gateway and each service instance of the upstream server based on the host resource information and the log information, comprises steps S131 to S135.

[0067] S131, calculating minimum response time, average response time, minimum connection establishment time and average connection establishment time of each service instance of the gateway according to the log information;

[0068] S132, calculating host resource consumption value of each service instance of the gateway according to the host resource information of each service instance of the gateway;

[0069] S133, calculating host resource consumption value of each service instance of the upstream server according to the host resource information of each service instance of the upstream server;

[0070] S134, calculating connection establishment timeout time between each service instance of the gateway and each service instance of the upstream server according to the minimum connection establishment time, the average connection establishment time of each service instance of the gateway and the host resource consumption value of each service instance of the gateway;

[0071] S135, calculating response timeout time between each service instance of the gateway and each service instance of the upstream server according to the minimum response time, the average response time of each service instance of the gateway and the host resource consumption value of each service instance of the upstream server.

[0072] In the embodiment of the present application, according to the log information, the id identity information of the service instance of the upstream server to which each service instance of the gateway is correspondingly forwarded when responding to a service request, and the connection establishment time and the response time in response to the service request are determined. For any service instance of the gateway, according to the obtained log information of the service request responded within 15 minutes, the minimum response time MRT(i) in all response times is determined, and the average response time ART(i) is calculated by averaging all response times. Similarly, the minimum connection establishment time MCT(i) in all connection establishment times is determined, and the average connection establishment time ACT(i) is calculated by averaging all connection establishment times. Wherein, n represents the i th service instance of the gateway, i = 1, 2, 3…n; n is the number of service instances of the gateway.

[0073] For the host resource information of any service instance of the gateway, the host resource consumption value AXR(i) of the service instance is calculated, and the host resource consumption value = the load of the system in the last 1 minute / the number of cpu cores of the current host. Therefore, the host resource consumption value can be simplified to a decimal number in [0, 1), and the larger the value is, the less the available resources are.

[0074] For the host resource information of any service instance of the upstream server, the host resource consumption value BSR(j) of the service instance is calculated, and the host resource consumption value = the load of the system in the last 1 minute / the number of cpu cores of the current host. Therefore, the host resource consumption value can be simplified to a decimal number in [0, 1), and the larger the value is, the less the available resources are. Wherein, j represents the j th service instance of the upstream server, j = 1, 2, 3…m; m is the number of service instances of the upstream server.

[0075] According to the above data, the connection establishment timeout time and the response timeout time between the i th service instance of the gateway and the j th service instance of the upstream server are calculated respectively.

[0076] Preferably, step S134, that is, the connection establishment timeout time between each service instance of the gateway and each service instance of the upstream server is calculated according to the minimum connection establishment time of each service instance of the gateway, the average connection establishment time of each service instance of the gateway, and the host resource consumption value of each service instance of the gateway, comprising:

[0077] The minimum value of the minimum connection establishment time and the average connection establishment time of each service instance of the gateway is determined as the minimum connection establishment time;

[0078] According to the host resource consumption value of each service instance of the gateway, the host resource remaining value of each service instance of the gateway is calculated respectively;

[0079] According to the minimum connection establishment time of each service instance of the gateway and the host resource remaining value, a connection establishment timeout time between each service instance of the gateway and each service instance of the upstream server is calculated respectively.

[0080] That is, the calculation formula of the connection establishment timeout time between the i th service instance of the gateway and the j th service instance of the upstream server is as follows:

[0081] A(i,j) = min(MCT(i), ACT(i)) * (1-AXR(i)).

[0082] Preferably, step S135, that is, the response timeout time between each service instance of the gateway and each service instance of the upstream server is calculated according to the minimum response time, the average response time of each service instance of the gateway and the host resource consumption value of each service instance of the upstream server respectively, comprises:

[0083] The minimum value of the minimum response time and the average response time of each service instance of the gateway is determined as the minimum response time respectively;

[0084] According to the host resource consumption value of each service instance of the upstream server, a host resource remaining value of each service instance of the upstream server is calculated respectively;

[0085] According to the minimum response time of each service instance of the gateway, the host resource remaining value of each service instance of the upstream server and a preset time coefficient, a response timeout time between each service instance of the gateway and each service instance of the upstream server is calculated respectively.

[0086] For example, the time coefficient is set as 2, and the calculation formula of the response timeout time between the i th service instance of the gateway and the j th service instance of the upstream server is as follows:

[0087] B(i,j) = 2*min(MRT(i), ART(i)) * (1-BSR(j)).

[0088] By using the technical means of the embodiment of the present application, the log information and the host resource information of each service instance of the gateway and the upstream server are considered, and the traditional server level timeout time configuration is changed and is placed in the configuration of each service instance interface. The timeout time set by different service instances of the gateway and different service instances of the upstream server is different, and the problem that the connection establishment timeout time and the response timeout time of different gateway service instance interfaces are not suitable due to the difference of host resources is solved.

[0089] As a preferred embodiment, the embodiment of the present application is further implemented on the basis of any of the above embodiments, and step S11, that is, the real-time acquisition of the host resource information of each service instance of the gateway, the host resource information of each service instance of the upstream server, and the log information of the service request responded by each service instance of the gateway, and the storage in the preset memory queue, comprises the following steps:

[0090] S111, real-time acquisition of messages from each topic queue in the preset message queue to obtain the host resource information of each service instance of the gateway, the host resource information of each service instance of the upstream server, and the log information of the service request responded by each service instance of the gateway, and store in the preset memory queue;

[0091] Among them, the first recording plug-in is arranged on each service instance of the gateway, which is used for recording the host resource information of each service instance of the gateway and sending to the first topic queue in the preset message queue corresponding to the service instance of the gateway;

[0092] The second recording plug-in is arranged on each service instance of the gateway, which is used for recording the log information of each service instance of the gateway and sending to the second topic queue in the preset message queue corresponding to the service instance of the gateway;

[0093] The third recording plug-in is arranged on each service instance of the upstream server, which is used for recording the host resource information of each service instance of the upstream server and sending to the third topic queue in the preset message queue corresponding to the service instance of the upstream server.

[0094] In the embodiment of the present application, referring to Figure 2 , the micro-service system further comprises a message queue and a columnar database.

[0095] Each service instance of the apisix gateway needs to implement a plug-in (first recording plug-in) for recording host resource information. The first recording plug-in can directly record the resource data of the host. Every certain time interval, for example, one minute, the resource data of the host is sent to the topic queue (first topic queue) of the message queue through the message queue plug-in. Each service instance of the apisix gateway has an independent message queue topic name. The naming rule of the topic is apisix_load_instanceid. The instanceid is automatically allocated when the gateway is started for the first time and is not repeated. It will not change thereafter.

[0096] Each service instance of the apisix gateway needs to start a log plug-in (second record plug-in), which records the apisix gateway instance id, upstream service instance id, request address, connection establishment time, response time, connection establishment timeout, response timeout of each business request. Finally, it is sent to the topic queue (second topic queue) of the message queue through the message queue plug-in. The naming rule of the topic is apisix_interface_request_instanceid.

[0097] Each service instance of the upstream server needs to implement a plug-in (third record plug-in) for recording host resource information. The third record plug-in can directly record the resource data of the host, and every certain time interval, for example, one minute, the resource data of the host is sent to the topic queue (third topic queue) of the message queue through the message queue plug-in. Each upstream service instance has a separate message queue topic name. The naming rule of the topic is business_service_load_instanceid. The instance id is automatically assigned when the upstream service instance is started for the first time and is not repeated. It will not change afterwards.

[0098] The computing service is deployed in a cluster and subscribes to the data in the topic queues with the topic names apisix_load_instanceid, apisix_interface_request_instanceid, and business_service_load_instanceid in the message queue. Each computing service instance will share the topic consumption tasks and will not be subscribed repeatedly. When the computing service instance receives a message from the topic queue of the message queue, the message will be temporarily cached in the memory queue of the computing service instance. The computing service instance will check the number of data in the memory queue at regular intervals. If the number of data exceeds the number of data for batch writing, the data will be taken from the memory queue and batch written into the tables t_apisix_load_record, t_apisix_interface_request_record, t_business_service_load_record, etc. in the columnar database. The above tables store data by day.

[0099] By using the technical means of the embodiment of the application, the host resource information and log information of different service instances are acquired and classified through the message queue, so that the computing service can accurately calculate the corresponding timeout time according to the information acquired from different topic queues.

[0100] As a preferred embodiment, the embodiment of the application is further implemented on the basis of any of the above embodiments, each service instance of the gateway is provided with a service update interface, the service update interface is used to obtain the connection timeout time and the response timeout time, and the connection timeout time and the response timeout time are cached through the cache unit; when the service instance of the gateway responds to a service request, the corresponding connection timeout time and response timeout time can be obtained from the cache unit for timeout configuration.

[0101] In the embodiment of the application, each apisix gateway instance needs to cache the connection timeout time and the response timeout time of the service instance interface of each gateway and the service instance of the upstream server, and provide an update interface to support real-time updating. When the apisix gateway instance starts to forward a service request, the connection timeout time and the response timeout time between the gateway instance interface and the upstream service instance are obtained from the cache unit and set to the request body, and then the routing forwarding is started. Because the apisix gateway has provided an interface to update service information, but the update range of the interface is the service level and has not been sunk to the specific service instance. Therefore, the latest source code of apisix needs to be downloaded, and the service update interface and the timeout configuration setting during routing forwarding are modified.

[0102] As an example, the steps of modifying the service update interface are as follows: find the services.lua file in the apisix\admin\directory in the apisix source code, locate the _M.put(id,conf) function, the parameter id of the function is currently the service id, so a function parameter of the service instance id needs to be added to mark the service instance. In the function, the logic of judging whether the service instance id is empty is added, if not empty, the service instance id+current request address url is used as the key, and the timeout configuration conf is used as the value and stored in the etcd.

[0103] The steps of modifying the timeout configuration during routing forwarding are as follows: find the balancer.lua file in the apisix directory, locate the set_current_peer(server,ctx) function, the logic of the function is to select a service instance from the current service, so the logic of setting the timeout configuration of the service instance can be added in the function, the connection timeout time and the response timeout time configuration of the service instance are obtained from the etcd according to the service instance id+current request address url, if the obtained value is empty, no setting is performed. If the obtained value is not empty, the value is set to the request context ctx. In the subsequent forwarding process, when the apisix gateway instance establishes a tcp connection with the service instance, the connection timeout time and the response timeout time configuration in the request context ctx are used.

[0104] Each computing service instance queries the recent 15-minute request log information and host resource information of the currently subscribed apisix gateway instance and upstream service instance every 1 minute interval, and calculates the appropriate connection establishment timeout time and response timeout time of the apisix gateway instance interface. After the calculation is completed, the service update interface is called, and the interface address is / apisix / admin / services / service id / service instance id. The service id and service instance id can be obtained by calling the / apisix / admin / services interface after the service and service instance are newly created. The connection establishment timeout time and response timeout time configuration of each service instance interface of the apisix gateway are dynamically updated.

[0105] By adopting the technical means of the embodiment of the application, the timeout time is cached and configured by providing a service update interface on each service instance of the gateway, so that the timeout time of each service instance interface of the gateway and the service instance of the upstream server is configured according to different business requests.

[0106] As a preferred embodiment, the method further comprises steps S15 to S18:

[0107] S15, the log information in the recent fourth preset time length is obtained from the memory queue every third preset time length;

[0108] S16, according to the log information, the number of times that each service instance of the gateway continuously appears the connection establishment time greater than the corresponding configured connection establishment timeout time is counted as a first continuous timeout number, and the number of times that each service instance of the gateway continuously appears the response time greater than the corresponding configured response timeout time is counted as a second continuous timeout number;

[0109] S17, when the first continuous timeout number is greater than a preset first number threshold, corresponding first alarm information is generated and reported; when the first continuous timeout number is greater than a preset second number threshold, corresponding second alarm information is generated and reported.

[0110] As an example, the third preset time length is set to 5 minutes, the fourth preset time length is set to 1 hour, and the first number threshold and the second number threshold are both set to 10 times. Each computing service instance scans the log information of each service instance of the gateway responding to a business request in the recent 1 hour every 5 minutes, filters out the service instance interface information with a continuous timeout number greater than 10 times from the log information, and reports the timeout service instance interface information to the alarm center through an alarm information reporting interface provided by the alarm center. When the alarm center receives the interface timeout alarm, the person in charge of the interface is found according to the interface information, and the person in charge is notified by email or short message.

[0111] By means of the technical means of the embodiment of the present application, when the service instance interface of a gateway is in a timeout state for a long time, the interface information is timely reported to an alarm information and notified to a person in charge, so that the response time and host resource are amplified or reduced to avoid production accidents. Meanwhile, the interface timeout alarm information is needed to positively promote the optimization of the interface timeout problem.

[0112] Referring to Figure 3 is a structural schematic diagram of a timeout time adjustment device of a gateway interface provided by the embodiment of the present application. The embodiment of the present application further provides a timeout time adjustment device 20 of a gateway interface, which is applied to a micro-service system. The micro-service system includes a gateway and an upstream server. The gateway and the upstream server respectively include a plurality of service instances. The device includes:

[0113] an information storage module 21, configured to acquire host resource information of each service instance of the gateway, host resource information of each service instance of the upstream server and log information of a business request responded by each service instance of the gateway in real time, and store the information in a preset memory queue;

[0114] an information acquisition module 22, configured to acquire the host resource information and the log information in a second preset time period from the memory queue every first preset time period;

[0115] a timeout time calculation module 23, configured to calculate an establishment connection timeout time and a response timeout time of each service instance of the gateway respectively by means of the host resource information and the log information;

[0116] a timeout time sending module 24, configured to send the establishment connection timeout time and the response timeout time to each service instance of the gateway respectively, so as to perform timeout configuration of an interface of each service instance of the gateway.

[0117] The technical means of the embodiment of the application realizes the calculation of the service cluster, each calculation service instance in the cluster acquires the log information of the response to the business request and the host resource information of each service instance of the gateway and each service instance of the upstream server in the recent period of time every interval, and calculates the appropriate connection timeout time and response timeout time between each service instance interface of the gateway and each service instance of the upstream server, thereby realizing the dynamic adjustment of the connection timeout time and the response timeout time between each service instance of the gateway and each service instance of the corresponding different upstream server when responding to the business request each time. The application considers the log information and the host resource information of each service instance of the gateway and the upstream server, and changes the traditional server-level timeout time configuration, and downgrades to the configuration of each service instance interface. The timeout time set by each service instance of the gateway and each service instance of the upstream server is different, which avoids the inaccurate situation caused by the same timeout time configuration of each service instance of the gateway, avoids the situation that the upstream service instance is collapsed or the gateway interface is always in the timeout state due to the too large or too small timeout time, and also avoids the situation that the service instance with less host resource is always in the interface response timeout state.

[0118] Preferably, the log information comprises: identity information of the service instance of the gateway responding to the business request, identity information of the service instance of the upstream server connected by the service instance of the gateway, connection time and response time.

[0119] As a preferred implementation, the timeout time calculation module 23 is specifically used for:

[0120] According to the log information, the minimum response time, the average response time, the minimum connection time and the average connection time of each service instance of the gateway are calculated.

[0121] According to the host resource information of each service instance of the gateway, the host resource consumption value of each service instance of the gateway is calculated.

[0122] According to the host resource information of each service instance of the upstream server, the host resource consumption value of each service instance of the upstream server is calculated.

[0123] According to the minimum connection time, the average connection time of each service instance of the gateway and the host resource consumption value of each service instance of the gateway, the connection timeout time between each service instance of the gateway and each service instance of the upstream server is calculated.

[0124] According to the minimum response time, the average response time of each service instance of the gateway and the host resource consumption value of each service instance of the upstream server, the response timeout time between each service instance of the gateway and each service instance of the upstream server is calculated respectively.

[0125] As a preferred implementation, the connection establishment timeout time between each service instance of the gateway and each service instance of the upstream server is calculated according to the minimum connection establishment time, the average connection establishment time of each service instance of the gateway and the host resource consumption value of each service instance of the gateway, respectively, including:

[0126] The minimum value of the minimum connection establishment time and the average connection establishment time of each service instance of the gateway is determined as the minimum connection establishment time respectively;

[0127] According to the host resource consumption value of each service instance of the gateway, the host resource remaining value of each service instance of the gateway is calculated respectively;

[0128] According to the minimum connection establishment time and the host resource remaining value of each service instance of the gateway, the connection establishment timeout time between each service instance of the gateway and each service instance of the upstream server is calculated respectively.

[0129] As a preferred implementation, the response timeout time between each service instance of the gateway and each service instance of the upstream server is calculated according to the minimum response time, the average response time of each service instance of the gateway and the host resource consumption value of each service instance of the upstream server, respectively, including:

[0130] The minimum value of the minimum response time and the average response time of each service instance of the gateway is determined as the minimum response time respectively;

[0131] According to the host resource consumption value of each service instance of the upstream server, the host resource remaining value of each service instance of the upstream server is calculated respectively;

[0132] According to the minimum response time of each service instance of the gateway, the host resource remaining value of each service instance of the upstream server and a preset time coefficient, the response timeout time between each service instance of the gateway and each service instance of the upstream server is calculated respectively.

[0133] As a preferred implementation, the information storage module 21 is specifically used for:

[0134] acquire, in real time, messages from each topic queue in a preset message queue to obtain host resource information of each service instance of the gateway, host resource information of each service instance of the upstream server, and log information of a service request responded by each service instance of the gateway, and store in a preset memory queue;

[0135] The first record plug-in is arranged on each service instance of the gateway, and is configured to record the host resource information of each service instance of the gateway and send to a first topic queue corresponding to the service instance of the gateway in the preset message queue.

[0136] The second record plug-in is arranged on each service instance of the gateway, and is configured to record the log information of each service instance of the gateway and send to a second topic queue corresponding to the service instance of the gateway in the preset message queue.

[0137] The third record plug-in is arranged on each service instance of the upstream server, and is configured to record the host resource information of each service instance of the upstream server and send to a third topic queue corresponding to the service instance of the upstream server in the preset message queue.

[0138] As a preferred implementation, the service update interface is arranged on each service instance of the gateway, and is configured to acquire the connection establishment timeout time and the response timeout time and cache the same by the cache unit; when the service instance of the gateway responds to a service request, the corresponding connection establishment timeout time and the response timeout time can be acquired from the cache unit for timeout configuration.

[0139] As a preferred implementation, the device further comprises an alarm module, and the alarm module is specifically configured to:

[0140] acquire the log information in the memory queue every third preset time length within a fourth preset time length;

[0141] According to the log information, the number of times that the connection establishment time of each service instance of the gateway is greater than the corresponding configured connection establishment timeout time in succession is counted as a first continuous timeout number, and the number of times that the response time of each service instance of the gateway is greater than the corresponding configured response timeout time in succession is counted as a second continuous timeout number.

[0142] When the first continuous timeout number is greater than a preset first number threshold, corresponding first alarm information is generated and reported.

[0143] When the first continuous timeout number is greater than a preset second number threshold, corresponding second alarm information is generated and reported.

[0144] Referring to Figure 4 is a structural schematic diagram of a gateway interface timeout time adjustment device provided by an embodiment of the present application. The embodiment of the present application also provides a gateway interface timeout time adjustment device 30, which comprises a processor 31, a memory 32, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, the gateway interface timeout time adjustment method of any one of the above embodiments is implemented.

[0145] It should be noted that the gateway interface timeout time adjustment device provided by the embodiment of the present application is used to execute all flow steps of the gateway interface timeout time adjustment method of the above embodiment. The working principles and beneficial effects of the two are one-to-one correspondence, and thus will not be repeated.

[0146] The embodiment of the present application also provides a computer readable storage medium, which comprises a stored computer program. When the computer program runs, the device where the computer readable storage medium is located executes the gateway interface timeout time adjustment method of any one of the above embodiments.

[0147] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by a computer program instructing related hardware. The program can be stored in a computer readable storage medium. When the program is executed, the program can include the processes of the above-mentioned embodiment methods. The storage medium can be a magnetic disc, an optical disc, a read-only memory (ROM), a random access memory (RAM), or the like.

[0148] The above is the preferred embodiment of the present application. It should be noted that those skilled in the art can make several improvements and refinements without departing from the principles of the present application. These improvements and refinements are also considered to be within the protection scope of the present application.

Claims

1. A method for adjusting the timeout period of a gateway interface, characterized in that, Applied to a microservice system, the microservice system including a gateway and an upstream server, the gateway and the upstream server each including multiple service instances; the method includes: The host resource information of each service instance of the gateway, the host resource information of each service instance of the upstream server, and the log information of the business requests responded to by each service instance of the gateway are obtained in real time and stored in a preset memory queue. Every first preset time interval, retrieve the host resource information and log information from the memory queue within the most recent second preset time interval; Using the host resource information and the log information, calculate the connection establishment timeout and response timeout between each service instance of the gateway and each service instance of the upstream server; The connection establishment timeout time and the response timeout time are sent to each service instance of the gateway to configure the timeout of the interface of each service instance of the gateway. The step of calculating the connection establishment timeout and response timeout between each service instance of the gateway and each service instance of the upstream server using the host resource information and the log information includes: Based on the log information, calculate the minimum response time, average response time, minimum connection establishment time, and average connection establishment time for each service instance of the gateway; Based on the host resource information of each service instance of the gateway, calculate the host resource consumption value of each service instance of the gateway; Based on the host resource information of each service instance of the upstream server, calculate the host resource consumption value of each service instance of the upstream server. Based on the minimum connection establishment time, average connection establishment time, and host resource consumption value of each service instance of the gateway, calculate the connection establishment timeout between each service instance of the gateway and each service instance of the upstream server. Based on the minimum response time, average response time, and host resource consumption value of each service instance of the gateway, the response timeout between each service instance of the gateway and each service instance of the upstream server is calculated.

2. The method for adjusting the timeout period of the gateway interface as described in claim 1, characterized in that, The log information includes: the identity information of the service instance of the gateway responding to the service request, the identity information of the service instance of the upstream server to which the service instance of the gateway is connected, the connection establishment time, and the response time.

3. The method for adjusting the timeout period of the gateway interface as described in claim 1, characterized in that, The step of calculating the connection establishment timeout between each service instance of the gateway and each service instance of the upstream server based on the minimum connection establishment time, average connection establishment time, and host resource consumption value of each service instance of the gateway includes: The minimum connection establishment time and the minimum connection establishment time of each service instance of the gateway are determined as the minimum connection establishment time. Based on the host resource consumption value of each service instance of the gateway, calculate the remaining host resource value of each service instance of the gateway. Based on the minimum connection establishment time and the remaining host resources of each service instance of the gateway, calculate the connection establishment timeout between each service instance of the gateway and each service instance of the upstream server.

4. The method for adjusting the timeout period of the gateway interface as described in claim 1, characterized in that, The step of calculating the response timeout between each service instance of the gateway and each service instance of the upstream server based on the minimum response time, average response time, and host resource consumption value of each service instance of the upstream server includes: The minimum response time is determined as the minimum response time for each service instance of the gateway. Based on the host resource consumption value of each service instance of the upstream server, calculate the remaining host resource value of each service instance of the upstream server. Based on the minimum response time of each service instance of the gateway, the remaining host resources of each service instance of the upstream server, and a preset time coefficient, the response timeout between each service instance of the gateway and each service instance of the upstream server is calculated respectively.

5. The method for adjusting the timeout period of a gateway interface as described in any one of claims 1 to 4, characterized in that, The real-time acquisition of host resource information of each service instance of the gateway, host resource information of each service instance of the upstream server, and log information of business requests responded to by each service instance of the gateway, and storage of these in a preset memory queue, includes: Messages are retrieved in real time from various topic queues in the preset message queue to obtain host resource information of each service instance of the gateway, host resource information of each service instance of the upstream server, and log information of business requests responded to by each service instance of the gateway, and stored in the preset memory queue. Each service instance of the gateway is equipped with a first recording plugin, which is used to record the host resource information of each service instance of the gateway and send it to the first topic queue corresponding to the service instance of the gateway in the preset message queue. Each service instance of the gateway is equipped with a second recording plugin, which is used to record the log information of each service instance of the gateway and send it to the second topic queue corresponding to the service instance of the gateway in the preset message queue; Each service instance of the upstream server is equipped with a third recording plugin, which is used to record the host resource information of each service instance of the upstream server and send it to the third topic queue corresponding to the service instance of the upstream server in the preset message queue.

6. The method for adjusting the timeout period of a gateway interface as described in any one of claims 1 to 4, characterized in that, Each service instance of the gateway is equipped with a service update interface, which is used to obtain the connection establishment timeout and the response timeout, and cache them through a caching unit. When the service instance of the gateway responds to a business request, it can obtain the corresponding connection establishment timeout time and response timeout time from the cache unit to configure the timeout.

7. The method for adjusting the timeout period of the gateway interface as described in claim 2, characterized in that, The method further includes: Every third preset time interval, the log information within the most recent fourth preset time interval is retrieved from the memory queue; Based on the log information, the number of times each service instance of the gateway experiences a connection establishment time that is greater than the corresponding configured connection establishment timeout is counted, which is taken as the first consecutive timeout count; and the number of times each service instance of the gateway experiences a response time that is greater than the corresponding configured response timeout is counted, which is taken as the second consecutive timeout count. When the first consecutive timeout count exceeds a preset first count threshold, a corresponding first alarm message is generated and reported. When the first consecutive timeout count exceeds the preset second count threshold, a corresponding second alarm message is generated and reported.

8. A device for adjusting the timeout period of a gateway interface, characterized in that, Applied to a microservice system, the microservice system including a gateway and an upstream server, the gateway and the upstream server each including multiple service instances; the device includes: The information storage module is used to acquire in real time the host resource information of each service instance of the gateway, the host resource information of each service instance of the upstream server, and the log information of the business requests responded to by each service instance of the gateway, and store them in a preset memory queue. The information acquisition module is used to acquire the host resource information and the log information within the most recent second preset time period from the memory queue every first preset time period; The timeout calculation module is used to calculate the connection establishment timeout and response timeout for each service instance of the gateway using the host resource information and the log information, respectively. The timeout sending module is used to send the connection establishment timeout and the response timeout to each service instance of the gateway, and to configure the timeout of the interface of each service instance of the gateway. The timeout calculation module is specifically used for: Based on the log information, calculate the minimum response time, average response time, minimum connection establishment time, and average connection establishment time for each service instance of the gateway; Based on the host resource information of each service instance of the gateway, calculate the host resource consumption value of each service instance of the gateway; Based on the host resource information of each service instance of the upstream server, calculate the host resource consumption value of each service instance of the upstream server. Based on the minimum connection establishment time, average connection establishment time, and host resource consumption value of each service instance of the gateway, calculate the connection establishment timeout between each service instance of the gateway and each service instance of the upstream server. Based on the minimum response time, average response time, and host resource consumption value of each service instance of the gateway, the response timeout between each service instance of the gateway and each service instance of the upstream server is calculated.

9. A device for adjusting the timeout period of a gateway interface, characterized in that, It includes a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor, when executing the computer program, implements the method for adjusting the timeout of the gateway interface as described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • A service background and a service request asynchronous processing method thereof

    CN109819021A

  • Network element timer management method and system based on micro service, and related equipment

    CN115250230A