Task processing method and device, electronic equipment and storage medium
By using session reference counters to track task processing in distributed or microservice programs, the problems of low task processing performance and high development difficulty in the existing technology are solved, and high-performance asynchronous programming interface task processing is realized, reducing development difficulty and Automatically complete related business.
Patent Information
- Application Number
- CN202411522791.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-29
- Publication Date
- 2025-02-18
AI Technical Summary
In the development of distributed or microservice programs, the task processing performance based on synchronous programming interfaces is low in the prior art, while the programming model based on asynchronous programming interfaces is complex logic, and the development and implementation are difficult, and there is a lack of development and implementation difficulty. A method for low programming model and high-performance task processing under this programming model.
By receiving the target request task, create a target session object, including a session reference counter, determine multiple subtasks to be called for processing, count increase and decrease processing for each subtask through the session reference counter, call the subtask and receive the result, according to The sub-call result determines the target call result, and returns the result to the request task object, and finally destroys the session object.
It realizes high-performance task processing under the programming model of asynchronous programming interface, reduces the difficulty of development and implementation, automatically completes session synchronization, data caching and resource management and other services, and improves RPC processing capabilities.
Smart Images

Figure CN119473543A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer application technology, and in particular to a task processing method, device, electronic device and storage medium. Background Art
[0002] Currently, in distributed or microservice program development, tasks often use Remote Procedure Calls (RPCs) to obtain results. Typically, the Application Programming Interface (API) of an RPC framework includes both synchronous and asynchronous programming interfaces.
[0003] In the related technologies, task processing based on the programming model of the synchronous programming interface has the problem of low task processing performance, and task processing based on the programming model of the asynchronous programming interface has the problem of complex programming model logic and greater difficulty in development and implementation. Therefore, there is currently a lack of a programming model with low development and implementation difficulty, and a method for high-performance task processing under the programming model. Summary of the Invention
[0004] The present invention provides a task processing method, device, electronic device and storage medium to solve the current lack of a programming model with low development and implementation difficulty, and a method for performing high-performance task processing under the programming model.
[0005] According to one aspect of the present invention, a task processing method is provided, wherein the method comprises:
[0006] Receive a target request task, and create a target session object corresponding to the target request task, wherein the target session object includes a session reference counter;
[0007] Determine a plurality of subtasks required to be called to process the target request task;
[0008] For each of the subtasks to be called, incrementing a target reference count by using a session reference counter to obtain a first reference count, and calling the subtask to be called; and receiving a subcall result of the subtask, and for each received subcall result, decrementing the target reference count by using a session reference counter to obtain a second reference count, wherein the target reference count includes at least one of the original reference count, the first reference count, and the second reference count;
[0009] When the second reference count reaches a target count value, determining a target call result according to the plurality of sub-call results;
[0010] The target call result is returned to the target request object corresponding to the target request task, and the target session object is destroyed.
[0011] According to another aspect of the present invention, a task processing device is provided, wherein the device includes:
[0012] A session creation module, configured to receive a target request task and create a target session object corresponding to the target request task, wherein the target session object includes a session reference counter;
[0013] A calling task determination module is used to determine a plurality of subtasks required to be called to process the target request task;
[0014] a counting processing module, configured to, for each of the subtasks to be called, increase a target reference count by using a session reference counter to obtain a first reference count, and call the subtask to be called; and, receive a subcall result of the subtask, and for each received subcall result, decrease the target reference count by using a session reference counter to obtain a second reference count, wherein the target reference count includes at least one of an original reference count, the first reference count, and the second reference count;
[0015] a call result determining module, configured to determine a target call result according to the plurality of sub-call results when the second reference count reaches a target count value;
[0016] The result returning module is used to return the target call result to the target request object corresponding to the target request task and destroy the target session object.
[0017] According to another aspect of the present invention, an electronic device is provided, comprising:
[0018] at least one processor; and
[0019] a memory communicatively connected to the at least one processor; wherein,
[0020] The memory stores a computer program that can be executed by the at least one processor. The computer program is executed by the at least one processor to enable the at least one processor to perform the task processing method described in any embodiment of the present invention.
[0021] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the task processing method described in any embodiment of the present invention when executed.
[0022] The technical solution of the embodiment of the present invention is to receive a target request task, create a target session object corresponding to the target request task, wherein the target session object includes a session reference counter; determine multiple subtasks required to call the target request task; for each subtask to be called, increase the target reference count through the session reference counter to obtain a first reference count, and call the subtask to be called; and receive a subcall result of the subtask, and for each received subcall result, decrease the target reference count through the session reference counter to obtain a second reference count, wherein the target reference count includes at least one of the original reference count, the first reference count, and the second reference count; when the second reference count reaches the target count value, determine the target call result based on the multiple subcall results; return the target call result to the target request object corresponding to the target request task, and destroy the target session object. The present invention adopts a task processing method that tracks tasks through session objects, realizing high-performance task processing under the programming model of the asynchronous programming interface of remote procedure call.
[0023] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present invention, nor is it intended to limit the scope of the present invention. Other features of the present invention will become readily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0025] Figure 1 is a programming model framework diagram of a synchronous programming interface provided according to an embodiment of the present invention;
[0026] Figure 2 This is a programming model framework diagram of an asynchronous programming interface provided according to an embodiment of the present invention;
[0027] Figure 3 This is a target programming model framework diagram of an asynchronous programming interface based on session tracking according to an embodiment of the present invention;
[0028] Figure 4 This is a flowchart of a task processing method provided according to the first embodiment of the present invention;
[0029] Figure 5 A schematic diagram of the structure of a target session object provided by an embodiment of the present invention;
[0030] Figure 6 This is a flowchart of a task processing method provided according to the second embodiment of the present invention;
[0031] Figure 7 A flow chart of increasing a session reference count provided by an embodiment of the present invention;
[0032] Figure 8 A flow chart of reducing the count of session references provided by an embodiment of the present invention;
[0033] Figure 9 This is a structural diagram of a task processing device provided according to a third embodiment of the present invention;
[0034] Figure 10 It is a structural diagram of an electronic device for implementing the task processing method according to an embodiment of the present invention. DETAILED DESCRIPTION
[0035] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present invention.
[0036] It should be noted that the terms "first", "second", etc. in the description and claims of the present invention 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 numbers used in this way can be interchanged where appropriate so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0037] In distributed or microservice program development, tasks usually obtain results through remote procedure calls (RPCs).
[0038] A typical RPC call scenario involves one task (the master task) accepting a request from another task (the requesting task), then invoking multiple other tasks (subtasks) via RPC to obtain the results, and finally returning the results. The programming of the master task is crucial to the entire system.
[0039] Common RPC framework application programming interfaces (APIs) include synchronous programming interfaces and asynchronous programming interfaces, such as Figure 1 and Figure 2 As shown, Figure 1 is a programming model framework diagram of a synchronous programming interface provided according to an embodiment of the present invention; Figure 2 This is a programming model framework diagram of an asynchronous programming interface provided according to an embodiment of the present invention.
[0040] Programming model for synchronous programming interfaces, Figure 1 In the code, rpc_call and rpc_recv are general forms of synchronous interfaces, representing the calling and receiving functions, respectively. get_result represents the main control task's business program, specifically, it calculates the result of the requested task based on the results obtained from the subtasks. This model suffers from the problem of blocking while waiting for the result during synchronous calls, resulting in low task execution efficiency.
[0041] Programming model for asynchronous programming interfaces, Figure 2 Among them, rpc_async_call, rpc_async_recv, rpc_async_reply, and rpc_async_call_callback are general forms of asynchronous interfaces, where
[0042] rpc_async_call is an asynchronous call interface that does not block waiting for the call result. The call result is obtained from the callback interface rpc_async_call_callback.
[0043] rpc_async_recv can be used to receive asynchronous call requests. This process does not directly return the call request result, but can be returned through the rpc_async_reply interface.
[0044] rpc_async_reply is used to return the result of an asynchronous call request.
[0045] rpc_async_call_callback is used to obtain the return result of the asynchronous call.
[0046] The asynchronous programming interface programming model separates the calling request and receiving processes and can be executed concurrently. RPC requests do not need to block and wait, and task execution is efficient. However, the programming model is complex and difficult to develop, requiring developers to handle multiple process synchronization, data caching, and resource allocation and release.
[0047] Based on the programming model of asynchronous programming interface, this paper develops a target programming model of RPC asynchronous programming interface based on session tracking, which abstracts complex business logic into a unified framework. Figure 3 As shown, Figure 3 This is a target programming model framework diagram of an asynchronous programming interface based on session tracking provided according to an embodiment of the present invention.
[0048] Figure 3 The session can represent the RPC session object. In the master task, the entire process from receiving the RPC request of the request task -> initiating calls to each subtask -> receiving callbacks from the subtask call -> returning the final result of the request task is defined as an RPC session, or simply a session.
[0049] Specifically, the general steps for task processing based on this programming model include: 1. When the session starts, create a session object (session_create), and destroy the session object before the session ends (session_destroy). 2. Increase the session reference count (session_ref) before asynchronously calling each subtask, and reduce the session reference count (session_unref) at the end of each asynchronous call callback. 3. Each time the session reference count is reduced, check whether the count has returned to 0. 4. When the session reference count returns to 0, it means that all subtask calls have been completed, and execute rpc_async_reply to return the asynchronous call request result. 5. Execute session_ref once before calling all subtasks to avoid some subtasks asynchronously calling callbacks earlier than other subtasks, thereby detecting that the session reference count has returned to 0, causing the session to end prematurely before completion.
[0050] When a distributed or microservice program developed based on the programming model framework of the present invention performs task processing, the following effects can be achieved: 1. The asynchronous call process is non-blocking. 2. Services such as session synchronization, data caching, and resource management are automatically implemented without the developer having to perform self-processing, reducing the complexity of asynchronous programming. 3. The programming model of the asynchronous programming interface based on session tracking can be reused and developed in distributed or microservice business scenarios, and has strong versatility. Taking the master control task of the target programming model as the execution subject, the specific steps for task processing in a distributed or microservice program developed based on this programming model are explained below.
[0051] Example 1
[0052] Figure 4 A flowchart of a task processing method is provided for the first embodiment of the present invention. This embodiment is applicable to the case where task processing is performed through a programming model of an asynchronous programming interface based on session tracking. The method can be executed by a task processing device, which can be implemented in the form of hardware and / or software and can be configured in a computer. Figure 4 As shown, the method includes:
[0053] S110: Receive a target request task, and create a target session object corresponding to the target request task, wherein the target session object includes a session reference counter.
[0054] The target request task can be understood as a target request task. In the embodiment of the present invention, the target request task can be related to the actual application scenario and is not specifically limited here. Optionally, the target request task can be a data read and write task, etc.
[0055] The target session object can be understood as a session object created for the target request task. In an embodiment of the present invention, the target session object created for the target request task can track the processing of the target request task and complete the services such as session synchronization, data caching, and resource management involved in the processing of the target request task.
[0056] Figure 5 A schematic diagram of the structure of a target session object provided by an embodiment of the present invention. Figure 5 As shown, optionally, the structure of the target session object may include the session reference counter, the synchronization lock, the data storage, and the request identifier, etc. Ref may represent the session reference counter, lock may represent the synchronization lock, reply_info may represent the request identifier, and data_cache may represent the data storage.
[0057] The session reference counter can be used to count session references. In the implementation of the present invention, before calling the subtask or after returning the subtask's subcall result, the target session object is referenced once. At this time, the real-time count value can be increased or decreased by the session reference counter.
[0058] S120: Determine a plurality of subtasks required to be called to process the target request task.
[0059] The subtasks may be understood as tasks required to process the target request task. For example, the multiple subtasks required to process different target request tasks may be the same or different. For example, the subtasks corresponding to the target request task may include subtask 1, subtask 2, and subtask 3.
[0060] S130. For each subtask to be called, increase the target reference count through the session reference counter to obtain a first reference count, and call the subtask to be called; and receive the subcall result of the subtask, and for each received subcall result, decrease the target reference count through the session reference counter to obtain a second reference count, wherein the target reference count includes at least one of the original reference count, the first reference count, and the second reference count.
[0061] The original reference count can be understood as the original reference count or the default reference count. In an embodiment of the present invention, the original reference count can be preset according to the scenario requirements and is not specifically limited here. For example, the original reference count can be 0.
[0062] The first reference count may be understood as a reference count obtained after a count-increment process, and the second reference count may be understood as a reference count obtained after a count-decrement process.
[0063] The target reference count may be understood as an object of count increase or decrease processing. In an embodiment of the present invention, the target reference count may include at least one of an original reference count, a first reference count, and a second reference count.
[0064] In the embodiment of the present invention, the reference count may be understood as a count value related to the number of times the target session object is referenced. The reference count may be determined by counting the session reference counter.
[0065] In an embodiment of the present invention, count increase processing and count decrease processing can be executed in no particular order, that is, specifically, first, determine the first subtask to be called, perform count increase processing on the original reference count through the session reference counter to obtain a first reference count, and call the subtask to be called; then, if the second subtask to be called is determined first, perform count increase processing on the first reference count through the session reference counter to obtain an updated first reference count; if the subcall result of the first subtask to be called is received first, perform count decrease processing on the first reference count through the session reference counter to obtain a second reference count; then, use the updated first reference count or the second reference count as the target reference count; further, return to the target reference count and execute the count increase processing or count decrease processing operation until the last second reference count reaches the target count value.
[0066] The sub-call result can be understood as the result obtained by calling the sub-task. In the embodiment of the present invention, one sub-task can correspond to one sub-call result.
[0067] Optionally, the step of incrementing the target reference count by using a session reference counter to obtain a first reference count includes:
[0068] Determine the preset counting unit value;
[0069] The target reference count is incremented using the session reference counter and the counting unit value to obtain a first reference count.
[0070] The counting unit value can be understood as a unit value for counting increase or decrease. In the embodiment of the present invention, the counting unit value can be preset according to the scenario requirements and is not specifically limited here. For example, the counting unit value can be 1.
[0071] Optionally, the step of reducing the target reference count by using a session reference counter to obtain a second reference count may include:
[0072] The target reference count is decremented using the session reference counter and the counting unit value to obtain a second reference count.
[0073] S140. When the second reference count reaches a target count value, determine a target call result according to the multiple sub-call results.
[0074] The target count value can be understood as a counting threshold. In the embodiment of the present invention, the target count value can be preset according to the scenario requirements and is not specifically limited here. Optionally, the target count value can be the same as or different from the original reference count. Exemplarily, the target count value can be 0.
[0075] In the embodiment of the present invention, the second reference count is a target count value, which indicates that the calling of all the subtasks has been completed and the sub-call results corresponding to all the subtasks have been obtained.
[0076] Optionally, after receiving the sub-call result of the subtask, the method further includes:
[0077] caching the sub-call result by using the data storage corresponding to the target session object;
[0078] Determining the target call result according to the multiple sub-call results includes:
[0079] A plurality of sub-call results are obtained through the data storage, and a target call result is determined according to the plurality of sub-call results.
[0080] The target session object further includes a data buffer that can be used to store relevant data during task processing.
[0081] The target call result can be understood as the processing result corresponding to the target request task.
[0082] S150: Return the target call result to the target request object corresponding to the target request task, and destroy the target session object.
[0083] The target request object may be understood as the object that initiates the target request task. Optionally, the target request object may be a target terminal.
[0084] Optionally, the target session object further includes a request identifier; and after the target request receiving task, further includes:
[0085] Identifying the task request address of the target request task by the request identifier;
[0086] The step of returning the target call result to the target request object corresponding to the target request task includes:
[0087] The target call result is returned to the target request object corresponding to the target request task through the task request address.
[0088] The request identifier may be used to identify the request information corresponding to the target request task.
[0089] The task request address can be understood as the request address of the target request task. The task request address can correspond to one target request object.
[0090] Optionally, after destroying the target session object, the method further includes:
[0091] Releases data cached by the data memory.
[0092] The data cached by the data memory may include at least one of a reference count, a call result, and a task request address.
[0093] The technical solution of the embodiment of the present invention is to receive a target request task, create a target session object corresponding to the target request task, wherein the target session object includes a session reference counter; determine multiple subtasks required to call the target request task; for each subtask to be called, increase the target reference count through the session reference counter to obtain a first reference count, and call the subtask to be called; and receive a subcall result of the subtask, and for each received subcall result, decrease the target reference count through the session reference counter to obtain a second reference count, wherein the target reference count includes at least one of the original reference count, the first reference count, and the second reference count; when the second reference count reaches the target count value, determine the target call result based on the multiple subcall results; return the target call result to the target request object corresponding to the target request task, and destroy the target session object. The present invention adopts a task processing method that tracks tasks through session objects, realizing high-performance task processing under the programming model of the asynchronous programming interface of remote procedure call.
[0094] Example 2
[0095] Figure 6 This is a flowchart of a task processing method provided by the second embodiment of the present invention. This embodiment is to add to the counting process of the original reference count by the session reference counter described in the above embodiment. Figure 6 As shown, the method includes:
[0096] S210: Receive a target request task, and create a target session object corresponding to the target request task, wherein the target session object includes a session reference counter.
[0097] S220: Determine a plurality of subtasks required to be called to process the target request task.
[0098] Figure 7A flow chart of increasing a session reference count is provided in an embodiment of the present invention. Specific steps are shown in S230, where lock represents a synchronization lock and ref value represents a reference count.
[0099] S230: For each subtask to be called, obtain the synchronization lock, increase the target reference count through the session reference counter to obtain a first reference count, and release the synchronization lock.
[0100] Optionally, the target session object further includes a synchronization lock. In an embodiment of the present invention, the synchronization lock can be used to control the asynchronous execution of the counting process. That is, this can avoid counting errors caused by simultaneously counting the target reference count for different pending subtasks or different received subcall results.
[0101] S240: Receive a sub-call result of the sub-task, and for each received sub-call result, reduce the target reference count using a session reference counter to obtain a second reference count.
[0102] The synchronization lock is used to control the asynchronous execution of the counting process.
[0103] Figure 8 A flowchart of reducing the session reference count provided by an embodiment of the present invention is shown below, where lock represents a synchronization lock and ref value represents a reference count.
[0104] Optionally, the receiving the sub-call result of the sub-task and, for each received sub-call result, reducing the target reference count by using a session reference counter to obtain a second reference count may include:
[0105] The sub-call result of the sub-task is received, the synchronization lock is obtained, and for each received sub-call result, the target reference count is reduced by a session reference counter to obtain a second reference count, and the synchronization lock is released.
[0106] In the technical solution of the present invention, since the increase and decrease calculations of the reference count may be executed concurrently, the present invention first obtains a synchronization lock before the reference count is increased or decreased, and releases the synchronization lock after the operation is completed, thereby avoiding the concurrent execution of the reference count, which may cause confusion in the reference count calculation, ensuring the asynchronous execution of the counting processing, and ensuring the accuracy of the reference count calculation.
[0107] In the technical solution of the present invention, the target reference count is cached before the synchronization lock is released to facilitate the acquisition and processing of the target reference count next time.
[0108] Optionally, the target session object further includes a data storage device, and before releasing the synchronization lock, further includes:
[0109] Using the first reference count as the target reference count, and caching the target reference count in the data memory;
[0110] Before the target reference count is reduced by the session reference counter, the method further includes:
[0111] The target reference count is obtained through the data memory.
[0112] Optionally, before releasing the synchronization lock, the method further includes:
[0113] The second reference count is used as the target reference count, and the target reference count is cached in the data memory.
[0114] S250. When the second reference count reaches a target count value, determine a target call result according to the multiple sub-call results.
[0115] S260: Return the target call result to the target request object corresponding to the target request task, and destroy the target session object.
[0116] The technical solution of the embodiment of the present invention obtains the synchronization lock before incrementing the target reference count using the session reference counter, wherein the synchronization lock is used to control the asynchronous execution of the counting process; and releases the synchronization lock after obtaining the first reference count. This avoids the situation where concurrent reference counting may cause confusion in reference count calculation, ensures asynchronous execution of the counting process, and guarantees the accuracy of reference count calculation.
[0117] The following further describes the technical solution of running to buy that based on the above embodiment.
[0118] 1. Regarding the session object structure. Session reference counter: It can be used to count how many asynchronous requests there are currently. When the reference count is 0, it means that all asynchronous requests have been completed. Synchronous lock: The present invention may initiate asynchronous calls to multiple subtasks at the same time. Therefore, the present invention obtains the synchronous lock before operating the reference count and releases the synchronous lock after completing the operation. The request identifier is used to record the address or proxy information of the RPC requester. When a session starts, the session records the request address and other information. Before the session ends, the information is obtained from the session to return the request result to the requester. Data storage, the session object of the present invention encapsulates a cache that can access data in a key-value manner, so that multiple asynchronous processes in the session can cache data.
[0119] 2. Interface functions for session objects. The interface of the session object of the present invention may include: session_ccreate, used to create a session object and initialize session object data; session_destroy, used to destroy the session object and release the data cache; session_reply_set, used to record the address information of the RPC request; session_reply_get, used to obtain the address information of the RPC request; session_ref, used to increase the reference count and return the current count; session_unref, used to decrease the reference count and return the current count; session_data_set, used to cache data using key-value parameters; session_data_get, used to obtain value data from the cache using a key.
[0120] 3. The process of receiving a request task. Specifically, when receiving an RPC request (i.e., the target request task), a session object is first created; before asynchronously calling all subtasks, a reference count is first increased to ensure that all asynchronous callbacks are executed before the session ends; the session object records the request address; before executing the asynchronous call to the subtask, a reference count is increased; the asynchronous call is executed on the subtask, and the callback interface and the session object are passed as parameters to the asynchronous call process; after completing the asynchronous call to all subtasks, the reference count is decremented; and it is determined whether the current reference count is 0. If all asynchronous calls to the subtasks have completed the callback (i.e., the call results are received), the session ends.
[0121] 4. Request result return process. Specifically, obtain the results returned by all asynchronous calls from the session object data cache; calculate the final result based on the results of all subtask asynchronous calls; obtain the request reply address from the session object; return the final result to the caller through the reply address; and destroy the session object.
[0122] 5. Obtain the session object by passing parameters from the callback interface. Specifically, obtain the session object by passing parameters from the callback interface; save the asynchronous call return data of the callback interface into the session object data cache; decrement the session reference count; and determine whether the current reference count is 0. If the reference count is 0, the session ends.
[0123] Based on the technical solution of the embodiment of the invention, the RPC processing capability can be improved through non-blocking operations during the RPC asynchronous call process; the asynchronous programming model based on session tracking that implements the technical solution of the present invention can be reused and developed in distributed or microservice business scenarios; the present invention tracks the asynchronous call process of multiple subtasks based on reference counting, thereby achieving business effects such as automatic completion of session synchronization, data caching, and resource management.
[0124] Example 3
[0125] Figure 9 This is a structural diagram of a task processing device provided by the third embodiment of the present invention. Figure 9 As shown, the apparatus includes: a session creation module 310 , a calling task determination module 320 , a counting processing module 330 , a calling result determination module 340 and a result returning module 350 .
[0126] Among them, the session creation module 310 is used to receive a target request task and create a target session object corresponding to the target request task, wherein the target session object includes a session reference counter; the calling task determination module 320 is used to determine multiple subtasks required to be called to process the target request task; the counting processing module 330 is used to increase the target reference count by using the session reference counter for each subtask to be called to obtain a first reference count, and call the subtask to be called; and receive the subcall result of the subtask, and for each received subcall result, decrease the target reference count by using the session reference counter to obtain a second reference count, wherein the target reference count includes at least one of the original reference count, the first reference count, and the second reference count; the calling result determination module 340 is used to determine the target call result based on the multiple subcall results when the second reference count reaches the target count value; the result return module 350 is used to return the target call result to the target request object corresponding to the target request task and destroy the target session object.
[0127] The technical solution of the embodiment of the present invention is to receive a target request task, create a target session object corresponding to the target request task, wherein the target session object includes a session reference counter; determine multiple subtasks required to call the target request task; for each subtask to be called, increase the target reference count through the session reference counter to obtain a first reference count, and call the subtask to be called; and receive a subcall result of the subtask, and for each received subcall result, decrease the target reference count through the session reference counter to obtain a second reference count, wherein the target reference count includes at least one of the original reference count, the first reference count, and the second reference count; when the second reference count reaches the target count value, determine the target call result based on the multiple subcall results; return the target call result to the target request object corresponding to the target request task, and destroy the target session object. The present invention adopts a task processing method that tracks tasks through session objects, realizing high-performance task processing under the programming model of the asynchronous programming interface of remote procedure call.
[0128] Optionally, the target session object further includes a synchronization lock; the counting processing module 330 includes: a synchronization lock acquisition unit and a synchronization lock release unit; wherein,
[0129] The synchronization lock acquisition unit is configured to acquire the synchronization lock before performing a count increment process on the target reference count through the session reference counter, wherein the synchronization lock is used to control asynchronous execution of the counting process;
[0130] The synchronization lock releasing unit is configured to release the synchronization lock after obtaining the first reference count.
[0131] Optionally, the target session object further includes a data memory; the count processing module 330 further includes: a count storage unit, configured to use the first reference count as the target reference count before releasing the synchronization lock, and cache the target reference count through the data memory;
[0132] The counting processing module 330 further includes: a counting obtaining unit, configured to obtain the target reference count through the data memory before performing count reduction processing on the target reference count through the session reference counter.
[0133] Optionally, the counting processing module 330 further includes: a result storage unit, configured to cache the sub-call result of the subtask in a data storage corresponding to the target session object after receiving the sub-call result of the subtask;
[0134] The call result determination module 340 is specifically configured to obtain a plurality of the sub-call results through the data storage device, and determine a target call result according to the plurality of the sub-call results.
[0135] Optionally, the target session object further includes a request identifier; the session creation module 310 includes an address identification unit for identifying the task request address of the target request task through the request identifier after receiving the target request task;
[0136] The result returning module 350 is specifically configured to return the target call result to the target request object corresponding to the target request task through the task request address.
[0137] Optionally, the task processing device further includes: a data releasing module, configured to release the data cached by the data storage after the target session object is destroyed.
[0138] Optionally, the counting processing module 330 includes: a counting unit determining unit and a counting increasing unit;
[0139] Wherein, the counting unit determining unit is used to determine a preset counting unit value;
[0140] The count increasing unit is used to perform count increasing processing on the target reference count by using the session reference counter and the count unit value to obtain a first reference count.
[0141] The task processing device provided by the embodiment of the present invention can execute the task processing method provided by any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0142] Example 4
[0143] Figure 10 A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or claimed herein.
[0144] like Figure 10 As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., which is communicatively connected to the at least one processor 11. The memory stores a computer program that can be executed by the at least one processor. The processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 into the random access memory (RAM) 13. Various programs and data required for the operation of the electronic device 10 can also be stored in the RAM 13. The processor 11, ROM 12, and RAM 13 are connected to each other via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0145] Multiple components in the electronic device 10 are connected to the I / O interface 15, including an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a magnetic disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.
[0146] The processor 11 may be any general-purpose and / or specialized processing component with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various specialized artificial intelligence (AI) computing chips, various processors that run machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as the task processing method.
[0147] In some embodiments, the task processing method can be implemented as a computer program that is tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program can be loaded and / or installed on electronic device 10 via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the task processing method described above can be performed. Alternatively, in other embodiments, processor 11 can be configured to perform the task processing method in any other appropriate manner (e.g., by means of firmware).
[0148] Various embodiments of the systems and techniques described herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), system-on-chip systems (SOCs), programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include being implemented in one or more computer programs that are executable and / or interpreted on a programmable system that includes at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0149] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when the computer program is executed by the processor, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The computer program may be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0150] In the context of the present invention, computer-readable storage media can be tangible media that can contain or store a computer program for use with an instruction execution system, device or equipment or used in combination with an instruction execution system, device or equipment. Computer-readable storage media can include but are not limited to electronic, magnetic, optical, electromagnetic, infrared or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, computer-readable storage media can be machine-readable signal media. More specific examples of machine-readable storage media can include electrical connections based on one or more lines, portable computer disks, hard disks, random access memories (RAM), read-only memories (ROM), erasable programmable read-only memories (EPROM or flash memory), optical fibers, portable compact disk read-only memories (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0151] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0152] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0153] A computing system may include clients and servers. The clients and servers are typically remote from each other and typically interact via a communication network. This client-server relationship arises through computer programs running on the respective computers, creating a client-server relationship. The server may be a cloud server, also known as a cloud computing server or cloud host. This server is a hosting product within the cloud computing service ecosystem that addresses the management difficulties and limited scalability of traditional physical hosting and VPS services.
[0154] It should be understood that the various forms of the processes shown above can be used to reorder, add, or delete steps. For example, the steps described in the present invention can be performed in parallel, sequentially, or in a different order, as long as the desired results of the technical solution of the present invention can be achieved. This is not limited herein.
[0155] The above specific embodiments do not limit the scope of protection of the present invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions may be made based on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention are intended to be included within the scope of protection of the present invention.
Claims
1. A task processing method, characterized in that: include: Receive a target request task, and create a target session object corresponding to the target request task, wherein the target session object includes a session reference counter; Determine a plurality of subtasks required to be called to process the target request task; For each of the subtasks to be called, the target reference count is increased by using the session reference counter to obtain a first reference count, and the subtask to be called is called; and, the subcall result of the subtask is received, and for each of the received subcall results, the target reference count is decreased by using the session reference counter to obtain a second reference count, wherein the target reference count includes at least one of the original reference count, the first reference count, and the second reference count; When the second reference count reaches the target count value, determining a target call result according to the plurality of sub-call results; The target call result is returned to the target request object corresponding to the target request task, and the target session object is destroyed.
2. The method according to claim 1, characterized in that The target session object also includes a synchronization lock; before the target reference count is increased by the session reference counter, it also includes: Acquiring the synchronization lock, wherein the synchronization lock is used to control asynchronous execution of counting processing; After obtaining the first reference count, the method further includes: The synchronization lock is released.
3. The method according to claim 2, characterized in that The target session object also includes a data storage device; and before releasing the synchronization lock, it also includes: Using the first reference count as the target reference count, and caching the target reference count in the data memory; Before the target reference count is reduced by the session reference counter, the method further includes: The target reference count is obtained through the data storage.
4. The method according to claim 1, characterized in that: After receiving the sub-call result of the sub-task, the method further includes: caching the sub-call result by using a data storage device corresponding to the target session object; The determining the target call result according to the plurality of sub-call results comprises: The plurality of sub-call results are acquired through the data storage device, and the target call result is determined according to the plurality of sub-call results.
5. The method according to claim 1, characterized in that The target session object also includes a request identifier; after the receiving target request task, it also includes: Identifying the task request address of the target request task by the request identifier; The step of returning the target call result to the target request object corresponding to the target request task includes: The target call result is returned to the target request object corresponding to the target request task through the task request address.
6. The method according to claim 1, characterized in that After destroying the target session object, the method further includes: Releases data cached by the data memory.
7. The method according to claim 1, characterized in that The step of increasing the target reference count by using the session reference counter to obtain a first reference count includes: Determine a preset counting unit value; The target reference count is incremented by using the session reference counter and the counting unit value to obtain a first reference count.
8. A task processing device, characterized in that: include: A session creation module, used for receiving a target request task and creating a target session object corresponding to the target request task, wherein the target session object includes a session reference counter; A calling task determination module is used to determine a plurality of subtasks required to be called to process the target request task; A counting processing module is used to increase the target reference count through the session reference counter for each subtask to be called, obtain a first reference count, and call the subtask to be called; and receive the subcall result of the subtask, and for each received subcall result, reduce the target reference count through the session reference counter to obtain a second reference count, wherein the target reference count includes at least one of the original reference count, the first reference count, and the second reference count; A call result determination module, configured to determine a target call result according to a plurality of the sub-call results when the second reference count reaches a target count value; The result returning module is used to return the target calling result to the target request object corresponding to the target request task, and destroy the target session object.
9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can perform the task processing method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the task processing method according to any one of claims 1 to 7 when executed.