Timeout detection method, device, equipment, storage medium and computer program product
By periodically judging the timeout of the call request at the distributor layer on the service provider side, and terminating the business processing if it times out, the problem of resource waste after the service call times out is solved, and fast failure and resource saving are achieved.
Patent Information
- Application Number
- CN202211423536.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-15
- Publication Date
- 2025-01-21
- Estimated Expiration
- 2042-11-15
AI Technical Summary
Under the microservice architecture, when the service call timeout expires, the service provider cannot perceive the timeout, resulting in continued execution of subsequent request processing and waste of resources.
The call request is received through the network communication layer of the service provider, and the request is submitted to the filter layer through the distributor layer. It periodically determines whether the current time is greater than the first time information. If it times out, the business processing is terminated according to the returned result.
It realizes the periodic detection of timeout during the business processing process. If it times out, the business processing will be terminated immediately to avoid waste of resources and achieve the purpose of rapid failure.
Smart Images

Figure CN115766859B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of cloud computing technology, and in particular to a timeout detection method, apparatus, device, storage medium and computer program product. Background Art
[0002] Under the microservice architecture, microservice calls take a short time and transaction timeouts are generally in the millisecond level. In certain system failure scenarios (such as server system failure, network failure, etc.), call timeouts are prone to occur.
[0003] Currently, after a service consumer sends a request, the network communication layer in the service consumer will wait for a response and continuously check whether it has timed out. If it has timed out, it can be sensed immediately and will no longer wait for a response, but will directly return a failure. After receiving a request, the service provider will directly start processing until it is completed and return the result to the service consumer.
[0004] However, after the service consumer sends a request, if the service consumer calls the service timeout, it will actively mark the request as failed and immediately return a failure prompt to the client. However, since the service provider cannot perceive the transaction timeout, it will continue to execute the subsequent request processing process, resulting in a waste of resources. Summary of the invention
[0005] Based on this, it is necessary to provide a timeout detection method, device, equipment, storage medium and computer program product that can reduce resource waste in response to the above technical problems.
[0006] In a first aspect, the present application provides a timeout detection method. The method comprises:
[0007] receiving a call request sent by a service consumer through a network communication layer of a service provider, and submitting the call request to a distributor layer of the service provider through the network communication layer; the call request includes first time information, which is determined according to the time when the service consumer sends the call request and a preset duration;
[0008] Submitting the call request to the filter layer of the service provider through the distributor layer, and receiving a first return result returned by the filter layer through the distributor layer;
[0009] The distributor layer periodically determines whether the current time is greater than the first time information, and when the current time is greater than the first time information, terminates the business processing corresponding to the call request according to the first return result.
[0010] In one embodiment, submitting the call request to the filter layer of the service provider through the distributor layer, and receiving the first return result returned by the filter layer through the distributor layer, includes:
[0011] The call request is submitted to the timeout detection filter in the filter layer through the distributor layer, and the return result returned by the timeout detection filter is received through the distributor layer.
[0012] In one embodiment, the method further comprises: submitting the call request to the filter layer of the service provider through the distributor layer;
[0013] Determine whether the current time is greater than the first time information through the timeout detection filter;
[0014] If the current time is greater than the first time information, an empty result is returned to the distributor layer through the timeout detection filter.
[0015] In one embodiment, the method further comprises:
[0016] If the current time is not greater than the first time information, calling other filters in the filter layer to call the business code layer of the service provider through the other filters; the other filters include filters in the filter layer except the timeout detection filter;
[0017] The second return result returned by the business code layer is received through the timeout detection filter.
[0018] In one of the embodiments, after calling other filters in the filter layer, the method further includes:
[0019] Determine whether the current time is greater than the first time information through the timeout detection filter;
[0020] If the current time is greater than the first time information, the second returned result is discarded through the timeout detection filter, and an empty result is returned to the network communication layer through the timeout detection filter.
[0021] In one embodiment, terminating the business processing corresponding to the call request according to the first returned result includes:
[0022] According to the thread identifier included in the first returned result, the target thread corresponding to the thread identifier is terminated to terminate the business processing corresponding to the call request.
[0023] In a second aspect, the present application also provides a timeout detection device. The device comprises:
[0024] A first receiving module is used to receive a call request sent by a service consumer through a network communication layer of a service provider, and submit the call request to a distributor layer of the service provider through the network communication layer; the call request includes first time information, which is determined according to the time when the service consumer sends the call request and a preset time length;
[0025] A submission module, used to submit the call request to the filter layer of the service provider through the distributor layer, and receive a first return result returned by the filter layer through the distributor layer;
[0026] A processing module is used to periodically determine whether the current time is greater than the first time information through the distributor layer, and when the current time is greater than the first time information, terminate the business processing corresponding to the call request according to the first return result.
[0027] In a third aspect, the present application further provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:
[0028] receiving a call request sent by a service consumer through a network communication layer of a service provider, and submitting the call request to a distributor layer of the service provider through the network communication layer; the call request includes first time information, which is determined according to the time when the service consumer sends the call request and a preset duration;
[0029] Submitting the call request to the filter layer of the service provider through the distributor layer, and receiving a first return result returned by the filter layer through the distributor layer;
[0030] The distributor layer periodically determines whether the current time is greater than the first time information, and when the current time is greater than the first time information, terminates the business processing corresponding to the call request according to the first return result.
[0031] In a fourth aspect, the present application further provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0032] receiving a call request sent by a service consumer through a network communication layer of a service provider, and submitting the call request to a distributor layer of the service provider through the network communication layer; the call request includes first time information, which is determined according to the time when the service consumer sends the call request and a preset duration;
[0033] Submitting the call request to the filter layer of the service provider through the distributor layer, and receiving a first return result returned by the filter layer through the distributor layer;
[0034] The distributor layer periodically determines whether the current time is greater than the first time information, and when the current time is greater than the first time information, terminates the business processing corresponding to the call request according to the first return result.
[0035] In a fifth aspect, the present application further provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0036] receiving a call request sent by a service consumer through a network communication layer of a service provider, and submitting the call request to a distributor layer of the service provider through the network communication layer; the call request includes first time information, which is determined according to the time when the service consumer sends the call request and a preset duration;
[0037] Submitting the call request to the filter layer of the service provider through the distributor layer, and receiving a first return result returned by the filter layer through the distributor layer;
[0038] The distributor layer periodically determines whether the current time is greater than the first time information, and when the current time is greater than the first time information, terminates the business processing corresponding to the call request according to the first return result.
[0039] The above-mentioned timeout detection method, device, equipment, storage medium and computer program product receive the call request sent by the service consumer end through the network communication layer of the service provider end, and submit the call request to the distributor layer of the service provider end through the network communication layer, and submit the call request to the filter layer of the service provider end through the distributor layer, and receive the first return result returned by the filter layer through the distributor layer, and then periodically determine whether the current time is greater than the first time information through the distributor layer, and when the current time is greater than the first time information, terminate the business processing corresponding to the call request according to the first return result, thereby realizing periodic loop detection of whether timeout occurs during the business processing process. If timeout occurs, it means that the service consumer end has given up waiting for the return result of this call request, and it is meaningless to continue execution. Therefore, in the case of timeout, the business processing being executed is terminated immediately to achieve the purpose of rapid failure and avoid waste of resources on the service provider end. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 An application environment diagram of a timeout detection method in an embodiment;
[0041] Figure 2 It is a flowchart of a timeout detection method provided in an embodiment of the present application;
[0042] Figure 3 It is a flowchart of a request processing method of a service provider provided in an embodiment of the present application;
[0043] Figure 4 It is a flowchart of a timeout determination method provided in an embodiment of the present application;
[0044] Figure 5 It is a flowchart of a second return result receiving method provided in an embodiment of the present application;
[0045] Figure 6 It is a flowchart of a second returned result discarding method provided in an embodiment of the present application;
[0046] Figure 7 It is a flow chart of signaling interaction between a service consumer and a service provider provided in an embodiment of the present application;
[0047] Figure 8 It is a structural schematic diagram of a timeout detection device provided in an embodiment of the present application;
[0048] Fig. 9 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0049] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0050] In traditional technology, if a transaction times out, the time it takes for the service consumer and the service provider to perceive this abnormal situation is different. Specifically, after the service consumer sends a request, the network communication layer of the service consumer will wait for a response and continuously check whether it has timed out. If it has timed out, it can be sensed immediately and will no longer wait for a response, but will directly return failure.
[0051] When the service provider receives a request, it will directly start processing until it is completed and return the result to the service consumer. Even if the transaction has timed out, the service consumer will not be aware of it, and will do a lot of useless work in vain, resulting in a waste of resources.
[0052] Therefore, in order to solve the above technical problems. The present application embodiment provides a timeout detection method, which can be applied to Figure 1In the application environment shown. Among them, the service consumer end 101 communicates with the service provider end 102 through the network. The call request sent by the service consumer end 101 is received through the network communication layer of the service provider end 102, and the call request is submitted to the distributor layer of the service provider end 102 through the network communication layer; the call request includes the first time information, and the first time information is determined according to the time when the service consumer end 101 sends the call request and the preset duration; the call request is submitted to the filter layer of the service provider end 102 through the distributor layer, and the first return result returned by the filter layer is received through the distributor layer; the distributor layer periodically determines whether the current time is greater than the first time information, and when the current time is greater than the first time information, the service processing corresponding to the call request is terminated according to the first return result. Among them, the service consumer end 101 can be, but not limited to, various personal computers, laptops, smart phones, tablet computers, Internet of Things devices and portable wearable devices, and the Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The service provider end can be implemented with an independent server or a server cluster composed of multiple servers.
[0053] In one embodiment, Figure 2 As shown, Figure 2 is a flow chart of a timeout detection method provided in an embodiment of the present application, in which the method is applied to Figure 1 The service provider in the example is used as an example to illustrate, including the following steps:
[0054] S201. Receive a call request sent by a service consumer through the network communication layer of the service provider, and submit the call request to the distributor layer of the service provider through the network communication layer; the call request includes first time information, which is determined according to the time when the service consumer sends the call request and a preset duration.
[0055] In the embodiment of the present application, before the service consumer sends a call request to the service provider, the service consumer encapsulates the first time information and the request content in the call request, and then sends the call request to the service provider. The first time information refers to the timeout information. The timeout information here is a timestamp, which refers to the maximum time allowed to wait for a transaction corresponding to the call request. For example, the timestamp of the current time is 1651914922000 (in milliseconds), and the preset duration, that is, the timeout time is set to 5000 milliseconds, then the timeout information transmitted here is 1651914922000+5000=1651914927000.
[0056] S202: Submit a call request to the filter layer of the service provider through the distributor layer, and receive a first return result returned by the filter layer through the distributor layer.
[0057] In an embodiment of the present application, after a call request is submitted to the filter layer of the service provider through the distributor layer, the filter layer will detect whether it has timed out immediately after receiving the call request, that is, determine whether the current time is greater than the first time information.
[0058] It should be noted that in traditional technology, in the original logic, the submission operation of submitting a call request to the filter layer of the service provider through the distributor layer has no return value, which means that once the request is submitted to the thread pool, the distributor layer can no longer intervene in the call request. In the solution designed by this application, this submission action needs to have a return value so that the timing detection mechanism can terminate the business processing process in time after detecting a timeout. From the technical implementation of Java, the original logical submission operation uses the Executor#execute function, while the solution of this application uses the ExecutorService#submit function, and this function returns a Future type result, which provides the ability to terminate the task being executed. The Future type result can be the first return result.
[0059] Step 203: The distributor layer periodically determines whether the current time is greater than the first time information, and when the current time is greater than the first time information, terminates the business processing corresponding to the call request according to the first return result.
[0060] After the call request is submitted to the thread pool, an idle thread will be selected from the thread pool to process the call request. The first returned result may include the thread identifier of the thread that processes the call request. If the distributor layer detects that the current time is greater than the first time information, the thread corresponding to the thread identifier will be terminated, thereby terminating the business processing corresponding to the thread.
[0061] The timeout detection method provided in the embodiment of the present application receives the call request sent by the service consumer end through the network communication layer of the service provider end, submits the call request to the distributor layer of the service provider end through the network communication layer, submits the call request to the filter layer of the service provider end through the distributor layer, and receives the first return result returned by the filter layer through the distributor layer, and then periodically determines whether the current time is greater than the first time information through the distributor layer, and terminates the business processing corresponding to the call request according to the first return result when the current time is greater than the first time information, thereby realizing periodic loop detection of timeout during the business processing process. If timeout occurs, it means that the service consumer end has given up waiting for the return result of the call request, and it is meaningless to continue execution. Therefore, in the case of timeout, the business processing being executed is terminated immediately to achieve the purpose of rapid failure and avoid waste of resources on the service provider end.
[0062] It should be noted that the so-called fast failure means that in the software system, if errors or anomalies in operation can be discovered as early as possible, it is possible to correct them in time, or directly terminate the operation where the error occurred to avoid larger errors. At the same time, it can also save valuable system resources. This strategy is called fast failure.
[0063] In one embodiment, the above S202, submitting a call request to the filter layer of the service provider through the distributor layer, and receiving the first return result returned by the filter layer through the distributor layer, can be implemented as follows:
[0064] A call request is submitted to the timeout detection filter in the filter layer through the distributor layer, and a first return result returned by the timeout detection filter is received through the distributor layer.
[0065] like Figure 3 As shown, Figure 3 1 is a flow chart of a request processing method of a service provider provided in an embodiment of the present application. The method includes:
[0066] S301. The network communication layer of the service provider sends a call request to the distributor layer of the service provider.
[0067] S302: The dispatcher layer of the service provider submits a call request to the timeout detection filter in the filter layer.
[0068] S303. The timeout detection filter returns a first return result to the distributor layer.
[0069] S304: The distributor layer periodically determines whether the current time is greater than the first time information.
[0070] S305: When the current time is greater than the first time information, terminate the business processing corresponding to the call request according to the first returned result.
[0071] The filter layer includes a timeout detection filter and other filters, for example, other filters include filter Y and filter M. If the filter layer receives a call request, it will then call the business code layer to process the business. After the business code layer processes the business, it will return the result of the business processing through filter M, filter Y, timeout detection filter and network communication layer in sequence. The return result is transmitted to the network communication layer of the service consumer through the network communication layer of the service provider.
[0072] Reference Figure 4 , Figure 41 is a flow chart of a timeout determination method provided by an embodiment of the present application. This embodiment relates to an optional implementation method of how to determine whether a timeout has occurred after a call request is submitted to a timeout detection filter in a filter layer through a distributor layer. Based on the above embodiment, the method includes the following steps:
[0073] S401. Determine whether the current time is greater than the first time information through a timeout detection filter.
[0074] S402: If the current time is greater than the first time information, an empty result is returned to the distributor layer.
[0075] In the embodiment of the present application, after receiving the call request, the timeout detection filter can also determine whether the current time is greater than the first time information. If the current time is greater than the first time information, it means that it has timed out and no further business processing is required. In this case, the timeout detection filter immediately returns an empty result to the distributor. Thereby, when the timeout detection filter on the service provider side detects a timeout, it fails immediately and no longer processes according to the original process, thereby reducing unnecessary computing overhead. In this embodiment, if the timeout detection filter has timed out at this moment after just receiving the call request, it will no longer continue processing and directly return an empty result.
[0076] Reference Figure 5 , Figure 5 1 is a flow chart of a second return result receiving method provided by an embodiment of the present application. This embodiment relates to an optional implementation method of how to determine whether a timeout has occurred after a call request is submitted to a timeout detection filter in a filter layer through a distributor layer. Based on the above embodiment, the method includes the following steps:
[0077] S501. If the current time is not greater than the first time information, other filters in the filter layer are called to call the business code layer of the service provider through other filters; other filters include filters in the filter layer except the timeout detection filter.
[0078] In the present application embodiment, for example, Figure 3 As shown, if the current time is not greater than the first time information, filter Y and filter M in the filter layer are called to call the business code layer of the service provider, so that the business code layer processes the business corresponding to the call request.
[0079] S502: Receive a second return result returned by the business code layer through a timeout detection filter.
[0080] If the service code layer processes the service, the service code layer returns the second return result to the timeout detection filter. The second return result is as follows Figure 3 The returned results are shown.
[0081] In an embodiment of the present application, if the current time is not greater than the first time information, other filters in the filter layer are called to call the business code layer of the service provider through other filters, and the second return result returned by the business code layer is received through the timeout detection filter, thereby ensuring that other filters in the filter layer are called only when the current time is not greater than the first time information, so as to call the business code layer of the service provider through other filters to process the business, thereby avoiding unnecessary waste of resources.
[0082] Reference Figure 6 , Figure 6 1 is a flow chart of a second return result discarding method provided by an embodiment of the present application. This embodiment relates to an optional implementation method of how to determine whether a timeout has occurred after calling other filters in the filter layer. Based on the above embodiment, the method includes the following steps:
[0083] S601. Determine whether the current time is greater than the first time information through a timeout detection filter.
[0084] It should be noted that the current time in this step refers to the time when the timeout detection filter receives the second return result. If the current time is greater than the first time information, it means that there is no need to return the real processing result, that is, there is no need to return the second return result.
[0085] S602: If the current time is greater than the first time information, the second returned result is discarded through the timeout detection filter, and an empty result is returned to the network communication layer through the timeout detection filter.
[0086] In the embodiment of the present application, the timeout detection filter is used to determine whether the current time is greater than the first time information. If the current time is greater than the first time information, the second return result is discarded through the timeout detection filter, and an empty result is returned to the network communication layer through the timeout detection filter. If the current time is greater than the first time information, it means that the timeout detection filter has timed out when receiving the second return result. At this time, there is no need to return the second return result to the service consumer. Therefore, in this case, an empty result is returned to the network communication layer through the timeout detection filter.
[0087] It should be noted that when the business code layer completes processing and is about to return a result, if it has timed out at this moment, the real business result is discarded, that is, the second returned result is discarded.
[0088] In one embodiment, the above-mentioned step of terminating the business processing corresponding to the call request according to the first return result in S203 can be implemented in the following manner:
[0089] According to the thread identifier included in the first returned result, the target thread corresponding to the thread identifier is terminated to terminate the business processing corresponding to the call request.
[0090] The business processing corresponding to the termination call request here refers to "trying" to terminate the thread corresponding to the call request. The reason why we say "trying" to terminate the thread is that the thread cannot always be terminated. In Java, a thread that is using the CPU for calculation cannot be stopped. Taking the JDK8 version of the specification as an example, the thread can only be terminated when it is in the following three states: "Newly created and not yet started (New)", "Waiting state (Runnable) due to temporary release of the CPU by CPU scheduling", and "Blocked temporarily due to waiting for resources (blocked)". Please note that this paragraph discusses the thread state at the micro level, from the perspective of the CPU. If we stand at the macro level, the business processing is actually ongoing. For example, there is a step in the business processing logic that needs to read data from the database. When the thread waits for the database to return data, the thread will be in the Runable state due to the CPU scheduling, but from a macro perspective, the business processing is accessing the database without any stagnation.
[0091] Considering that most business processing is IO-intensive rather than CPU-intensive, it means that threads are often in the three interruptible states mentioned above, so calling the cancel method to terminate the thread is mostly effective.
[0092] Reference Figure 7 , Figure 7 This is a flow chart of signaling interaction between a service consumer and a service provider provided by an embodiment of the present application. The method includes: the service code layer of the service consumer sends a call request to filter 1 of the service consumer, filter 1 sends a call request to filter 2, filter 2 sends a call request to filter N, filter N sends a call request to the network communication layer of the service consumer, the network communication layer of the service consumer sends a call request to the network communication layer of the service provider, and after the network communication layer of the service provider receives the call request, the subsequent processing process is the same as Figure 3 As shown, no further description is given here.
[0093] It should be noted that the core idea of this application is: when a call request is initiated at the service consumer end, the timeout information is sent to the service provider end along with the call request. The service provider end can perform timeout detection at three times. Once it is found that the transaction has timed out, it will fail immediately and will no longer be processed according to the original process, thereby reducing unnecessary calculations. The three times include detecting the occurrence of timeouts at three moments before the start of business processing, during business processing, and after the end of business processing, and then performing corresponding special processing to reduce the provider's resource consumption and reduce the amount of data on the network. Before the start of business processing refers to the timeout detection filter returning an empty result after detecting a timeout, during business processing refers to the distributor periodically detecting whether there is a timeout, and after the end of business processing refers to if the current time is greater than the first time information, the second returned result is discarded through the timeout detection filter, and an empty result is returned to the network communication layer through the timeout detection filter.
[0094] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0095] Based on the same inventive concept, the embodiment of the present application also provides a timeout detection device for implementing the timeout detection method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more timeout detection device embodiments provided below can refer to the limitations on the timeout detection method above, and will not be repeated here.
[0096] In one embodiment, Figure 8 As shown, Figure 8 800 is a schematic diagram of a timeout detection device provided in an embodiment of the present application. The device 800 includes:
[0097] The first receiving module 801 is used to receive a call request sent by a service consumer through a network communication layer of a service provider, and submit the call request to a distributor layer of the service provider through the network communication layer; the call request includes first time information, which is determined according to the time when the service consumer sends the call request and a preset duration;
[0098] A submission module 802 is used to submit the call request to the filter layer of the service provider through the distributor layer, and receive a first return result returned by the filter layer through the distributor layer;
[0099] The processing module 803 is used to periodically determine whether the current time is greater than the first time information through the distributor layer, and when the current time is greater than the first time information, terminate the business processing corresponding to the call request according to the first return result.
[0100] In one of the embodiments, the submission module 802 is specifically used to submit the call request to the timeout detection filter in the filter layer through the distributor layer, and receive the first return result returned by the timeout detection filter through the distributor layer.
[0101] In one embodiment, after submitting the call request to the filter layer of the service provider through the distributor layer, the device 800 further includes:
[0102] A first judging module, configured to judge whether the current time is greater than the first time information through the timeout detection filter;
[0103] The first sending module is used to return an empty result to the distributor layer through the timeout detection filter if the current time is greater than the first time information.
[0104] In the embodiment of the present application, after receiving the call request, the timeout detection filter can also determine whether the current time is greater than the first time information. If the current time is greater than the first time information, it means that the timeout has been reached and no subsequent business processing is required. In this case, the timeout detection filter immediately returns an empty result to the distributor. In this way, when the timeout detection filter on the service provider side detects a timeout, it fails immediately and no longer processes according to the original process, thereby reducing unnecessary computing overhead.
[0105] In one embodiment, the apparatus 800 further includes:
[0106] A first calling module, configured to call other filters in the filter layer if the current time is not greater than the first time information, so as to call the business code layer of the service provider through the other filters; the other filters include filters in the filter layer except the timeout detection filter;
[0107] The second receiving module is used to receive a second return result returned by the business code layer through the timeout detection filter.
[0108] In one embodiment, after calling other filters in the filter layer, the apparatus 800 further includes:
[0109] A second judgment module, used for judging whether the current time is greater than the first time information through the timeout detection filter;
[0110] A discarding module is used to discard the second returned result through the timeout detection filter if the current time is greater than the first time information, and return an empty result to the network communication layer through the timeout detection filter.
[0111] In the embodiment of the present application, the timeout detection filter is used to determine whether the current time is greater than the first time information. If the current time is greater than the first time information, the second return result is discarded through the timeout detection filter, and an empty result is returned to the network communication layer through the timeout detection filter. If the current time is greater than the first time information, it means that the timeout detection filter has timed out when receiving the second return result. At this time, there is no need to return the second return result to the service consumer. Therefore, in this case, an empty result is returned to the network communication layer through the timeout detection filter.
[0112] In one embodiment, the processing module 803 is specifically configured to terminate the target thread corresponding to the thread identifier according to the thread identifier included in the first returned result, so as to terminate the business processing corresponding to the call request.
[0113] Each module in the above-mentioned timeout detection device can be implemented in whole or in part by software, hardware and a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each module above.
[0114] In one embodiment, a computer device is provided. The computer device may be a server or a terminal. The internal structure diagram thereof may be as follows: Fig. 9 As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a timeout detection method is implemented.
[0115] Those skilled in the art will understand that Fig. 9The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0116] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the following steps are implemented:
[0117] receiving a call request sent by a service consumer through a network communication layer of a service provider, and submitting the call request to a distributor layer of the service provider through the network communication layer; the call request includes first time information, which is determined according to the time when the service consumer sends the call request and a preset duration;
[0118] Submitting the call request to the filter layer of the service provider through the distributor layer, and receiving a first return result returned by the filter layer through the distributor layer;
[0119] The distributor layer periodically determines whether the current time is greater than the first time information, and when the current time is greater than the first time information, terminates the business processing corresponding to the call request according to the first return result.
[0120] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0121] The call request is submitted to the timeout detection filter in the filter layer through the distributor layer, and the first return result returned by the timeout detection filter is received through the distributor layer.
[0122] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0123] Determine whether the current time is greater than the first time information through the timeout detection filter;
[0124] If the current time is greater than the first time information, an empty result is returned to the distributor layer through the timeout detection filter.
[0125] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0126] If the current time is not greater than the first time information, calling other filters in the filter layer to call the business code layer of the service provider through the other filters; the other filters include filters in the filter layer except the timeout detection filter;
[0127] The second return result returned by the business code layer is received through the timeout detection filter.
[0128] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0129] Determine whether the current time is greater than the first time information through the timeout detection filter;
[0130] If the current time is greater than the first time information, the second returned result is discarded through the timeout detection filter, and an empty result is returned to the network communication layer through the timeout detection filter.
[0131] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0132] According to the thread identifier included in the first returned result, the target thread corresponding to the thread identifier is terminated to terminate the business processing corresponding to the call request.
[0133] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0134] receiving a call request sent by a service consumer through a network communication layer of a service provider, and submitting the call request to a distributor layer of the service provider through the network communication layer; the call request includes first time information, which is determined according to the time when the service consumer sends the call request and a preset duration;
[0135] Submitting the call request to the filter layer of the service provider through the distributor layer, and receiving a first return result returned by the filter layer through the distributor layer;
[0136] The distributor layer periodically determines whether the current time is greater than the first time information, and when the current time is greater than the first time information, terminates the business processing corresponding to the call request according to the first return result.
[0137] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0138] The call request is submitted to the timeout detection filter in the filter layer through the distributor layer, and the first return result returned by the timeout detection filter is received through the distributor layer.
[0139] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0140] Determine whether the current time is greater than the first time information through the timeout detection filter;
[0141] If the current time is greater than the first time information, an empty result is returned to the distributor layer through the timeout detection filter.
[0142] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0143] If the current time is not greater than the first time information, calling other filters in the filter layer to call the business code layer of the service provider through the other filters; the other filters include filters in the filter layer except the timeout detection filter;
[0144] The second return result returned by the business code layer is received through the timeout detection filter.
[0145] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0146] Determine whether the current time is greater than the first time information through the timeout detection filter;
[0147] If the current time is greater than the first time information, the second returned result is discarded through the timeout detection filter, and an empty result is returned to the network communication layer through the timeout detection filter.
[0148] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0149] According to the thread identifier included in the first returned result, the target thread corresponding to the thread identifier is terminated to terminate the business processing corresponding to the call request.
[0150] In one embodiment, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the following steps:
[0151] receiving a call request sent by a service consumer through a network communication layer of a service provider, and submitting the call request to a distributor layer of the service provider through the network communication layer; the call request includes first time information, which is determined according to the time when the service consumer sends the call request and a preset duration;
[0152] Submitting the call request to the filter layer of the service provider through the distributor layer, and receiving a first return result returned by the filter layer through the distributor layer;
[0153] The distributor layer periodically determines whether the current time is greater than the first time information, and when the current time is greater than the first time information, terminates the business processing corresponding to the call request according to the first return result.
[0154] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0155] The call request is submitted to the timeout detection filter in the filter layer through the distributor layer, and the first return result returned by the timeout detection filter is received through the distributor layer.
[0156] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0157] Determine whether the current time is greater than the first time information through the timeout detection filter;
[0158] If the current time is greater than the first time information, an empty result is returned to the distributor layer through the timeout detection filter.
[0159] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0160] If the current time is not greater than the first time information, calling other filters in the filter layer to call the business code layer of the service provider through the other filters; the other filters include filters in the filter layer except the timeout detection filter;
[0161] The second return result returned by the business code layer is received through the timeout detection filter.
[0162] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0163] Determine whether the current time is greater than the first time information through the timeout detection filter;
[0164] If the current time is greater than the first time information, the second returned result is discarded through the timeout detection filter, and an empty result is returned to the network communication layer through the timeout detection filter.
[0165] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0166] According to the thread identifier included in the first returned result, the target thread corresponding to the thread identifier is terminated to terminate the business processing corresponding to the call request.
[0167] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.
[0168] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0169] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0170] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A timeout detection method, characterized in that: The method comprises: receiving a call request sent by a service consumer through a network communication layer of a service provider, and submitting the call request to a distributor layer of the service provider through the network communication layer; the call request includes first time information, which is determined according to the time when the service consumer sends the call request and a preset duration; Submitting the call request to the filter layer of the service provider through the distributor layer, and receiving a first return result returned by the filter layer through the distributor layer; Periodically judging, by the distributor layer, whether the current time is greater than the first time information, and terminating the business processing corresponding to the call request according to the first returned result when the current time is greater than the first time information; After submitting the call request to the filter layer of the service provider through the distributor layer, the method further includes: Determine whether the current time is greater than the first time information through the timeout detection filter in the filter layer; If the current time is not greater than the first time information, calling other filters in the filter layer to call the business code layer of the service provider through the other filters; the other filters include filters in the filter layer except the timeout detection filter; The second return result returned by the business code layer is received through the timeout detection filter.
2. The method according to claim 1, characterized in that Submitting the call request to the filter layer of the service provider through the distributor layer, and receiving the first return result returned by the filter layer through the distributor layer, includes: The call request is submitted to the timeout detection filter in the filter layer through the distributor layer, and the first return result returned by the timeout detection filter is received through the distributor layer.
3. The method according to claim 2, characterized in that The method further comprises: If the current time is greater than the first time information, an empty result is returned to the distributor layer through the timeout detection filter.
4. The method according to claim 1, characterized in that: After calling other filters in the filter layer, the method further includes: Determine whether the current time is greater than the first time information through the timeout detection filter; If the current time is greater than the first time information, the second returned result is discarded through the timeout detection filter, and an empty result is returned to the network communication layer through the timeout detection filter.
5. The method according to any one of claims 1 to 4, characterized in that: The terminating the business processing corresponding to the calling request according to the first returned result includes: According to the thread identifier included in the first returned result, the target thread corresponding to the thread identifier is terminated to terminate the business processing corresponding to the call request.
6. A timeout detection device, characterized in that: The device comprises: A first receiving module is used to receive a call request sent by a service consumer through a network communication layer of a service provider, and submit the call request to a distributor layer of the service provider through the network communication layer; the call request includes first time information, which is determined according to the time when the service consumer sends the call request and a preset time length; A submission module, used to submit the call request to the filter layer of the service provider through the distributor layer, and receive a first return result returned by the filter layer through the distributor layer; a processing module, configured to periodically determine, through the distributor layer, whether the current time is greater than the first time information, and, if the current time is greater than the first time information, terminate the business processing corresponding to the call request according to the first returned result; The device also includes: A first judgment module, used for judging whether the current time is greater than the first time information through a timeout detection filter in the filter layer; A first calling module, configured to call other filters in the filter layer if the current time is not greater than the first time information, so as to call the business code layer of the service provider through the other filters; the other filters include filters in the filter layer except the timeout detection filter; The second receiving module is used to receive a second return result returned by the business code layer through the timeout detection filter.
7. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 5 are implemented.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
9. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Transaction anti-suspension method and device under Dubbo framework
CN111796958A