Method and system for proxy gateway timeout forwarding
Through the proxy gateway, differentiating processing policies based on request type, and using the redis cache and synchronization retry mechanism, the problem of request timeout in the service cluster is solved, improving the response speed and user experience.
Patent Information
- Application Number
- CN202211665036.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-23
- Publication Date
- 2025-08-15
- Estimated Expiration
- 2042-12-23
AI Technical Summary
In a service cluster, clients may time out requests due to performance and network differences between different servers, resulting in too long waiting time and affecting the user experience.
When the proxy gateway determines that the request type is GET, an md5 digest is generated as key to read the redis cache result. Otherwise, it will be forwarded to a server randomly and retry synchronously when the timeout is out; for POST requests, redis is forwarded randomly and retry again without reading it.
It shortens the time the client waits for feedback and improves the system's response speed and user experience.
Smart Images

Figure CN115842862B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of proxy gateways, in particular to a method and system for proxy gateway timeout forwarding. Background Art
[0002] To improve the system's carrying capacity, a service is deployed across multiple servers, forming a cluster to provide higher performance and robustness. Requests are forwarded to the backend using the DNS domain name. However, different servers may have performance and network differences, which can lead to timeouts and other issues. This can cause clients to wait for extended periods, resulting in a poor user experience. Summary of the Invention
[0003] The purpose of the present invention is to provide a method for proxy gateway timeout forwarding, which can shorten the time a client waits for request feedback.
[0004] To achieve the above object, the present invention provides the following technical solution: a method for forwarding a proxy gateway timeout, comprising the following steps:
[0005] Step S1, after the proxy gateway receives the client request, the request type is determined, if the request type is GET, step S2 is executed, if the request type is POST, step S5 is executed;
[0006] Step S2: Concatenate the request address and request parameters and generate a digest using MD5. Use the digest string as the key to read Redis. If the result exists in Redis, the result is returned directly to the client. If the result does not exist in Redis, execute Step S3.
[0007] Step S3: randomly forward the request parameters and request address to a server. The server will feedback the result within the response time and return the result to the client immediately, and store the result in redis.
[0008] Step S4: If the server does not get the result within the response time, it will request the next server at the same time until the result is returned. Then it will return to the client immediately, store the result in redis, and end the process;
[0009] Step S5: Do not read redis, and randomly forward the request parameters and request address to a server. If the server response exceeds the response time and no result is obtained, request the next server at the same time until the result is fed back and the result is immediately returned to the client.
[0010] Furthermore, the response time in step S4 is 4-8 seconds; the response time in step S5 is 4-8 seconds; the proxy gateway stores the IP list of the backend server, sets the number of servers in the IP list to n, and randomly forwards to a server, that is, randomly picks a number i from 0 to n-1 from the IP list, and uses i as the subscript to represent the IP of the randomly forwarded server i , forward the request parameters and request address to the server IP i .
[0011] Furthermore, step S4 is further specified as follows: if the server response exceeds the response time and no result is obtained, the same request parameters and request address are copied and the next server is requested at the same time until the requested server returns the result. The server that returns the result first will immediately return the result to the client and store the result in redis. The return result of the server that does not return the result first will be discarded.
[0012] Furthermore, step S5 is further specified as follows: if the request type received by the proxy gateway is POST, redis is not read, and the request parameters and request address are randomly forwarded to a server. If the server response exceeds the response time and no result is obtained, the same request parameters and request address are copied and the next server is requested at the same time until the requested server returns the result. The server that returns the result first will immediately return the result to the client.
[0013] The present invention also provides a proxy gateway timeout forwarding system, comprising a request type judgment module, a GET type processing module, a request forwarding module, a response timeout processing module, and a POST type processing module;
[0014] The request type judgment module is responsible for judging the request type after the proxy gateway receives the client request. If the request type is GET, the GET type processing module is executed; if the request type is POST, the POST type processing module is executed;
[0015] The GET type processing module is responsible for concatenating the request address and request parameters and performing MD5 digest generation, and reading the digest string as the key from redis. If the result exists in redis, the result is directly returned to the client. If the result does not exist in redis, the request forwarding module is executed;
[0016] The request forwarding module is responsible for randomly forwarding the request parameters and request address to a server. The server will feedback the result within the response time and return the result to the client immediately, and store the result in redis.
[0017] The response timeout processing module is responsible for requesting the next server at the same time when the server has not received the result within the response time, and returns the result to the client immediately until the result is returned, stores the result in redis, and ends the process;
[0018] The POST type processing module is responsible for not reading redis, but randomly forwarding the request parameters and request address to a server. If the server response exceeds the response time and no result is obtained, the next server is requested at the same time until the result is fed back and the result is immediately returned to the client.
[0019] Furthermore, the response time in the response timeout processing module is 4-8 seconds; the response time in the POST type processing module is 4-8 seconds; the proxy gateway stores the IP list of the backend server, sets the number of servers in the IP list to n, and randomly forwards to a server, that is, randomly picks a number i from 0 to n-1 from the IP list, and uses i as the subscript to represent the IP of the randomly forwarded server i , forward the request parameters and request address to the server IP i .
[0020] Furthermore, the response timeout processing module is further specified as follows: if the server response exceeds the response time and no result is obtained, the same request parameters and request address are copied and the next server is requested at the same time until the requested server returns the result. The server that returns the result first will immediately return the result to the client and store the result in redis. The return result of the server that does not return the result first will be discarded.
[0021] Furthermore, the POST type processing module is further specified as follows: if the request type received by the proxy gateway is POST, redis is not read, and the request parameters and request address are randomly forwarded to a server. If the server response exceeds the response time and no result is obtained, the same request parameters and request address are copied and the next server is requested at the same time until the requested server returns the result. The server that returns the result first will immediately return the result to the client.
[0022] The beneficial effects of the present invention are as follows: the present invention distinguishes whether to cache the same request according to different request types. If the request type is GET, the address and parameters are spliced together and then MD5 is performed to generate a summary. The summary string is used as the key to read redis, and the result is directly returned to the client. If the request type received by the proxy gateway is POST, redis is not read, and the request parameters and request address are randomly forwarded to a server; and then combined with the timeout synchronous retry mechanism, the timed-out request can obtain the result more quickly. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 Schematic diagram of the method of the present invention.
[0024] Figure 2 Schematic diagram of module connection in the system of the present invention. DETAILED DESCRIPTION
[0025] The present invention will be further described below with reference to the accompanying drawings.
[0026] See also Figure 1 The present invention provides an embodiment: a method for forwarding by a proxy gateway when the proxy gateway timeout occurs, comprising the following steps:
[0027] Step S1, after the proxy gateway receives the client request, the request type is determined, if the request type is GET, step S2 is executed, if the request type is POST, step S5 is executed;
[0028] Step S2: Concatenate the request address and request parameters and generate a digest using MD5. Use the digest string as the key to read Redis. If the result exists in Redis, the result is returned directly to the client. If the result does not exist in Redis, execute Step S3.
[0029] Step S3: randomly forward the request parameters and request address to a server. The server will feedback the result within the response time and return the result to the client immediately, and store the result in redis.
[0030] Step S4: If the server does not get the result within the response time, it will request the next server at the same time until the result is returned. Then it will return to the client immediately, store the result in redis, and end the process;
[0031] Step S5: Do not read redis, and randomly forward the request parameters and request address to a server. If the server response exceeds the response time and no result is obtained, request the next server at the same time until the result is fed back and the result is immediately returned to the client.
[0032] The response time in step S4 is 4-8 seconds; the response time in step S5 is 4-8 seconds; the proxy gateway stores the IP list of the backend server, sets the number of servers in the IP list to n, and randomly forwards to a server, that is, randomly picks a number i from 0 to n-1 from the IP list, and uses i as the subscript to represent the IP of the randomly forwarded server i , forward the request parameters and request address to the server IP i .
[0033] Step S4 is further specified as follows: if the server response exceeds the response time and no result is obtained, the same request parameters and request address are copied and requested to the next server simultaneously until the requested server returns a result. The server that returns the result first will immediately return the result to the client and store the result in Redis. The results returned by the server that did not return the result first will be discarded. An expiration time is set. Requests with the same address and parameters within the expiration time will directly obtain the result from Redis. If the response result is not read from Redis after 1 minute, the response result will be obtained from the new request URL.
[0034] The step S5 is further specified as follows: if the request type received by the proxy gateway is POST, redis is not read, and the request parameters and request address are randomly forwarded to a server. If the server response exceeds the response time and no result is obtained, the same request parameters and request address are copied and the next server is requested at the same time until the requested server returns a result. The server that returns the result first will immediately return the result to the client.
[0035] The present invention will be further described below in conjunction with specific embodiments:
[0036] Step S1, after the proxy gateway receives the client request, the request type is determined, if the request type is GET, step S2 is executed, if the request type is POST, step S5 is executed;
[0037] Step S2: Concatenate the request address and request parameters and perform MD5 to generate a digest. Use the digest string as the key to read redis. If the result exists in redis, the result is returned directly to the client. If the result does not exist in redis, execute step S3.
[0038] After the proxy gateway receives the client request, for example, the request received is https: / / ***.****.*** / info?name=yezi, it determines that the Request Method is equal to GET, concatenates the request address / info and the parameter name=yezi, and performs md5. ( / infoname=yezi)md5 obtains the digest string = 6c9c02c6939c46828a2733d744533b95, and reads the digest string as the key from redis. If there is a response result, it means that this request has been made, and the response result is returned directly to the client.
[0039] Step S3: randomly forward the request parameters and request address to a server. The server will feedback the result within the response time and return the result to the client immediately, and store the result in redis.
[0040] The proxy gateway stores a list of backend server IP addresses, for example, [1**.1**.10.1, 1**.1**.10.5, 1**.1**.10.8]. If no result is obtained from Redis in step 1, it indicates that this is a new request. Based on the number n in the IP list, a random number i from 0 to n-1 is used as the index to obtain the server IP address in the IP list. The request parameters and address are forwarded to a server, such as the following: 1**.1**.10.1:80 / info?name=yezi.
[0041] Step S4: If the server does not get the result within the response time, it will request the next server at the same time until the result is returned. Then it will immediately return to the client, store the result in redis, and end the process.
[0042] If the request 1**.1**.10.1:80 / info?name=yezi does not get a result after 5 seconds, the next server 1**.1**.10.5:80 / info?name=yezi will be requested with the same request parameters and request address. At this time, 1**.1**.10.1 and 1**.1**.10.5 will request at the same time. The server that returns the result first will immediately return it to the client and store the result in Redis. The result returned by the server that did not return the result first will be discarded. Set a 60-second expiration time. Requests with the same address and parameters within 1 minute will get the result directly from Redis. If the response result is not read in Redis after 1 minute, the response result will be obtained from the new request URL.
[0043] Step S5: Do not read redis, and randomly forward the request parameters and request address to a server. If the server response exceeds the response time and no result is obtained, request the next server at the same time until the result is fed back and the result is immediately returned to the client.
[0044] If the proxy gateway receives a request with a Request Method equal to POST, it will not read the request result from Redis, because POST is a write request and must be executed every time. For example, if the request address received is https: / / ***.****.*** / add and the request parameters are {"name":"yezi","age":18}, the request will be randomly forwarded to a server at 1**.1**.10.5:80 / add. If no result is received after 5 seconds, the proxy gateway will copy the same request parameters and request address and request the next server at 1**.1**.10.8:80 / add. At this time, 1**.1**.10.5 and 1**.1**.10.8 are making requests at the same time, and the server that returns the result first will be immediately returned to the client.
[0045] See also Figure 2 As shown, the present invention also provides a proxy gateway timeout forwarding system, including a request type judgment module, a GET type processing module, a request forwarding module, a response timeout processing module, and a POST type processing module;
[0046] The request type judgment module is responsible for judging the request type after the proxy gateway receives the client request. If the request type is GET, the GET type processing module is executed; if the request type is POST, the POST type processing module is executed;
[0047] The GET type processing module is responsible for concatenating the request address and request parameters and performing MD5 digest generation, and reading the digest string as the key from redis. If the result exists in redis, the result is directly returned to the client. If the result does not exist in redis, the request forwarding module is executed;
[0048] The request forwarding module is responsible for randomly forwarding the request parameters and request address to a server. The server will feedback the result within the response time and return the result to the client immediately, and store the result in redis.
[0049] The response timeout processing module is responsible for requesting the next server at the same time when the server has not received the result within the response time, and returns the result to the client immediately until the result is returned, stores the result in redis, and ends the process;
[0050] The POST type processing module is responsible for not reading redis, but randomly forwarding the request parameters and request address to a server. If the server response exceeds the response time and no result is obtained, the next server is requested at the same time until the result is fed back and the result is immediately returned to the client.
[0051] The response time in the response timeout processing module is 4-8 seconds; the response time in the POST type processing module is 4-8 seconds; the proxy gateway stores the IP list of the backend server, sets the number of servers in the IP list to n, and randomly forwards to a server, that is, randomly picks a number i from 0 to n-1 from the IP list, and uses i as the subscript to represent the IP of the randomly forwarded server i , forward the request parameters and request address to the server IP i .
[0052] The response timeout processing module is further specifically: if the server response exceeds the response time and no result is obtained, the same request parameters and request address are copied and the next server is requested at the same time until the requested server returns the result. The server that returns the result first will immediately return the result to the client and store the result in redis. The return result of the server that does not return the result first will be discarded.
[0053] The POST type processing module is further specified as follows: if the request type received by the proxy gateway is POST, redis will not be read, and the request parameters and request address will be randomly forwarded to a server. If the server response exceeds the response time and no result is obtained, the same request parameters and request address will be copied and the next server will be requested at the same time until the requested server returns the result. The server that returns the result first will immediately return the result to the client.
[0054] In summary, the present invention distinguishes whether to cache the same request based on different request types. If the request type is GET, the address and parameters are concatenated and then md5 is used to generate a summary. The summary string is used as the key to read redis, and the result is directly returned to the client. If the request type received by the proxy gateway is POST, redis is not read, and the request parameters and request address are randomly forwarded to a server; combined with the timeout synchronous retry mechanism, the timed-out request can obtain the result faster.
[0055] The above description is only a preferred embodiment of the present invention and should not be understood as limiting the present application. All equivalent changes and modifications made within the scope of the patent application of the present invention should fall within the scope of the present invention.
Claims
1. A method for forwarding when a proxy gateway times out, characterized in that: The following steps are involved: Step S1: After receiving the client request, the proxy gateway determines the request type. If the request type is GET, it executes step S2; if the request type is POST, it executes step S5. Step S2: Concatenate the request address and request parameters and generate a digest using MD5. Use the digest string as the key to read Redis. If the result exists in Redis, the result is returned directly to the client. If the result does not exist in Redis, execute Step S3. Step S3: randomly forward the request parameters and request address to a server. The server will feedback the result within the response time and return the result to the client immediately, and then store the result in redis. Step S4: If the server does not get the result within the response time, it will request the next server at the same time until the result is returned. Then it will return to the client immediately, store the result in redis, and end the process; Step S5: Do not read redis, and randomly forward the request parameters and request address to a server. If the server response exceeds the response time and no result is obtained, request the next server at the same time until the result is fed back and the result is immediately returned to the client.
2. The method for forwarding a proxy gateway timeout according to claim 1, characterized in that: The response time in step S4 is 4-8 seconds; the response time in step S5 is 4-8 seconds; the proxy gateway stores the IP list of the backend server, sets the number of servers in the IP list to n, and randomly forwards to a server, that is, randomly picks a number i from 0 to n-1 from the IP list, and uses i as the subscript to represent the IP of the randomly forwarded server i , forward the request parameters and request address to the server IP i .
3. The method for forwarding a proxy gateway timeout according to claim 1, wherein: Specifically, step S4 is as follows: if the server response exceeds the response time and no result is obtained, the same request parameters and request address are copied and the next server is requested at the same time until the requested server returns the result. The server that returns the result first will immediately return the result to the client and store the result in redis. The return result of the server that does not return the result first will be discarded.
4. The method for forwarding by proxy gateway timeout according to claim 1, characterized in that: Specifically, step S5 is as follows: if the request type received by the proxy gateway is POST, redis is not read, and the request parameters and request address are randomly forwarded to a server. If the server response exceeds the response time and no result is obtained, the same request parameters and request address are copied and the next server is requested at the same time until the requested server returns the result. The server that returns the result first will immediately return the result to the client.
5. A system for proxy gateway timeout forwarding, characterized by: Including request type judgment module, GET type processing module, request forwarding module, response timeout processing module, and POST type processing module; The request type judgment module is responsible for judging the request type after the proxy gateway receives the client request. If the request type is GET, the GET type processing module is executed; if the request type is POST, the POST type processing module is executed; The GET type processing module is responsible for concatenating the request address and request parameters and performing MD5 digest generation, and reading the digest string as the key from redis. If the result exists in redis, the result is directly returned to the client. If the result does not exist in redis, the request forwarding module is executed; The request forwarding module is responsible for randomly forwarding the request parameters and request address to a server. The server feeds back the result within the response time and returns the result to the client immediately, and then stores the result in redis; The response timeout processing module is responsible for requesting the next server at the same time when the server has not received the result within the response time, and returning the result to the client immediately until the result is returned, then storing the result in redis and ending the process; The POST type processing module is responsible for not reading redis, but randomly forwarding the request parameters and request address to a server. If the server response exceeds the response time and no result is obtained, the next server is requested at the same time until the result is fed back and the result is immediately returned to the client.
6. The system for proxy gateway timeout forwarding according to claim 5, characterized in that: The response time in the response timeout processing module is 4-8 seconds; the response time in the POST type processing module is 4-8 seconds; the proxy gateway stores the IP list of the backend server, sets the number of servers in the IP list to n, and randomly forwards to a server, that is, randomly picks a number i from 0 to n-1 from the IP list, and uses i as the subscript to represent the IP of the randomly forwarded server i , forward the request parameters and request address to the server IP i .
7. The proxy gateway timeout forwarding system according to claim 5, characterized in that: The response timeout processing module specifically copies the same request parameters and request address to the next server at the same time if the server response exceeds the response time and no result is obtained, until the requested server returns the result. The server that returns the result first will immediately return the result to the client and store the result in redis. The return result of the server that does not return the result first will be discarded.
8. The proxy gateway timeout forwarding system according to claim 5, characterized in that: Specifically, if the request type received by the proxy gateway is POST, the proxy gateway does not read redis, and randomly forwards the request parameters and request address to a server. If the server response exceeds the response time and no result is obtained, the proxy gateway copies the same request parameters and request address and requests the next server at the same time until the requested server returns the result. The server that returns the result first will immediately return the result to the client.
Citation Information
Patent Citations
Method for binding user account and gateway equipment on basis of open-type intelligent gateway platform
CN104144168A
Method and device for realizing interface idempotence
CN111865970A