Service calling method, device, electronic device and storage medium
By allocating alternative threads for task processing requests in service calls to handle abnormal sub-target services, the avalanche problem caused by too long a timeout mechanism is solved, improving task processing efficiency and avoiding long-term blocking.
Patent Information
- Application Number
- CN202010613836.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-06-30
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2040-10-29
AI Technical Summary
In the existing technology, the timeout mechanism is set too long when the service is called, which may cause an avalanche phenomenon when a sub-service fails, resulting in low task processing efficiency and the inability to effectively avoid long-term blocking.
By allocating the first calling thread for the task processing request, if it is detected that the sub-target service is in an abnormal state, the second calling thread is assigned to replace the first calling thread. If the first calling thread does not receive the result within the preset time, the call will continue. For the next subtask, the waiting time between threads is less than the timeout of the first calling thread to avoid long-term blocking.
It effectively avoids long-term blocking when the sub-target service call fails, improves the processing efficiency of task processing requests, and ensures that when the sub-target service fails, the call failure can be quickly determined and other sub-tasks can be continued.
Smart Images

Figure CN111782364B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of Internet technology, and in particular to a service calling method, device, electronic device and storage medium. Background Art
[0002] With the development of Internet business, the services that can be provided are becoming more and more complex. Therefore, the services are split into multiple sub-services and deployed on different servers. When needed, multiple sub-services are called through RPC (Remote Procedure Call) to provide complete services.
[0003] In Internet services, in order to complete a task, it may be necessary to use remote calls to request other sub-services to complete some intermediate steps, that is, the sub-tasks of the task. If the called sub-service fails, it may cause the processing result of the sub-task to not be returned in time, thereby blocking the processing of the entire task. In severe cases, the failure of a smaller sub-service may cause the entire task to be unable to continue. This phenomenon is called avalanche.
[0004] At present, the industry has proposed solutions to solve the above-mentioned call blocking problem, such as the timeout mechanism. Specifically, the timeout mechanism sets a timeout period. When the remote call time of a sub-service exceeds the timeout period, it is determined that the remote call to the sub-service has failed, and the next sub-service can be called remotely, thereby ensuring that subsequent subtasks can continue to be executed, while avoiding the computing resources being occupied all the time.
[0005] However, the problem with the timeout mechanism is that in order to avoid a small amount of service performance jitter causing a remote call timeout failure, the timeout period is usually set to be relatively long, which means that if the called sub-service or network fails for a long time, it is possible that all subtasks will increase the waiting time. And when a sub-service call fails for a long time, it will still cause an avalanche. It can be seen that setting a timeout period too long cannot solve the blocking problem in the case of a failure. Therefore, how to reasonably adjust the timeout period for calling sub-services to avoid long-term blocking and improve the processing efficiency of task processing requests is an urgent problem to be solved. Summary of the invention
[0006] The present disclosure provides a service calling method, device, electronic device and storage medium to at least solve the problem in the related art that the timeout period for calling a sub-service is unreasonable, resulting in long-term blocking and low processing efficiency of task processing requests.
[0007] The technical solution of the present disclosure is as follows:
[0008] According to a first aspect of an embodiment of the present disclosure, a service calling method is provided, the method comprising:
[0009] A service calling method, characterized in that the method comprises:
[0010] Obtaining a task processing request; the task processing request includes at least one subtask to be processed;
[0011] Determine a sub-target service corresponding to the sub-task; the sub-target service is used to process the sub-task and return a processing result;
[0012] Allocating a first calling thread to the task processing request, wherein the first calling thread is used to call the sub-target services in sequence;
[0013] In the process of the first calling thread calling the sub-target service, when it is determined that the sub-target service is in an abnormal state, a second calling thread is allocated to the sub-target service, and the second calling thread is used to replace the first calling thread to call the sub-target service;
[0014] If the first calling thread fails to receive the processing result of the sub-target service processing the sub-task returned by the second calling thread within the preset inter-thread waiting time, the first calling thread continues to call the sub-target service corresponding to the next sub-task; wherein the inter-thread waiting time is less than the first timeout time corresponding to the first calling thread, and the first timeout time is the waiting time for the first calling thread to determine whether to stop calling the sub-target service.
[0015] In an exemplary embodiment, before allocating a second calling thread to the sub-target service, the method further includes:
[0016] Acquire state description data of the sub-target service; the state description data is used to characterize the response state of the sub-target service to the sub-task;
[0017] According to the state description data, it is determined whether the sub-target service is in an abnormal state or a normal state.
[0018] In an exemplary embodiment, when the state description data is a weight value, the weight value is used to represent the proportion of the number of times the sub-target service is successfully called in the total number of times the sub-target service is called;
[0019] The determining, according to the state description data, that the sub-target service is in an abnormal state or a normal state includes:
[0020] When the weight value is less than a preset threshold, determining that the sub-target service is in an abnormal state;
[0021] When the weight value is greater than or equal to a preset threshold, it is determined that the sub-target service is in a normal state.
[0022] In an exemplary embodiment, after allocating a second calling thread for the sub-target service, the method further includes:
[0023] When the processing result of the sub-target service processing the sub-task is obtained through the second calling thread within the second timeout period, the weight value is increased; wherein the second timeout period is the waiting time for the second calling thread to determine whether to stop calling the sub-target service;
[0024] When the processing result of the task processed by the sub-target service is not received through the second calling thread within the second timeout period, the weight value is reduced.
[0025] In an exemplary embodiment, when the state description data is the time taken for the sub-target service to return the processing result of the sub-task, determining, according to the state description data, that the sub-target service is in an abnormal state or a normal state includes:
[0026] Obtaining the time taken by the sub-target service to return each processing result of the sub-task;
[0027] According to the time taken for each processing result, obtaining the average time taken for the sub-target service to return multiple processing results of the sub-task within a preset time interval;
[0028] When the average time consumed is greater than or equal to a preset indicator threshold, it is determined that the sub-target service is in an abnormal state;
[0029] When the average time consumption is less than the preset indicator threshold, it is determined that the sub-target service is in a normal state.
[0030] In an exemplary embodiment, allocating a second calling thread for the sub-target service includes:
[0031] Obtaining a task processing level identifier of the subtask corresponding to the sub-target service;
[0032] According to the task processing level identifier, determining whether the subtask is a first processing level task or a second processing level task; wherein the task importance of the first processing level task is lower than the task importance of the second processing level task;
[0033] When it is determined that the subtask is a first processing level task, allocating the second calling thread to the sub-target service;
[0034] When it is determined that the subtask is a second processing level task, the allocation of the second calling thread to the sub-objective service is refused.
[0035] In an exemplary embodiment, after allocating a second calling thread for the sub-target service, the method further includes:
[0036] During the inter-thread waiting time, the first calling thread receives the processing result of the sub-target service processing the sub-task returned by the second calling thread.
[0037] In an exemplary embodiment, after allocating the first calling thread for the task processing request, the method further includes:
[0038] When it is determined that the sub-target service is in a normal state, the processing result of the sub-target service processing the subtask is obtained through the first calling thread.
[0039] In an exemplary embodiment, the method further comprises:
[0040] When the calls to the multiple sub-target services are completed, the processing results returned by the multiple sub-target services are combined to obtain the task processing result corresponding to the task processing request;
[0041] The task processing result is sent to the request end corresponding to the task processing request.
[0042] According to a second aspect of an embodiment of the present disclosure, a service invocation device is provided, the device comprising:
[0043] A task processing request acquisition unit is configured to execute and acquire a task processing request; the task processing request includes at least one subtask to be processed;
[0044] A sub-goal service determination unit is configured to execute and determine a sub-goal service corresponding to the sub-task; the sub-goal service is used to process the sub-task and return a processing result;
[0045] A first calling thread allocating unit is configured to allocate a first calling thread for the task processing request, wherein the first calling thread is used to call the sub-target services in sequence;
[0046] A second calling thread allocating unit is configured to allocate a second calling thread to the sub-target service when it is determined that the sub-target service is in an abnormal state during the process of the first calling thread calling the sub-target service, wherein the second calling thread is used to replace the first calling thread in calling the sub-target service;
[0047] A continuing calling unit is configured to execute, if the first calling thread fails to receive the processing result of the sub-target service processing the sub-task returned by the second calling thread within a preset inter-thread waiting time, then continue to call the sub-target service corresponding to the next sub-task through the first calling thread; wherein the inter-thread waiting time is less than the first timeout time corresponding to the first calling thread, and the first timeout time is the waiting time for the first calling thread to determine whether to stop calling the sub-target service.
[0048] In an exemplary embodiment, the device also includes: a status description acquisition unit, configured to execute acquisition of status description data of the sub-target service; the status description data is used to characterize the response status of the sub-target service to the subtask; and a response status determination unit, configured to execute, based on the status description data, determining whether the sub-target service is in an abnormal state or a normal state.
[0049] In an exemplary embodiment, when the status description data is a weight value, the weight value is used to characterize the proportion of the number of times the sub-target service is successfully called in the total number of times it is called; the response status determination unit is specifically configured to execute when the weight value is less than a preset threshold, determine that the sub-target service is in an abnormal state; when the weight value is greater than or equal to the preset threshold, determine that the sub-target service is in a normal state.
[0050] In an exemplary embodiment, after the second calling thread is assigned to the sub-target service, the device also includes: a first weight adjustment unit, configured to increase the weight value when the processing result of the sub-target service processing the subtask is obtained through the second calling thread within the second timeout period; wherein the second timeout period is the waiting time for the second calling thread to determine whether to stop calling the sub-target service; and a second weight adjustment unit, configured to reduce the weight value when the processing result of the sub-target service processing the task is not received through the second calling thread within the second timeout period.
[0051] In an exemplary embodiment, when the status description data is the time taken for the sub-target service to return the processing result of the subtask, the response status determination unit is specifically configured to execute the acquisition of the time taken for the sub-target service to return each processing result of the subtask; based on the time taken for each processing result, obtain the average time taken for the sub-target service to return multiple processing results of the subtask within a preset time interval; when the average time taken is greater than or equal to a preset indicator threshold, determine that the sub-target service is in an abnormal state; when the average time taken is less than the preset indicator threshold, determine that the sub-target service is in a normal state.
[0052] In an exemplary embodiment, the second calling thread allocation unit is specifically configured to execute the acquisition of the task processing level identifier of the subtask corresponding to the sub-target service; determine whether the subtask is a first processing level task or a second processing level task based on the task processing level identifier; wherein the task importance of the first processing level task is lower than the task importance of the second processing level task; when it is determined that the subtask is a first processing level task, allocate the second calling thread to the sub-target service; when it is determined that the subtask is a second processing level task, refuse to allocate the second calling thread to the sub-target service.
[0053] In an exemplary embodiment, after allocating a second calling thread to the sub-target service, the device further includes: a result returning unit configured to execute within the inter-thread waiting time, and receive, through the first calling thread, a processing result of the sub-target service processing the subtask returned by the second calling thread.
[0054] In an exemplary embodiment, after allocating a first calling thread for the task processing request, the device further includes: a result acquisition unit configured to execute, when it is determined that the sub-target service is in a normal state, obtaining the processing result of the sub-task processed by the sub-target service through the first calling thread.
[0055] In an exemplary embodiment, the method also includes: a task processing result obtaining unit, which is configured to execute, when calls to multiple sub-target services are completed, combining the processing results returned by the multiple sub-target services to obtain the task processing result corresponding to the task processing request; and a task processing result sending unit, which is configured to execute sending the task processing result to the request end corresponding to the task processing request.
[0056] According to a third aspect of an embodiment of the present disclosure, a server is provided, including:
[0057] processor;
[0058] a memory for storing instructions executable by the processor;
[0059] Among them, the processor is configured to execute the instructions to implement the service calling method described in the embodiment of the first aspect above.
[0060] According to a fourth aspect of an embodiment of the present disclosure, a storage medium is provided. When instructions in the storage medium are executed by a processor of an electronic device, the electronic device can execute the service calling method described in the embodiment of the first aspect above.
[0061] According to a fifth aspect of an embodiment of the present disclosure, a computer program product is provided, the program product comprising a computer program, the computer program being stored in a readable storage medium, at least one processor of a device reading and executing the computer program from the readable storage medium, so that the device executes the service calling method described in any one of the embodiments of the first aspect.
[0062] The technical solution provided by the embodiments of the present disclosure brings at least the following beneficial effects:
[0063] When obtaining a task processing request, determine the sub-target service corresponding to the sub-task in the task processing request, and then assign a first calling thread to the task processing request, so that the first calling thread can call the sub-target service in sequence to complete the processing of the corresponding sub-task and return the processing result. In the process of the first calling thread calling the sub-target service in sequence, if it is determined that the sub-service that the first calling thread is about to call is in an abnormal state, that is, it means that the sub-target service may have a fault and the probability of calling failure is relatively high, then assign a second calling thread to the first calling thread to call the sub-target service through the second calling thread instead of the first calling thread; if the first calling thread fails to receive the processing result of the sub-target service processing sub-task returned by the second calling thread within the preset thread waiting time, then continue to call the sub-target service corresponding to the next sub-task through the first calling thread; wherein, the thread waiting time The waiting time is less than the first timeout time corresponding to the first calling thread, and the first timeout time is the waiting time for the first calling thread to determine whether to stop calling the sub-target service; in this way, when the sub-target service is called by the second calling thread and the first calling thread fails to receive the processing result of the sub-target service processing subtask returned by the second calling thread within the preset waiting time between threads, the first calling thread continues to call the sub-target service corresponding to the next subtask, which can reduce the time waiting for the sub-target service to return the processing result. In the case that there is a high probability of call failure of the sub-target service, long-term blocking can be completely avoided, and the call failure of the sub-target service can be quickly determined. By quickly determining the call failure of the sub-target service, the call of the next sub-target service can be continued, thereby ensuring that other sub-target services can be executed normally, thereby improving the processing efficiency of the entire task processing request.
[0064] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0065] The drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the description are used to explain the principles of the present disclosure, and do not constitute improper limitations on the present disclosure.
[0066] Figure 1The present invention is an application environment diagram of a service calling method according to an exemplary embodiment.
[0067] Figure 2 The figure is a flowchart of a service calling method according to an exemplary embodiment.
[0068] Figure 3 The figure is a block diagram of a service calling device according to an exemplary embodiment.
[0069] Figure 4 The figure is a diagram showing the internal structure of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION
[0070] In order to enable ordinary persons in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings.
[0071] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0072] The service calling method provided by the present disclosure can be applied to Figure 1In the application environment shown, the terminal 102 and the server 104 communicate with the server 106 via a network. Specifically, when the terminal 102 or the server 104 needs to perform task processing, or the server 106 itself needs to perform task processing, a task processing request will be obtained on the server 106; the task processing request includes at least one subtask to be processed; the server 106 determines the sub-target service corresponding to the subtask; the sub-target service is used to process the subtask and return the processing result; a first calling thread is assigned to the task processing request, and the first calling thread is used to call the sub-target service in sequence; in the process of the first calling thread calling the sub-target service, when the server 106 determines that the sub-target service is in an abnormal state, a second calling thread is assigned to the sub-target service, and the second calling thread is used to replace the first calling thread to call the sub-target service; if the first calling thread fails to receive the processing result of the sub-target service processing subtask returned by the second calling thread within the preset thread waiting time, the server 106 continues to call the sub-target service corresponding to the next subtask through the first calling thread; wherein the thread waiting time is less than the first timeout time corresponding to the first calling thread, and the first timeout time is the waiting time for the first calling thread to determine whether to stop calling the sub-target service. The terminal 102 may be, but is not limited to, various personal computers, laptop computers, smart phones, tablet computers, and portable wearable devices, and the server 104 and the server 106 may be implemented as an independent server or a server cluster consisting of multiple servers.
[0073] Figure 2 is a flow chart of a service calling method according to an exemplary embodiment. Figure 2 As shown, the service calling method is applied in the server 106 and includes the following steps.
[0074] In step S210, a task processing request is obtained; the task processing request includes at least one subtask to be processed.
[0075] Among them, services refer to programs, methods or functions deployed on various servers. When a task processing request is obtained on a server, the task in the task processing request can be processed by calling the service and the processing result can be returned.
[0076] In this embodiment, the server may obtain a task processing request sent by another server or terminal, or the server itself may generate a task processing request when it needs to process a task. The task processing request may be a request to access a web page or a request to obtain data.
[0077] When the server receives a task processing request, it will parse the task to be processed from the task processing request. Generally speaking, a task contains multiple subtasks. For example, suppose a task processing request is received to query a user's information. This task request involves two database accesses, one is to access the database containing the user's basic information, and the other is to access the database containing the user's friend information. In this case, this task needs to be split into two subtasks.
[0078] In step S212, the sub-target service corresponding to the sub-task is determined; the sub-target service is used to process the sub-task and return the processing result.
[0079] After the subtasks in the task processing request are disassembled, the subtarget service for processing the subtask will be further determined. After receiving the subtask, the subtarget service will process it according to the task parameters corresponding to the subtask and return a corresponding processing result.
[0080] In step S214, a first calling thread is allocated to the task processing request, and the first calling thread is used to call sub-target services in sequence.
[0081] The call to a service needs to be made through a calling thread. In this embodiment, after the server obtains the task processing request, it can obtain an idle first calling thread in the thread pool, and the first calling thread will be used to complete the call of the sub-target service corresponding to all subtasks in the task processing request in sequence.
[0082] In step S216, during the process of the first calling thread sequentially calling the sub-target service, when it is determined that the sub-target service is in an abnormal state, a second calling thread is allocated to the sub-target service, and the second calling thread is used to replace the first calling thread in calling the sub-target service.
[0083] In this embodiment, in the process of the first calling thread calling the sub-target services in sequence, it is necessary to further determine whether each sub-target service is in an abnormal state. The abnormal state means that the sub-target service may have a fault, and the probability of calling failure when the sub-target service is called is very high.
[0084] In the thread pool of this embodiment, a second calling thread, also called an additional calling thread, is also provided. When it is determined that the sub-target service is in an abnormal state, in order to reduce the time of waiting for the sub-target service to return the processing result, the second calling thread can be allocated to the first calling thread, that is, the calling of the sub-target service in the abnormal state is completed by the second calling thread.
[0085] If it is determined that the sub-target service is not in an abnormal state, that is, it is in a normal state, it means that the probability of successful calling of the sub-target service is very high, so there is no need to use the second calling thread to call the sub-target service. It can be seen that this embodiment does not need to introduce additional resource overhead (second calling thread) when the sub-target service is in a normal state, so that it is not too sensitive to the time consumption caused by network jitter in a normal state, has a certain tolerance, and ensures the call success rate.
[0086] In step S218, if the first calling thread fails to receive the processing result of the sub-target service processing sub-task returned by the second calling thread within the preset inter-thread waiting time, the sub-target service corresponding to the next sub-task will continue to be called through the first calling thread.
[0087] The inter-thread waiting time may refer to the time that the first calling thread waits for the processing result of the sub-target service processing sub-task returned by the second calling thread.
[0088] The waiting time between threads is less than the first timeout time corresponding to the first calling thread.
[0089] The first calling thread has a corresponding first timeout period, i.e., the waiting period for the first calling thread to determine whether to stop calling the sub-target service. When the first calling thread calls the sub-target service to process the sub-task, it waits for the processing result based on the first timeout period. If the processing result is not obtained within the first timeout period, it is determined that the sub-target service call has failed and the calling of the sub-target service is stopped, and the next sub-target service will continue to be called to process the corresponding next sub-task.
[0090] It should be noted that the service call in this embodiment is a synchronous call, that is, when the first calling thread calls the sub-target service to process the sub-task, it is necessary to wait for the sub-target service to return a processing result or after the first timeout period has expired before the next sub-target service can be called.
[0091] In a specific implementation, when it is determined that the sub-target service is in an abnormal state, the second calling thread will replace the first calling thread to call the sub-target service. During the process of the second calling thread calling the sub-target service, the first calling thread will synchronously wait for the calling result of the second calling thread according to the inter-thread waiting time, that is, determine whether the processing result of the sub-target service processing subtask returned by the second calling thread is received within the inter-thread waiting time.
[0092] If the first calling thread fails to obtain the processing result of the sub-target service processing subtask returned by the second calling thread within the waiting time between threads, it will no longer continue to wait for the processing result of the sub-target service processing subtask returned by the first calling thread, but will continue to call the sub-target service corresponding to the next subtask through the first calling thread to continue to execute other subtasks in the task processing request.
[0093] In the above service calling method, when obtaining a task processing request, the sub-target service corresponding to the sub-task in the task processing request is determined, and then a first calling thread is allocated to the task processing request, so that the first calling thread can call the sub-target service in sequence to complete the processing of the corresponding sub-task and return the processing result. In the process of the first calling thread calling the sub-target service in sequence, if it is determined that the sub-service to be called by the first calling thread is in an abnormal state, that is, it means that the sub-target service may have a fault and the probability of call failure is relatively high, then a second calling thread is allocated to the first calling thread to call the sub-target service through the second calling thread instead of the first calling thread; if the first calling thread fails to receive the processing result of the sub-target service processing sub-task returned by the second calling thread within the preset thread waiting time, then the first calling thread continues to call the sub-target service corresponding to the next sub-task through the first calling thread; Among them, the waiting time between threads is less than the first timeout time corresponding to the first calling thread, and the first timeout time is the waiting time for the first calling thread to determine whether to stop calling the sub-target service; in this way, when the sub-target service is called by the second calling thread and the first calling thread fails to receive the processing result of the sub-target service processing subtask returned by the second calling thread within the preset waiting time between threads, the first calling thread continues to call the sub-target service corresponding to the next subtask, which can reduce the time waiting for the sub-target service to return the processing result. In the case that there is a high probability of calling failure of the sub-target service, long-term blocking can be completely avoided, and the calling failure of the sub-target service can be quickly determined. By quickly determining the calling failure of the sub-target service, the calling of the next sub-target service can be continued, thereby ensuring that other sub-target services can be executed normally, thereby improving the processing efficiency of the entire task processing request.
[0094] It should be noted that this embodiment does not directly adjust the first timeout period of the first calling thread and wait for the processing result based on the adjusted first timeout period, but uses another additional thread, namely the second calling thread, to complete the call to the sub-target service and waits for the processing result of the second calling thread within the inter-thread waiting time that is less than the first timeout period corresponding to the first calling thread. By introducing additional threads, the crash of the first calling thread can be avoided, which would affect the calls to other subsequent sub-target services, and the robustness of the system operation can be improved.
[0095] In an exemplary embodiment, before allocating a second calling thread to the sub-target service, the method also includes: obtaining status description data of the sub-target service; the status description data is used to characterize the response status of the sub-target service to the sub-task; and determining whether the sub-target service is in an abnormal state or a normal state based on the status description data.
[0096] In this embodiment, for the remote call of each sub-service, a state description data is maintained, and the availability state of the corresponding sub-service can be determined based on the state description data, that is, whether the sub-service has a fault and the success rate of the call.
[0097] Before allocating the second calling thread to the sub-target service, state description data for characterizing the response state of the sub-target service to the sub-task may also be obtained; then, based on the state description data of the sub-target service, it is determined whether the sub-target service is in an abnormal state or a normal state.
[0098] In an exemplary embodiment, when the status description data is a weight value, the weight value is used to characterize the proportion of the number of times the sub-target service is successfully called in the total number of times it is called; based on the status description data, determine whether the sub-target service is in an abnormal state or a normal state, including: obtaining the status description data of the sub-target service; the status description data is a weight value; the weight value is used to characterize the proportion of the number of times the sub-target service is successfully called in the total number of times it is called; when the weight value is less than a preset threshold, determine that the sub-target service is in an abnormal state; when the weight value is greater than or equal to the preset threshold, determine that the sub-target service is in a normal state.
[0099] Among them, the status description data can be a weight value, which is used to characterize the proportion of the number of times the sub-target service is successfully called in the total number of times it is called. Therefore, for the sub-target service, it can be determined whether the sub-target service is in an abnormal state according to the size of the weight value. Specifically, the larger the weight value, the higher the probability of the sub-target service being called successfully, and the smaller the weight value, the lower the probability of the sub-target service being called successfully.
[0100] In a specific implementation, the weight value corresponding to the sub-target service can be compared with a preset threshold. When it is determined that the weight value corresponding to the sub-target service is less than the preset threshold, it is determined that the sub-target service is in an abnormal state; when it is determined that the weight value corresponding to the sub-target service is greater than or equal to the preset threshold, it is determined that the sub-target service is in an abnormal state.
[0101] For example, for a sub-goal service, such as a sub-goal service for querying user friend information, assuming that the preset threshold is 5, when the weight value is greater than 5, it is determined that the sub-goal service is in a normal state, and when the weight value is less than 5, it is determined that the sub-goal service is in an abnormal state. In this way, by obtaining the state description data corresponding to the sub-goal service, the probability of the corresponding sub-goal service being successfully called can be quickly determined, and then the response state of the sub-goal service to the sub-task can be judged, that is, whether the sub-goal service is in an abnormal state or a normal state. .
[0102] In an exemplary embodiment, after allocating the second calling thread for the sub-target service, the method further includes:
[0103] When the processing result of the sub-target service processing sub-task is obtained through the second calling thread within the second timeout period, the weight value is increased;
[0104] When the processing result of the sub-target service processing task is not received through the second calling thread within the second timeout period, the weight value is reduced.
[0105] The second timeout period is the waiting time for the second calling thread to determine whether to stop calling the sub-target service. That is, when the second calling thread calls the sub-target service to process the subtask, it waits for the processing result based on the second timeout period. If the processing result is not obtained within the second timeout period, the sub-target service is stopped from being called.
[0106] In this embodiment, the state description data of each sub-service is maintained in real time. When the call of a sub-target service in an abnormal state ends, the state description data can be adjusted according to the call result. Specifically, when the sub-target service is successfully called by the second calling thread after the second calling thread is assigned to the sub-target service, that is, the second calling thread obtains the processing result of the sub-target service within the second timeout period, the weight value can be increased, and when the sub-target service fails to be called, that is, the second calling thread does not obtain the processing result of the sub-target service within the second timeout period, the weight value can be reduced.
[0107] Assume that the initial weight value set for a sub-target service is 10, and the preset threshold is 5. If the query of user friend information is successful, the weight value is increased by 1 (cannot exceed 10); if the query of user friend information fails, the weight value is reduced by 1 (cannot be lower than 0).
[0108] In another exemplary embodiment, when the status description data is the time taken for the sub-target service to return the processing result of a sub-task, determining whether the sub-target service is in an abnormal state or a normal state is performed based on the status description data, including: obtaining the time taken for the sub-target service to return each processing result of the sub-task; and based on the time taken for each processing result, obtaining the average time taken for the sub-target service to return multiple processing results of the sub-task within a preset time interval.
[0109] When the average time consumed is greater than or equal to the preset indicator threshold, it is determined that the sub-target service is in an abnormal state;
[0110] When the average time consumed is less than the preset indicator threshold, it is determined that the sub-target service is in a normal state.
[0111] In actual applications, in addition to the above-mentioned method of determining whether it is in an abnormal state based on the weight value corresponding to each sub-service on the server, it can also be determined by the actual time consumed when calling the sub-target service. Specifically, the time consumed by the sub-target service to return each processing result within a preset time interval (such as nearly a week) can be obtained, and then the time consumed for each processing result is averaged to obtain an average time consumed. Then, based on whether the average time consumed is greater than the preset indicator threshold, it is determined whether the sub-target service is in an abnormal state or a normal state. Specifically, when the average time consumed is greater than or equal to the preset indicator threshold, the probability of the sub-target service being called successfully is lower; when the average time consumed is less than the preset indicator threshold, the probability of the sub-target service being called successfully is higher.
[0112] Of course, in addition to the above average time consumption, other time consumption statistical indicators, such as time consumption percentiles, etc., can also be used to determine whether the sub-target service is in an abnormal state or a normal state, and this embodiment does not need to be limited to this.
[0113] In an exemplary embodiment, a second calling thread is assigned to a sub-target service, including: obtaining a task processing level identifier of a sub-task corresponding to the sub-target service; determining whether the sub-task is a first processing level task or a second processing level task based on the task processing level identifier; when the sub-task is determined to be a first processing level task, the second calling thread is assigned to the sub-target service; when the sub-task is determined to be a second processing level task, refusing to assign the second calling thread to the sub-target service.
[0114] Among them, the task importance of the first processing level task is lower than the task importance of the second processing level task.
[0115] In practical applications, the first processing level task can also be named as a secondary task, and the second processing level task can also be named as an important task.
[0116] In actual applications, among the subtasks corresponding to a task processing request task, some subtasks are relatively unimportant and execution failure is allowed, while some subtasks are relatively important and need to be executed successfully as much as possible. Therefore, in this embodiment, a corresponding task processing level identifier is set for each subtask, and according to the identifier, it can be determined whether the subtask is executed successfully as much as possible, that is, whether its corresponding sub-target service needs to be called successfully as much as possible.
[0117] Specifically, when the subtask is determined to be a secondary task based on the task processing level identifier, indicating that it is not necessary to ensure that its corresponding sub-target service is called successfully, a second calling thread can be allocated to the sub-target service, so that the waiting time can be reduced and the result of the failed call of the sub-target service corresponding to the secondary task can be obtained as soon as possible. Then, when the sub-target service fails to be called, the next sub-target service can be called quickly to improve the processing efficiency of the overall task processing request. When the subtask is determined to be an important task based on the task processing level identifier, indicating that it is necessary to ensure that its corresponding sub-target service is called successfully, the allocation of the second calling thread to the sub-target service can be refused, so that the processing result of the important task can be obtained as much as possible.
[0118] In order to make those skilled in the art better understand this example, a specific application scenario is used as an example for explanation. Taking database access as an example, assuming that the task processing request is to query the information of a user, the task processing request needs to involve the access of two databases, that is, there are two subtasks, the first subtask is the access to the database of the user's basic information, and the second subtask is the access to the database of the user's friend information. Assuming that the access to the first database is more important, if the first subtask fails to execute, the entire task processing request is deemed to have failed to execute, but if the second subtask fails to execute, it is also acceptable to return only the first subtask, and at this time, the task processing request can still be regarded as successful execution. This processing method of sacrificing secondary tasks is called service degradation. For the subtasks that can be sacrificed in service degradation, that is, the secondary tasks, if blocking occurs, not only may the entire task processing request fail in the end, but also it is necessary to wait until the timeout time to see the failure result, which is a very poor experience. However, when the secondary task is blocked, it only needs to wait for a short time, and the processing result of the important task can also be obtained.
[0119] Of course, in practical applications, it can also be set that no matter what kind of subtask it is, that is, no matter whether it is an important task or a secondary task, the second calling thread can be allocated to it, and this embodiment does not need to limit this.
[0120] In an exemplary embodiment, after allocating the second calling thread for the sub-target service, the method further includes:
[0121] During the inter-thread waiting time, the processing result of the sub-target service processing sub-task acquired by the second calling thread is received by the first calling thread.
[0122] In this embodiment, when it is determined that the sub-target service is in an abnormal state, the second calling thread will replace the first calling thread to call the sub-target service. When the second calling thread completes calling the sub-target service and waiting for the processing result within the waiting time between threads, the second calling thread returns the processing result to the first calling thread.
[0123] In an exemplary embodiment, after allocating the first calling thread for the task processing request, the method further includes:
[0124] When it is determined that the sub-target service is in a normal state, the processing result of the sub-target service processing subtask is obtained through the first calling thread.
[0125] In this embodiment, when it is determined that the sub-target service is in a normal state, the first calling thread directly calls the sub-target service and obtains the processing result after the sub-target service processes the corresponding subtask. In a normal state, the call is only based on the first calling thread, which can reduce the pressure on the server without introducing additional resource overhead.
[0126] In an exemplary embodiment, the method further comprises:
[0127] When the calls to multiple sub-target services are completed, the processing results returned by the multiple sub-target services are combined to obtain the task processing result corresponding to the task processing request;
[0128] The task processing result is sent to the request end corresponding to the task processing request.
[0129] When the server completes the call to the target service corresponding to all subtasks, it can combine the processing results of all successfully called subtarget services to obtain the task processing result corresponding to the task processing request, and send the task processing result to the request end of the task processing request. The request end can be the server itself, or other servers or terminals.
[0130] It should be understood that although Figure 2 and Figure 3 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 2 and Figure 3At least part of the steps may include multiple steps or multiple stages. These steps or stages are not necessarily performed at the same time, but can be performed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed in turn or alternately with other steps or at least part of the steps or stages in other steps.
[0131] Figure 3 is a block diagram of a service calling device according to an exemplary embodiment. Figure 3 The device includes a task processing request acquisition unit 310, a sub-target service determination unit 312, a first calling thread allocation unit 314, a second calling thread allocation unit 316 and a continuing calling unit 318.
[0132] The task processing request acquisition unit 310 is configured to execute and acquire a task processing request; the task processing request includes at least one subtask to be processed;
[0133] The sub-goal service determination unit 312 is configured to execute and determine the sub-goal service corresponding to the sub-task; the sub-goal service is used to process the sub-task and return the processing result;
[0134] The first calling thread allocating unit 314 is configured to allocate a first calling thread to the task processing request, wherein the first calling thread is used to call the sub-target services in sequence;
[0135] The second calling thread allocating unit 316 is configured to allocate a second calling thread to the sub-target service when it is determined that the sub-target service is in an abnormal state during the process of the first calling thread calling the sub-target service, wherein the second calling thread is used to replace the first calling thread in calling the sub-target service;
[0136] The continue calling unit 318 is configured to execute if the first calling thread fails to receive the processing result of the sub-target service processing the sub-task returned by the second calling thread within the preset inter-thread waiting time, then continue to call the sub-target service corresponding to the next sub-task through the first calling thread; wherein the inter-thread waiting time is less than the first timeout time corresponding to the first calling thread, and the first timeout time is the waiting time for the first calling thread to determine whether to stop calling the sub-target service.
[0137] In an exemplary embodiment, the device also includes: a status description acquisition unit, configured to execute acquisition of status description data of the sub-target service; the status description data is used to characterize the response status of the sub-target service to the subtask; and a response status determination unit, configured to execute, based on the status description data, determining whether the sub-target service is in an abnormal state or a normal state.
[0138] In an exemplary embodiment, when the status description data is a weight value, the weight value is used to characterize the proportion of the number of times the sub-target service is successfully called in the total number of times it is called; the response status determination unit is specifically configured to execute when the weight value is less than a preset threshold, determine that the sub-target service is in an abnormal state; when the weight value is greater than or equal to the preset threshold, determine that the sub-target service is in a normal state.
[0139] In an exemplary embodiment, after the second calling thread is assigned to the sub-target service, the device also includes: a first weight adjustment unit, configured to increase the weight value when the processing result of the sub-target service processing the subtask is obtained through the second calling thread within the second timeout period; wherein the second timeout period is the waiting time for the second calling thread to determine whether to stop calling the sub-target service; and a second weight adjustment unit, configured to reduce the weight value when the processing result of the sub-target service processing the task is not received through the second calling thread within the second timeout period.
[0140] In an exemplary embodiment, when the status description data is the time taken for the sub-target service to return the processing result of the subtask, the response status determination unit is specifically configured to execute the acquisition of the time taken for the sub-target service to return each processing result of the subtask; based on the time taken for each processing result, obtain the average time taken for the sub-target service to return multiple processing results of the subtask within a preset time interval; when the average time taken is greater than or equal to a preset indicator threshold, determine that the sub-target service is in an abnormal state; when the average time taken is less than the preset indicator threshold, determine that the sub-target service is in a normal state.
[0141] In an exemplary embodiment, the second calling thread allocation unit 316 is specifically configured to execute the acquisition of the task processing level identifier of the subtask corresponding to the sub-target service; determine whether the subtask is a first processing level task or a second processing level task based on the task processing level identifier; wherein the task importance of the first processing level task is lower than the task importance of the second processing level task; when it is determined that the subtask is a first processing level task, allocate the second calling thread to the sub-target service; when it is determined that the subtask is a second processing level task, refuse to allocate the second calling thread to the sub-target service.
[0142] In an exemplary embodiment, after allocating a second calling thread to the sub-target service, the device further includes: a result returning unit configured to execute within the inter-thread waiting time, and receive, through the first calling thread, a processing result of the sub-target service processing the subtask returned by the second calling thread.
[0143] In an exemplary embodiment, after allocating a first calling thread for the task processing request, the device further includes: a result acquisition unit configured to execute, when it is determined that the sub-target service is in a normal state, obtaining the processing result of the sub-task processed by the sub-target service through the first calling thread.
[0144] In an exemplary embodiment, the device also includes: a task processing result obtaining unit, which is configured to execute, when completing calls to multiple sub-target services, combining the processing results returned by the multiple sub-target services to obtain the task processing result corresponding to the task processing request; and a task processing result sending unit, which is configured to execute sending the task processing result to the request end corresponding to the task processing request.
[0145] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0146] Figure 4 FIG. 4 is a block diagram of a device 400 for calling a service according to an exemplary embodiment. For example, the device 400 may be a server. Figure 4 , the device 400 includes a processing component 420, which further includes one or more processors, and a memory resource represented by a memory 422 for storing instructions that can be executed by the processing component 420, such as an application. The application stored in the memory 422 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 420 is configured to execute instructions to perform the above-mentioned service call method.
[0147] The device 400 may also include a power supply component 424 configured to perform power management of the device 400, a wired or wireless network interface 426 configured to connect the device 400 to a network, and an input / output (I / O) interface 428. The device 400 may operate based on an operating system stored in the memory 422, such as Windows 44erver, MacO 4X, Unix, Linux, FreeB 4D or the like.
[0148] In an exemplary embodiment, a storage medium including instructions is also provided, such as a memory 422 including instructions, which can be executed by a processor of the device 400 to perform the above method. The storage medium can be a non-transitory computer-readable storage medium, for example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0149] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.
[0150] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A service calling method, characterized in that: The method comprises: Obtaining a task processing request; the task processing request includes at least one subtask to be processed; Determine a sub-target service corresponding to the sub-task; the sub-target service is used to process the sub-task and return a processing result; Allocating a first calling thread to the task processing request, wherein the first calling thread is used to call the sub-target services in sequence; In the process of the first calling thread calling the sub-target service, when it is determined that the sub-target service is in an abnormal state, a second calling thread is allocated to the sub-target service, and the second calling thread is used to replace the first calling thread to call the sub-target service; including: when the subtask is a secondary task, the second calling thread is allocated to the sub-target service; when the subtask is an important task, the second calling thread is refused to be allocated to the sub-target service; If the first calling thread fails to receive the processing result of the sub-target service processing the sub-task returned by the second calling thread within the preset inter-thread waiting time, the first calling thread continues to call the sub-target service corresponding to the next sub-task; the inter-thread waiting time is less than the first timeout time corresponding to the first calling thread, and the first timeout time is the waiting time for the first calling thread to determine whether to stop calling the sub-target service; wherein the service call is a synchronous call; the first calling thread calls the sub-target service corresponding to the next sub-task after waiting for the sub-target service to return the processing result or after the first timeout time has expired.
2. The service calling method according to claim 1, characterized in that: Before allocating the second calling thread to the sub-target service, the method further comprises: Acquire state description data of the sub-target service; the state description data is used to characterize the response state of the sub-target service to the sub-task; According to the state description data, it is determined whether the sub-target service is in an abnormal state or a normal state.
3. The service calling method according to claim 2, characterized in that: When the state description data is a weight value, the weight value is used to represent the proportion of the number of times the sub-target service is successfully called in the total number of times the sub-target service is called; The determining, according to the state description data, that the sub-target service is in an abnormal state or a normal state includes: When the weight value is less than a preset threshold, determining that the sub-target service is in an abnormal state; When the weight value is greater than or equal to a preset threshold, it is determined that the sub-target service is in a normal state.
4. The service calling method according to claim 3, characterized in that: After allocating the second calling thread to the sub-target service, the method further comprises: When the processing result of the sub-target service processing the sub-task is obtained through the second calling thread within the second timeout period, the weight value is increased; wherein the second timeout period is the waiting time for the second calling thread to determine whether to stop calling the sub-target service; When the processing result of the task processed by the sub-target service is not received through the second calling thread within the second timeout period, the weight value is reduced.
5. The service calling method according to claim 2, characterized in that: When the state description data is the time taken for the sub-target service to return the processing result of the sub-task, determining, according to the state description data, that the sub-target service is in an abnormal state or a normal state includes: Obtaining the time taken by the sub-target service to return each processing result of the sub-task; According to the time taken for each processing result, obtaining the average time taken for the sub-target service to return multiple processing results of the sub-task within a preset time interval; When the average time consumed is greater than or equal to a preset indicator threshold, it is determined that the sub-target service is in an abnormal state; When the average time consumption is less than the preset indicator threshold, it is determined that the sub-target service is in a normal state.
6. The service calling method according to claim 1, characterized in that: The allocating a second calling thread for the sub-target service comprises: Obtaining a task processing level identifier of the subtask corresponding to the sub-target service; According to the task processing level identifier, the subtask is determined to be the secondary task or the important task; wherein the task importance of the secondary task is lower than the task importance of the important task.
7. The service calling method according to claim 1, characterized in that: After allocating the second calling thread to the sub-target service, the method further comprises: During the inter-thread waiting time, the first calling thread receives the processing result of the sub-target service processing the sub-task returned by the second calling thread.
8. The service calling method according to claim 1, characterized in that: After allocating the first calling thread for the task processing request, the method further includes: When it is determined that the sub-target service is in a normal state, the processing result of the sub-target service processing the subtask is obtained through the first calling thread.
9. The service calling method according to claim 1, characterized in that: The method further comprises: When the calls to the multiple sub-target services are completed, the processing results returned by the multiple sub-target services are combined to obtain the task processing result corresponding to the task processing request; The task processing result is sent to the request end corresponding to the task processing request.
10. A service calling device, characterized in that: The device comprises: A task processing request acquisition unit is configured to execute and acquire a task processing request; the task processing request includes at least one subtask to be processed; A sub-goal service determination unit is configured to execute and determine a sub-goal service corresponding to the sub-task; the sub-goal service is used to process the sub-task and return a processing result; A first calling thread allocating unit is configured to allocate a first calling thread for the task processing request, wherein the first calling thread is used to call the sub-target services in sequence; A second calling thread allocating unit is configured to allocate a second calling thread to the sub-target service when it is determined that the sub-target service is in an abnormal state during the process of the first calling thread calling the sub-target service, wherein the second calling thread is used to replace the first calling thread in calling the sub-target service; The second calling thread allocating unit is specifically used to allocate the second calling thread to the sub-target service when the sub-task is a secondary task; and refuse to allocate the second calling thread to the sub-target service when the sub-task is an important task; A continuing calling unit is configured to execute, if the first calling thread fails to receive the processing result of the sub-target service processing the sub-task returned by the second calling thread within a preset inter-thread waiting time, then continue to call the sub-target service corresponding to the next sub-task through the first calling thread; the inter-thread waiting time is less than the first timeout time corresponding to the first calling thread, and the first timeout time is the waiting time for the first calling thread to determine whether to stop calling the sub-target service; wherein the service call is a synchronous call; the first calling thread calls the sub-target service corresponding to the next sub-task after waiting for the sub-target service to return a processing result or after the first timeout time has expired.
11. The service calling device according to claim 10, characterized in that: The device also includes: a status description acquisition unit, configured to execute acquisition of status description data of the sub-target service; the status description data is used to characterize the response status of the sub-target service to the subtask; and a response status determination unit, configured to execute, based on the status description data, determining whether the sub-target service is in an abnormal state or a normal state.
12. The service calling device according to claim 11, characterized in that: When the status description data is a weight value, the weight value is used to characterize the proportion of the number of times the sub-target service is successfully called in the total number of times it is called; the response status determination unit is specifically configured to execute when the weight value is less than a preset threshold, determine that the sub-target service is in an abnormal state; when the weight value is greater than or equal to the preset threshold, determine that the sub-target service is in a normal state.
13. The service calling device according to claim 12, characterized in that: After the second calling thread is assigned to the sub-target service, the device also includes: a first weight adjustment unit, configured to increase the weight value when the processing result of the sub-target service processing the subtask is obtained through the second calling thread within the second timeout period; wherein the second timeout period is the waiting time for the second calling thread to determine whether to stop calling the sub-target service; and a second weight adjustment unit, configured to reduce the weight value when the processing result of the sub-target service processing the task is not received through the second calling thread within the second timeout period.
14. The service calling device according to claim 11, characterized in that: When the state description data is the time taken for the sub-target service to return the processing result of the sub-task, the response state determination unit is specifically configured to execute the acquisition of the time taken for the sub-target service to return each processing result of the sub-task; According to the time taken for each processing result, obtaining the average time taken for the sub-target service to return multiple processing results of the sub-task within a preset time interval; When the average time consumed is greater than or equal to a preset indicator threshold, it is determined that the sub-target service is in an abnormal state; when the average time consumed is less than the preset indicator threshold, it is determined that the sub-target service is in a normal state.
15. The service calling device according to claim 10, characterized in that: The second calling thread allocation unit is specifically configured to execute the task processing level identifier of the subtask corresponding to the sub-target service; determine whether the subtask is the secondary task or the important task according to the task processing level identifier; wherein the task importance of the secondary task is lower than the task importance of the important task.
16. The service calling device according to claim 10, characterized in that: After allocating the second calling thread to the sub-target service, the device also includes: a result returning unit, which is configured to execute within the waiting time between the threads and receive the processing result of the sub-target service processing the subtask returned by the second calling thread through the first calling thread.
17. The service calling device according to claim 10, characterized in that: After allocating the first calling thread for the task processing request, the device further includes: a result acquisition unit configured to execute, when it is determined that the sub-target service is in a normal state, to acquire the processing result of the sub-task processed by the sub-target service through the first calling thread.
18. The service calling device according to claim 10, characterized in that: The device also includes: a task processing result obtaining unit, which is configured to execute, when completing the call to multiple sub-target services, combining the processing results returned by the multiple sub-target services to obtain the task processing result corresponding to the task processing request; and a task processing result sending unit, which is configured to execute sending the task processing result to the request end corresponding to the task processing request.
19. A server, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the service calling method as described in any one of claims 1 to 9.
20. A storage medium, when instructions in the storage medium are executed by a processor of a server, enables the server to execute the service calling method according to any one of claims 1 to 9.
Citation Information
Patent Citations
Socket thread pool design method oriented to multi-terminal wireless communication
CN106997307A
Service calling method and device
CN110231981A
