Task execution method and device, computer equipment and storage medium
By querying and broadcasting the hash value of the task script in the cache library on the script execution side, and obtaining the target execution results, the problem of multiple script users frequently executing the same script is solved, reducing the task burden of the operation and maintenance platform and improving processing efficiency.
Patent Information
- Application Number
- CN202411664529.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-20
- Publication Date
- 2025-03-07
AI Technical Summary
In automated operation and maintenance, multiple script users run the same idempotent scripts within a similar time, resulting in frequent query and calculation, occupying a large number of network and computing resources, and increasing the task burden of the operation and maintenance platform.
The cache library is introduced on the script execution side, and a query request is generated through the hash value of the task script, and the query request is broadcast to the other script execution side, obtain the target execution result, and feedback it to the management side as the execution result of the task to be executed.
By reducing the execution process of the script execution side, the target execution results in the cache library are directly obtained, which reduces the task burden of the operation and maintenance platform, improves the feedback speed of task execution results, and improves processing efficiency.
Smart Images

Figure CN119576497A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of big data operation and maintenance platforms, and in particular to a task execution method, apparatus, computer equipment and storage medium. Background Art
[0002] In automated operation and maintenance, scripts such as Bash or Python are usually used. Some scripts are only used for query or calculation, and do not rewrite the stored data, so they are idempotent. Idempotence means that no matter how many times an operation is executed, the effect it produces is the same as the effect of executing it once.
[0003] In relevant scenarios, the demand for automated operation and maintenance and the division of labor have divided operation and maintenance personnel into script providers and script users. The formation and expansion of the division of labor have also caused the following problems: In many cases, different script users will run the same idempotent script at a similar time, and the execution results of these scripts are the same; some idempotent scripts are even executed more frequently, and these scripts may need to query a large amount of data and calculate statistics, which will occupy a lot of network and computing resources, thereby placing a heavy task burden on the operation and maintenance platform.
[0004] Therefore, how to reduce the task burden of the operation and maintenance platform is an urgent problem that needs to be solved. Summary of the invention
[0005] Based on this, it is necessary to provide a task execution method, device, computer equipment and storage medium that can reduce the task burden of the operation and maintenance platform in response to the above technical problems.
[0006] In a first aspect, the present application provides a task execution method, which is applied to a script execution end, and each of the script execution ends is associated with a cache library, and the method includes:
[0007] When receiving the task to be executed sent by the management end, the task to be executed is parsed to obtain the hash value of the task script corresponding to the task to be executed;
[0008] If the target execution result corresponding to the hash value of the task script is not found in the associated cache library, a query request is generated based on the hash value of the task script, and the query request is broadcast to the remaining script execution ends, and query results fed back by the remaining script execution ends based on the query request are received;
[0009] If it is determined that the target execution result exists in each of the query results, the target execution result is used as the execution result of the task to be executed, and the execution result of the task to be executed is fed back to the management end.
[0010] In one embodiment, the method further comprises:
[0011] If it is determined that the target execution result does not exist in each of the query results, the task script is retrieved based on the hash value of the task script, the task script is executed and the execution result is obtained, and the execution result is fed back to the management end;
[0012] Associating the execution result with the hash value of the task script, and writing the execution result as a historical execution result into an associated cache library;
[0013] A timer is associated with the historical execution result, and a tag of the historical execution result is set to be exclusive.
[0014] In one embodiment, the method further comprises:
[0015] Receive a query request, obtain a target hash value from the query request, and query a historical execution result corresponding to the target hash value from an associated cache library; the query request is initiated by any one of the remaining script execution terminals;
[0016] If the historical execution result corresponding to the target hash value is queried from the associated cache library, the historical execution result corresponding to the target hash value is fed back to the initiator of the query request as the request result;
[0017] If the historical execution result corresponding to the target hash value is not queried from the associated cache library, first information is fed back to the initiator of the query request, and the first information indicates that there is no historical execution result corresponding to the target hash value.
[0018] In one embodiment, feeding back the execution result corresponding to the target hash value as a request result to the initiator of the query request includes:
[0019] If the tag of the request result is exclusive, the tag of the request result is modified to shared in the associated cache library, and the request result after the tag is modified is fed back to the initiator of the query request;
[0020] If the tag of the request result is shared, the execution result corresponding to the target hash value in the associated cache library is fed back to the initiator of the query request as the request result.
[0021] In one embodiment, before broadcasting the query request to the remaining script execution terminals, the method further includes:
[0022] If a refresh request for the task to be executed is received, the task script is retrieved based on the hash value of the task script, the task script is executed and an execution result is obtained, and the execution result is fed back to the management end, and the refresh request represents the immediate execution of the task to be executed;
[0023] Generate an invalidation request based on the hash value of the task script, and broadcast the invalidation request to the remaining script execution terminals, wherein the invalidation request is used to indicate that the label of the historical execution result pointed to by the hash value in the invalidation request is modified to invalid;
[0024] If feedback information from the remaining script execution terminals is received, the execution result is written into the associated cache library as a historical execution result, and the label of the historical execution result is modified to be exclusive.
[0025] In one embodiment, the method further comprises:
[0026] Upon receiving an invalidation request, determining whether the associated cache library contains a historical execution result pointed to by the hash value in the invalidation request;
[0027] If it exists, the label of the historical execution result pointed to by the hash value in the invalidation request is modified to invalid, and the second information is fed back to the initiator of the invalidation request as feedback information; the second information indicates that the label modification is successful;
[0028] If not, the third information is fed back to the initiator of the invalidation request; the third information indicates that the historical execution result pointed to by the hash value in the invalidation request does not exist.
[0029] In one embodiment, the method further comprises:
[0030] After broadcasting any request to the remaining script execution terminals, determining the script execution terminal that has not fed back information within a preset feedback cycle as a failed execution terminal, and obtaining the identity information of the failed execution terminal;
[0031] The identity information of the failed execution end is fed back to the management end, and the identity information is used to instruct the management end to delete the failed execution end based on the identity information.
[0032] In a second aspect, the present application further provides a task execution device, each script execution end is associated with a cache library, and the device includes a parsing module, a broadcasting module and a feedback module, wherein:
[0033] The parsing module is used to parse the to-be-executed task upon receiving the to-be-executed task sent by the management terminal, and obtain the hash value of the task script corresponding to the to-be-executed task;
[0034] A broadcast module, for generating a query request based on the hash value of the task script if the target execution result corresponding to the hash value of the task script is not found in the associated cache library, broadcasting the query request to the remaining script execution ends, and receiving the query results fed back by the remaining script execution ends based on the query request;
[0035] A feedback module is used for, if it is determined that the target execution result exists in each of the query results, using the target execution result as the execution result of the task to be executed, and feeding back the execution result of the task to be executed to the management end.
[0036] In a third aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0037] When receiving the task to be executed sent by the management end, the task to be executed is parsed to obtain the hash value of the task script corresponding to the task to be executed;
[0038] If the target execution result corresponding to the hash value of the task script is not found in the associated cache library, a query request is generated based on the hash value of the task script, and the query request is broadcast to the remaining script execution ends, and query results fed back by the remaining script execution ends based on the query request are received;
[0039] If it is determined that the target execution result exists in each of the query results, the target execution result is used as the execution result of the task to be executed, and the execution result of the task to be executed is fed back to the management end.
[0040] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the following steps are implemented:
[0041] When receiving the task to be executed sent by the management end, the task to be executed is parsed to obtain the hash value of the task script corresponding to the task to be executed;
[0042] If the target execution result corresponding to the hash value of the task script is not found in the associated cache library, a query request is generated based on the hash value of the task script, and the query request is broadcast to the remaining script execution ends, and query results fed back by the remaining script execution ends based on the query request are received;
[0043] If it is determined that the target execution result exists in each of the query results, the target execution result is used as the execution result of the task to be executed, and the execution result of the task to be executed is fed back to the management end.
[0044] In a fifth aspect, the present application further provides a computer program product, including a computer program, which implements the following steps when executed by a processor:
[0045] When receiving the task to be executed sent by the management end, the task to be executed is parsed to obtain the hash value of the task script corresponding to the task to be executed;
[0046] If the target execution result corresponding to the hash value of the task script is not found in the associated cache library, a query request is generated based on the hash value of the task script, and the query request is broadcast to the remaining script execution ends, and query results fed back by the remaining script execution ends based on the query request are received;
[0047] If it is determined that the target execution result exists in each of the query results, the target execution result is used as the execution result of the task to be executed, and the execution result of the task to be executed is fed back to the management end.
[0048] The above-mentioned task execution method, device, computer equipment and storage medium, for a script execution end, when receiving a task to be executed, it does not first execute the task to be executed, but generates a query request based on the hash value of the task script obtained by parsing the task to be executed, and broadcasts the query request to the remaining script execution ends, and determines whether there is a target execution result (a historical execution result that is the same as the hash value of the task script and is in a valid state) in the cache library associated with the remaining script execution ends according to the query results of the remaining script execution ends. When it is determined that the target execution result exists, that is, at least one of the remaining script execution ends has recently executed the task script and obtained the corresponding execution result (target execution result). Since the task script has idempotence, the target execution result can be directly fed back to the management end as the execution result of the task script; that is, through the task execution method of the present application, the process of the script execution end executing the task script can be omitted, and the corresponding execution result can be obtained directly by broadcasting the query request to the remaining script execution ends, thereby reducing the task burden of the operation and maintenance platform, and also improving the feedback speed of the execution result of the task to be executed, thereby accelerating the processing efficiency of the task. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related technologies, the drawings required for use in the embodiments or the related technical descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0050] Figure 1 An application environment diagram of a task execution method in an embodiment;
[0051] Figure 2 A flowchart of a task execution method in an embodiment;
[0052] Figure 3 A schematic diagram of a flow chart of the script execution end executing task script steps in one embodiment;
[0053] Figure 4 A schematic diagram of a flow chart of a script execution end executing a query request in one embodiment;
[0054] Figure 5 A schematic diagram of a flow chart of a script execution end executing an invalidation request in one embodiment;
[0055] Figure 6 A schematic diagram of a change in a label of a historical execution result in an embodiment;
[0056] Figure 7 is a structural block diagram of a task execution device in one embodiment;
[0057] Figure 8 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0058] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0059] The task execution method provided in the embodiment of the present application can be applied to Figure 1In the application environment shown. Among them, the management end can assign tasks to be executed to each script execution end. After receiving the tasks to be executed, the script execution end feeds back the execution results of the target script in the tasks to be executed to the management end, and the management end processes the execution results accordingly. Among them, the management end communicates with each connected script execution end through the network, and each script execution end can also communicate with each other through the network. The data storage system can store the data that the management end needs to process, and the data storage system can be integrated on the server, or it can be placed on the cloud or other network servers. Each script execution end is associated with a cache library for caching the execution results of the corresponding script. Among them, the management end and each script execution end can be configured on the same computing device, or on different computing and devices. Computer devices can be, but are not limited to, various personal computers, laptops, smart phones, tablet computers, Internet of Things devices, portable wearable devices, and servers, etc.; wherein, the Internet of Things device can be a smart speaker, a smart TV, a smart air conditioner, a smart car-mounted device, etc.; the portable wearable device can be a smart watch, a smart bracelet, a head-mounted device, etc.; the server can be implemented with an independent server or a server cluster composed of multiple servers.
[0060] In an exemplary embodiment, Figure 2 As shown, a task execution method is provided, which is applied to Figure 1 The script execution end in FIG. 1 is taken as an example to illustrate, including steps 110 to 130, wherein:
[0061] Step 110: When receiving the task to be executed sent by the management end, the task to be executed is parsed to obtain the hash value of the task script corresponding to the task to be executed.
[0062] For the embodiment of the present application, the task to be executed is sent by the management end, and the management end sends the task to be executed to each script execution end based on the hash ring, wherein the hash ring includes the hash value of each script and the hash value corresponding to each script execution end; that is, the hash ring represents the mapping relationship between each script execution end and the corresponding script. The hash value of each script is obtained based on the same hash algorithm, and the type of hash algorithm is not specifically limited in the embodiment of the present application.
[0063] Among them, the task to be executed may include one task script, or two or more task scripts. In the case that the task to be executed includes only one task script, when the current management end receives a task to be executed, it determines the task script required for the task to be executed, and determines the hash value corresponding to the task script; or the task to be executed includes the corresponding hash value of the task script. The management end determines the script execution end corresponding to the hash value from the hash ring based on the hash value, and then sends the task to be executed to the script execution end corresponding to the hash value, and then receives the script execution result fed back by the script execution end. In the case that the task to be executed includes two or more task scripts, when the current management end receives a task to be executed, it parses each task script in the task to be executed and determines the hash value of each task script; further, it determines the execution priority of each task script, and then assigns the task based on the hash value of the task script with the highest execution priority. For example, there are two task scripts S1 and S2 in a task to be executed. In the hash ring, the hash value of S1 corresponds to the script execution end A, and the hash value of S2 corresponds to the script execution end B; but the execution priority of S1 is higher than that of S2, so the task to be executed will be assigned to the script execution end A.
[0064] When the current script execution end receives the task to be executed sent by the management end, it parses the task to be executed and obtains the hash value of the task script corresponding to the task to be executed; or performs hash calculation on the task script in the task to be executed through a hash algorithm to obtain the hash value of the task script. It should be noted that in the embodiment of the present application, each script is an idempotent script.
[0065] Step 120: If the target execution result corresponding to the hash value of the task script is not found in the associated cache library, a query request is generated based on the hash value of the task script, and the query request is broadcast to the remaining script execution ends, and query results fed back by the remaining script execution ends based on the query request are received.
[0066] For the embodiment of the present application, the execution results generated by the scripts executed by each script execution terminal are stored as a historical execution result in the associated cache library; and each historical execution result is associated with the hash value of the corresponding script. When the current script execution terminal determines the hash value of the task script in the task to be executed, it first queries the cache library associated with the current script execution terminal based on the hash value of the task script to determine whether there is a historical execution result with the same hash value as the task script in the cache library, that is, whether there is a target execution result.
[0067] In the case where there is only one task script in the task to be executed, if the current script execution end is a new load balancing end added to the management end, the current script execution end cannot query the target execution result corresponding to the hash value of the task script in the associated cache library. For example, the management end was originally connected to three script execution ends A, B, and C, among which script execution end C was kicked out of the load balancing end by the management end due to a fault. At the same time, the management end will introduce a new script execution end D to join and update the hash ring. Assuming that the update rule of the hash ring is to directly modify the hash value corresponding to the script execution end C to correspond to the script execution end D, the management end will directly assign the task to be executed originally assigned to the script execution end C to the script execution end D. Since the script execution end D is a new load balancing end added to the management end, when receiving the task to be executed, the script execution end D cannot query the target execution result corresponding to the hash value of the task script in the associated cache library.
[0068] When there are at least two task scripts in the task to be executed, regardless of whether the current script execution end is a new load balancing addition to the management end, the current script execution end cannot query the target execution result corresponding to the hash value of each task script in the associated cache library. For example, the current script execution end is A, and the script corresponding to A in the hash ring of the management end is S1; the task to be executed received by the current task script execution end A contains task scripts S1 and S2; when the current script execution end A has not obtained the historical execution result corresponding to S2, the current script execution end A cannot find the target execution result corresponding to task script S2 in the associated cache library.
[0069] The above is an example of a situation where the current script execution end cannot find the target execution results corresponding to the hash values of all task scripts in the associated cache library; if the target execution results do not exist in the cache library associated with the current script execution end, the script execution end generates a query request based on the hash value of the task script, and then broadcasts the query request to the remaining script execution ends connected to the management end.
[0070] Step 130: If it is determined that there is a target execution result in each query result, the target execution result is used as the execution result of the task to be executed, and the execution result of the task to be executed is fed back to the management end; wherein the target execution result is a historical execution result of a valid state obtained by the target script execution end from the associated cache library, and the hash value of the script associated with the target execution result is the same as the hash value of the task script in the query request, and the valid state indicates that the remaining life of the historical execution result is not 0.
[0071] For the embodiment of the present application, for any of the remaining script execution terminals, when receiving a query request, the hash value in the query request is used as the target hash value, and the execution result corresponding to the target hash value is queried from the associated cache library; if the historical execution result corresponding to the target hash value is queried from the associated cache library, the validity of the historical execution result is determined, and when it is determined to be valid, the historical execution result corresponding to the target hash value is fed back to the initiator of the query request as the request result; if it is determined that the historical execution result corresponding to the target hash value is invalid, or if the execution result corresponding to the target hash value is not queried from the associated cache library, the first information is fed back to the initiator of the query request, and the first information indicates that the target execution result does not exist. In addition, the current script execution terminal also writes the target execution result into the associated cache library.
[0072] For any historical execution result, when the associated timer indicates that its remaining life is not 0 and its tag is not invalid, it indicates that the historical execution result is in a valid state.
[0073] After the current script execution end broadcasts the query request to the other basic execution ends, the query results of the other script execution ends are received. For the script execution end without the target execution result, the query result fed back to the current script execution end is the first information; for the script execution end with the target execution result, the query result fed back to the current script execution end is the target execution result (the historical execution result with the same hash value as the task script). The current script execution end feeds back the target execution result in the received query result to the management end as the execution result corresponding to the task script in the task to be executed.
[0074] In the above-mentioned task execution method, for a script execution end, when it receives a task to be executed, it does not first execute the task to be executed, but generates a query request based on the hash value of the task script obtained by parsing the task to be executed, and broadcasts the query request to the remaining script execution ends, and determines whether there is a target execution result (a historical execution result that is the same as the hash value of the task script and is in a valid state) in the cache library associated with the remaining script execution ends according to the query results of the remaining script execution ends. When it is determined that there is a target execution result, that is, at least one of the remaining script execution ends has recently executed the task script and obtained the corresponding execution result (target execution result). Since the task script has idempotence, the target execution result can be directly fed back to the management end as the execution result of the task script; that is, through the task execution method of the present application, the process of the script execution end executing the task script can be omitted, and the corresponding execution result can be obtained directly by broadcasting the query request to the remaining script execution ends, thereby reducing the task burden of the operation and maintenance platform, and also improving the feedback speed of the execution result of the task to be executed, thereby speeding up the processing efficiency of the task.
[0075] Further, in one embodiment, referring to Figure 3 If the current script execution end determines that the target execution result does not exist in each query result, the task execution method provided in the embodiment of the present application further includes steps 140 to 160, wherein:
[0076] Step 140: If it is determined that the target execution result does not exist in each query result, the task script is retrieved based on the hash value of the task script, the task script is executed and the execution result is obtained, and the execution result is fed back to the management end.
[0077] Specifically, if the current script execution end determines that the target execution result does not exist in each query result, the current script execution end calls the task script based on the hash value of the task script, executes the task script and obtains the execution result, and feeds back the execution result to the management end.
[0078] Step 150: Associating the execution result with the hash value of the task script, and writing the execution result as a historical execution result into the associated cache library;
[0079] Step 160: Associate a timer with the historical execution result, and set the label of the historical execution result to exclusive.
[0080] Specifically, after the current script execution end executes the task script and obtains the execution result of the task script, it associates the hash value of the task script with the execution result, and then writes the execution result of the task script as a historical execution result into the cache library associated with the current script execution end. In addition, when any historical execution result is written into the cache library, a timer is set for the historical execution result, and the tag of the historical execution result is set to exclusive. Among them, the timer is used to represent the remaining life of the historical execution result, and the complete life represented by the timer of each historical execution result can be the same or different.
[0081] Further, refer to Figure 4 When the current script execution end receives the query request, the task execution method provided by the embodiment of the present application further includes steps 210 to 230, wherein:
[0082] Step 210: Receive a query request, obtain a target hash value from the query request, and query the historical execution result corresponding to the target hash value from the associated cache library; the initiator of the query request is any one of the remaining script execution terminals.
[0083] Specifically, when the current script execution end receives a query request sent by another script execution end, the hash value in the received query request is used as the target hash value, and then based on the target hash value, a query is performed from the cache library associated with the current script execution end to determine whether there is a hash value of a historical execution result in the cache library that is the same as the target hash value. The query request also includes an identifier of the initiator of the query request, which may be an IP (Internet Protocol, a protocol for interconnecting networks) address or an ID (Identification).
[0084] Step 220: If the historical execution result corresponding to the target hash value is queried from the associated cache library, the historical execution result corresponding to the target hash value is fed back to the initiator of the query request as the request result;
[0085] Step 230: If the historical execution result corresponding to the target hash value is not queried from the associated cache library, first information is fed back to the initiator of the query request, and the first information indicates that there is no historical execution result corresponding to the target hash value.
[0086] Specifically, if the current script execution end queries from the associated cache based on the target hash value, and does not find the historical execution result corresponding to the target hash value in the associated cache, then the current script execution end feeds back the first information as the request information corresponding to the query request to the initiator of the query request based on the identifier in the query request. The content of the first information is not specifically limited in the embodiment of the present application, but the first information indicates that there is no historical execution result corresponding to the target hash value in the current basic execution end.
[0087] Specifically, if the current script execution end queries the historical execution result corresponding to the target hash value in the associated cache library, it determines whether the historical execution result corresponding to the target hash value is in a valid state, that is, determines the remaining life and label of the historical execution result, and determines whether the historical execution result is in a valid state. Among them, when it is determined that the remaining life of the historical execution result is not 0, and the label of the historical execution result is not invalid, it is determined that the historical execution result is in a valid state, and the historical execution result is determined as the request result corresponding to the query request.
[0088] Furthermore, if the tag of the request result is exclusive, the tag of the request result is modified to shared in the associated cache library, and the request result after the tag is modified is fed back to the initiator of the query request. If the tag of the request result is shared, the execution result corresponding to the target hash value in the associated cache library is fed back to the initiator of the query request as the request result. Among them, for the historical execution results with the tag of exclusive, it indicates that the historical execution result does not exist in the cache library associated with other script execution ends; for the historical execution results with the tag of shared, it indicates that the historical execution result exists in at least the cache libraries associated with two script execution ends.
[0089] Further, in one embodiment, referring to Figure 5 The step of executing the refresh request may specifically include steps 310 to 330, wherein:
[0090] Step 310: If a refresh request for the task to be executed is received, the task script is retrieved based on the hash value of the task script, the task script is executed and the execution result is obtained, and the execution result is fed back to the management end. The refresh request indicates that the task to be executed is executed immediately.
[0091] Specifically, the refresh request represents a user request to immediately execute the task, that is, for the current script execution end, if a refresh request for the task to be executed is received when the task to be executed is received, the current script execution end does not execute the method of steps 110 to 130, but directly executes the method of steps 140 to 160. That is, the current script execution end immediately executes the task script in the task to be executed based on the refresh request, thereby obtaining the execution result of the task script, and then feeds back the execution result obtained by executing the task script to the management end.
[0092] Step 320: Generate an invalidation request based on the hash value of the task script, and broadcast the invalidation request to the remaining script execution terminals. The invalidation request is used to indicate that the label of the historical execution result pointed to by the hash value in the invalidation request is modified to invalid;
[0093] Step 330: If feedback information is received from other script execution terminals, the execution result is written into the associated cache library as a historical execution result, and the label of the historical execution result is modified to exclusive.
[0094] Specifically, since the current script execution end directly executes the task script based on the refresh request without querying the cache library associated with the current script execution end and the other script execution ends; therefore, the execution result of the task script executed by the current script execution end may exist in the cache library of the current script execution end as a historical execution result, or exist in the cache library associated with the other script execution ends as a historical execution result. Therefore, since the current script execution end has executed the task script and obtained the latest execution result of the latest task script, the current script execution end needs to generate an invalidation request based on the hash function of the task script and broadcast it to the other script execution ends. The invalidation request is used to instruct the other script execution ends to modify the label of the historical execution result pointed to by the hash value in the invalidation request to invalid.
[0095] When any script execution end receives an invalidation request, it needs to execute the invalidation request and send feedback information to the initiator of the invalidation request. Furthermore, if the current script execution end receives feedback information sent by each script execution end, it means that the labels of the historical execution results with the same hash value as the task script in other script execution ends have been modified to invalid. Therefore, the current script execution end writes the latest execution result obtained by executing the task script as a historical execution result into the associated cache library, and sets an exclusive label for the written historical execution result.
[0096] The above steps 310 to 330 are the process of the current script execution end sending an invalidation request to the other script execution ends; the embodiment of the present application further describes the steps that the current script execution end needs to perform when receiving an invalidation request sent by other script execution ends, wherein:
[0097] When the current script execution end receives an invalidation request, it determines whether the historical execution result pointed to by the hash value in the invalidation request exists in the associated cache library; if it is determined that the historical execution result pointed to by the hash value in the invalidation request exists in the associated cache library, the label of the historical execution result pointed to by the hash value in the invalidation request is modified to invalid, and the second information is fed back to the initiator of the invalidation request as feedback information; the second information indicates that the label modification is successful; if it is determined that the historical execution result pointed to by the hash value in the invalidation request does not exist in the associated cache library, the third information is fed back to the initiator of the invalidation request; the third information indicates that the historical execution result pointed to by the hash value in the invalidation request does not exist.
[0098] In one example, the management end communicates with three script execution ends A, B, and C; in the first case, the management end sends a pending task to the script execution end A and sends a refresh request, then the sample execution end A immediately executes the task script S in the pending task, and obtains the execution result S2 of the task script S, and then the script execution end A feeds back the execution result S2 to the management end. In fact, the historical execution result S1 corresponding to the task script S is stored in the cache library associated with the script execution end A, and the historical execution result S1 is also stored in the cache library associated with the script execution end B, then the label of the historical execution result S1 in any cache library is shared. At this time, the script execution end A needs to generate an invalidation request for the hash value of the task script S, and broadcast the invalidation request to the other script execution ends B and C. After receiving the invalidation request, script execution end B queries the historical execution result S1 in the associated cache library based on the hash value of the task script S. Then, based on the invalidation request, script execution end B modifies the label of the historical execution result S1 in the cache library to invalid; and script execution end A writes the latest execution result S2 of the task script S as a historical execution result into the associated cache library.
[0099] In the second case, the management end sends a pending task to the script execution end A and sends a refresh request. The sample execution end A immediately executes the task script S in the pending task and obtains the execution result S2 of the task script S. The script execution end A then feeds back the execution result S2 to the management end. In fact, the historical execution result S1 corresponding to the task script S is stored in the cache library associated with the script execution end A, and the label is exclusive. The script execution end A writes the latest execution result S2 of the task script S as a historical execution result into the associated cache library, modifies the label of the execution result S2 to exclusive, and does not need to broadcast an invalidation request to the other script execution ends B and C.
[0100] Furthermore, when a script execution end sends a request to the other script execution ends (an invalidation request or a query request), the other script execution ends need to send feedback information to the initiator of the request; for example, when the request is a query request, the feedback information sent to the initiator may be the first information, or the target execution result corresponding to the query request; when the request is an invalidation request, the feedback information sent to the initiator may be the second information, or the third information.
[0101] Furthermore, for any script execution end: after broadcasting any request to the other script execution ends, the script execution end that has not fed back information within the preset feedback cycle will be determined as an invalid execution end, and the identity information (identification) of the invalid execution end will be obtained; the identity information of the invalid execution end will be fed back to the management end, and the identity information is used to instruct the management end to delete (disconnect) the invalid execution end based on the identity information. This can improve the cache hit rate of query requests on the one hand, and on the other hand, it can also promptly remove invalid or faulty script execution ends, thereby improving the execution efficiency of the management end's tasks.
[0102] Further, in summary, refer to Figure 6 , further summarizes the changes in the label of a historical execution result in the cache library associated with a script execution end.
[0103] After executing a task script on the current script execution end, the execution result of the task script is obtained (generated). If it is determined that the historical execution results corresponding to the hash value of the task script do not exist in the cache libraries associated with the other script execution ends (determined by the query results obtained after broadcasting the invalidation request), then the execution result of the task script is written into the cache library associated with the current script execution end as a historical execution result, with the label exclusive.
[0104] If the historical execution result is remotely obtained by other script execution terminals through broadcast query requests, the label of the historical execution result is changed to shared. If the label of the historical execution result is shared, and further, the current script execution terminal re-executes the script corresponding to the hash function of the historical execution result and obtains a latest execution result, the current script execution terminal broadcasts an invalidation request to the other script execution terminals based on the hash value of the historical execution result, and writes the latest execution result as the historical execution result into the cache library of the current script execution terminal, and the label is set to exclusive.
[0105] After receiving the invalidation request sent by other script execution ends, the current script execution end will modify the label of the historical execution result to invalid (remote update) and recycle it, regardless of whether the label of the script execution end is exclusive or shared.
[0106] The current script execution end broadcasts query requests to other script execution ends, and when the historical execution results of other scripts are remotely obtained, the current script execution end stores the historical execution results, and the label is changed to shared.
[0107] Furthermore, in an exemplary embodiment, a task execution method is provided, wherein the method is applied to Figure 1 The script execution end in is used as an example to illustrate, wherein the implementation of this method is based on the design of the script center platform and multiple states (tags) of the historical execution results cached in the cache library of the script execution client:
[0108] Script Center Platform (management side): responsible for two core processes:
[0109] 1: Provide an editing and management platform for script providers, and an ordering platform for script users.
[0110] 2: Script storage, task allocation and delivery to script execution clients; as a central control hub, it is responsible for allocating tasks to each script execution terminal to ensure the correctness and high-performance execution of script services. Specifically, the script center platform allocates tasks based on the unique characteristics of the script (such as ID or hash), and uses hash rings and other designs to allocate tasks to script execution clients. It also adds or removes instances of assignable tasks based on the connectivity of the script execution client to improve the cache hit rate. It accepts status feedback from the script execution client (a heartbeat mechanism is configured for any script execution terminal); if the script center platform has a new (connected) script execution client, it should reconfigure the load balancing; if a connected script execution client fails, it should be removed in time, and the correctness of the cached data should be guaranteed.
[0111] Script execution client (script execution end): executes scripts to obtain results, caches and synchronizes these execution results in multiple script center platforms.
[0112] Script execution client cache design:
[0113] The cache line of the script execution client is controlled by a state machine with three states (tags). The states of the cache line are E (exclusive), S (shared), and I (invalid). The state conversion is described as follows:
[0114] (1) The local instance obtains data by executing the script, generates a new cache, and enters the E state;
[0115] (2) The E state is maintained because the cache data is updated locally;
[0116] (3) In the E state, the cache becomes invalid because the timer times out, and the cache enters the I state.
[0117] (4) Other script execution client instances remotely obtain the local valid cache (E and S states), set the local cache to the S state, and other script execution client instances generate new caches and set them to the S state.
[0118] (5) S state: Because other scripts execute the client to update cache data, it enters I state;
[0119] (6) The S state becomes invalid because the timer times out (because the S state is shared by other script execution ends, all caches in the S state with the same data have synchronized timers and they become invalid at the same time), and enters the I state;
[0120] (7) Cache recovery in I state releases resources.
[0121] A business department of a company needs to run a large number of scripts remotely multiple times. The department has a script center platform C and a script execution client A, where:
[0122] The business process when the instance is stable is as follows: a script user executes script D on platform C, and D generates a unique task identification ID for the script; C only sends the script to A based on the ID and the hash ring algorithm; A executes the script and caches the execution result, and the status is E (exclusive).
[0123] The process of adding an instance is as follows: add script execution client B to C's load balancing, assuming that the new load balancing will send the ID to B; because the load balancing has been updated, B broadcasts a request for cached ID; A receives the broadcast and returns the cached ID; A and B both set the cache status to S (shared).
[0124] The shared cache conversion process is as follows: a request to refresh the ID is sent to B, and B updates the cache; because B's state is S (shared), a request to invalidate the cache is broadcast; A receives the broadcast, sets its own cache state to I (invalid), waits for recycling, and responds to the request; B receives all requests and refreshes its own cache state to E (exclusive).
[0125] The process of handling disconnection on the script execution end is as follows: if B sends a broadcast request and times out without receiving a response from A (or receives an error response), the script center platform C is notified; the script center platform removes A from the load balancing and then responds to B.
[0126] The task execution method of the embodiment of the present application, through the design of the cache library of the script execution client, adopts a state machine with three states (labels) to mark the state of the cache object (historical execution results); and through the communication design between the script center platform and the script execution client, and between the script execution clients, combined with the state machine, the consistency of the cache is ensured; thereby, on the multi-instance script execution platform, the execution results of the same script are cached, the speed of result return is improved, and the repeated execution of scripts with idempotence is avoided, thereby reducing the task burden of the operation and maintenance platform.
[0127] It should be understood that, although the steps in the flowcharts involved in the above embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0128] Based on the same inventive concept, the embodiment of the present application also provides a task execution device for implementing the task execution method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more task execution device embodiments provided below can refer to the limitations on the task execution method above, and will not be repeated here.
[0129] In an exemplary embodiment, Figure 7 As shown, a task execution device is provided, including a parsing module 701, a broadcasting module 702 and a feedback module 703, wherein:
[0130] The parsing module 701 is used to parse the to-be-executed task upon receiving the to-be-executed task sent by the management terminal, and obtain the hash value of the task script corresponding to the to-be-executed task;
[0131] The broadcast module 702 is used to generate a query request based on the hash value of the task script if the target execution result corresponding to the hash value of the task script is not found in the associated cache library, broadcast the query request to the remaining script execution ends, and receive the query results fed back by the remaining script execution ends based on the query request;
[0132] Feedback module 703 is used to, if it is determined that there is a target execution result in each query result, use the target execution result as the execution result of the task to be executed, and feed back the execution result of the task to be executed to the management end; wherein the target execution result is a historical execution result of a valid state obtained by the target script execution end from the associated cache library, and the hash value of the script associated with the target execution result is the same as the hash value of the task script in the query request, and the valid state represents that the remaining life of the historical execution result is not 0.
[0133] In the above-mentioned task execution device, for a script execution end, when it receives a task to be executed, it does not first execute the task to be executed, but generates a query request based on the hash value of the task script obtained by parsing the task to be executed, and broadcasts the query request to the remaining script execution ends, and determines based on the query results of the remaining script execution ends whether there is a target execution result (a historical execution result that is the same as the hash value of the task script and is in a valid state) in the cache library associated with the remaining script execution ends. When it is determined that the target execution result exists, that is, at least one of the remaining script execution ends has recently executed the task script and obtained the corresponding execution result (target execution result). Since the task script has idempotence, the target execution result can be directly fed back to the management end as the execution result of the task script; that is, through the task execution method of the present application, the process of the script execution end executing the task script can be omitted, and the corresponding execution result can be obtained directly by broadcasting the query request to the remaining script execution ends, thereby reducing the task burden of the operation and maintenance platform, and also improving the feedback speed of the execution result of the task to be executed, thereby speeding up the task processing efficiency.
[0134] In one embodiment, the task execution device further includes an execution module, and the execution module is specifically used to:
[0135] If it is determined that the target execution result does not exist in each query result, the task script is retrieved based on the hash value of the task script, the task script is executed and the execution result is obtained, and the execution result is fed back to the management end;
[0136] Associate the execution result with the hash value of the task script, and write the execution result as a historical execution result into the associated cache library;
[0137] Associate a timer with the historical execution result and set the tag of the historical execution result to exclusive.
[0138] In one embodiment, the task execution device further includes a query module, and the query module is specifically used to:
[0139] Receive a query request, obtain a target hash value from the query request, and query the historical execution result corresponding to the target hash value from the associated cache library to obtain the query result; the initiator of the query request is any one of the other script execution terminals;
[0140] If the historical execution result corresponding to the target hash value is queried from the associated cache library, the historical execution result corresponding to the target hash value is fed back to the initiator of the query request as the request result;
[0141] If the historical execution result corresponding to the target hash value is not queried from the associated cache library, the first information is fed back to the initiator of the query request, and the first information indicates that there is no target execution result.
[0142] In one embodiment, the query module is further configured to:
[0143] If the tag of the request result is exclusive, the tag of the request result is modified to shared in the associated cache library, and the request result with the modified tag is fed back to the initiator of the query request;
[0144] If the tag of the request result is shared, the execution result corresponding to the target hash value in the associated cache library is fed back to the initiator of the query request as the request result.
[0145] In one embodiment, the execution module is further configured to:
[0146] If a refresh request for a pending task is received, the task script is retrieved based on the hash value of the task script, the task script is executed and the execution result is obtained, and the execution result is fed back to the management end. The refresh request indicates that the pending task is executed immediately.
[0147] Generate an invalidation request based on the hash value of the task script, and broadcast the invalidation request to other script execution terminals. The invalidation request is used to indicate that the label of the historical execution result pointed to by the hash value in the invalidation request is changed to invalid;
[0148] If feedback information is received from other script execution ends, the execution result is written into the associated cache library as a historical execution result, and the label of the historical execution result is modified to exclusive.
[0149] In one embodiment, the task execution device further includes a failure processing module, and the failure processing module is specifically used to:
[0150] When receiving an invalidation request, determining whether there is a historical execution result pointed to by the hash value in the invalidation request in the associated cache library;
[0151] If it exists, the label of the historical execution result pointed to by the hash value in the invalidation request is modified to invalid, and the second information is fed back to the initiator of the invalidation request as feedback information; the second information indicates that the label modification is successful;
[0152] If it does not exist, the third information is fed back to the initiator of the invalidation request; the third information indicates that the historical execution result pointed to by the hash value in the invalidation request does not exist.
[0153] In one embodiment, the feedback module 703 is further configured to:
[0154] After broadcasting any request to the remaining script execution terminals, the script execution terminals that have not fed back information within the preset feedback cycle are determined as invalid execution terminals, and the identity information of the invalid execution terminals is obtained;
[0155] The identity information of the failed execution end is fed back to the management end, and the identity information is used to instruct the management end to delete the failed execution end based on the identity information.
[0156] Each module in the above task execution device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each module.
[0157] In an exemplary embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as shown in FIG. Figure 8As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and the external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, a task execution method is implemented. The display unit of the computer device is used to form a visually visible picture, which can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the computer device shell, or an external keyboard, touchpad or mouse.
[0158] Those skilled in the art will understand that Figure 8 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0159] In an exemplary embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the steps in any of the above-mentioned task execution method embodiments are implemented.
[0160] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in any of the above-mentioned task execution method embodiments are implemented.
[0161] In one embodiment, a computer program product is provided, including a computer program, which, when executed by a processor, implements the steps in any of the above-mentioned task execution method embodiments.
[0162] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0163] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, cache library or other media used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The cache library involved in each embodiment provided in this application may include at least one of a relational cache library and a non-relational cache library. Non-relational cache libraries may include distributed cache libraries based on blockchain, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0164] The technical features of the above embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0165] The above embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A task execution method, characterized in that: Applied to the script execution end, and each of the script execution ends is associated with a cache library, the method includes: When receiving the task to be executed sent by the management end, the task to be executed is parsed to obtain the hash value of the task script corresponding to the task to be executed; If the target execution result corresponding to the hash value of the task script is not found in the associated cache library, a query request is generated based on the hash value of the task script, and the query request is broadcast to the remaining script execution ends, and query results fed back by the remaining script execution ends based on the query request are received; If it is determined that the target execution result exists in each of the query results, the target execution result is used as the execution result of the task to be executed, and the execution result of the task to be executed is fed back to the management end.
2. The method according to claim 1, characterized in that The method further comprises: If it is determined that the target execution result does not exist in each of the query results, the task script is retrieved based on the hash value of the task script, the task script is executed and the execution result is obtained, and the execution result is fed back to the management end; Associating the execution result with the hash value of the task script, and writing the execution result as a historical execution result into an associated cache library; A timer is associated with the historical execution result, and a tag of the historical execution result is set to be exclusive.
3. The method according to claim 2, characterized in that The method further comprises: Receive a query request, obtain a target hash value from the query request, and query a historical execution result corresponding to the target hash value from an associated cache library; the query request is initiated by any one of the remaining script execution terminals; If the historical execution result corresponding to the target hash value is queried from the associated cache library, the historical execution result corresponding to the target hash value is fed back to the initiator of the query request as the request result; If the historical execution result corresponding to the target hash value is not queried from the associated cache library, first information is fed back to the initiator of the query request, and the first information indicates that there is no historical execution result corresponding to the target hash value.
4. The method according to claim 3, characterized in that Feeding back the execution result corresponding to the target hash value as a request result to the initiator of the query request includes: If the tag of the request result is exclusive, the tag of the request result is modified to shared in the associated cache library, and the request result after the tag is modified is fed back to the initiator of the query request; If the tag of the request result is shared, the execution result corresponding to the target hash value in the associated cache library is fed back to the initiator of the query request as the request result.
5. The method according to claim 1, characterized in that: Before broadcasting the query request to the remaining script execution terminals, the method further includes: If a refresh request for the task to be executed is received, the task script is retrieved based on the hash value of the task script, the task script is executed and an execution result is obtained, and the execution result is fed back to the management end, and the refresh request represents the immediate execution of the task to be executed; Generate an invalidation request based on the hash value of the task script, and broadcast the invalidation request to the remaining script execution terminals, wherein the invalidation request is used to indicate that the label of the historical execution result pointed to by the hash value in the invalidation request is modified to invalid; If feedback information from the remaining script execution terminals is received, the execution result is written into the associated cache library as a historical execution result, and the label of the historical execution result is modified to be exclusive.
6. The method according to claim 1 or 2, characterized in that: The method further comprises: Upon receiving an invalidation request, determining whether the associated cache library contains a historical execution result pointed to by the hash value in the invalidation request; If it exists, the label of the historical execution result pointed to by the hash value in the invalidation request is modified to invalid, and the second information is fed back to the initiator of the invalidation request as feedback information; the second information indicates that the label modification is successful; If not, the third information is fed back to the initiator of the invalidation request; the third information indicates that the historical execution result pointed to by the hash value in the invalidation request does not exist.
7. The method according to any one of claims 1 to 5, characterized in that The method further comprises: After broadcasting any request to the remaining script execution terminals, determining the script execution terminal that has not fed back information within a preset feedback cycle as a failed execution terminal, and obtaining the identity information of the failed execution terminal; The identity information of the failed execution end is fed back to the management end, and the identity information is used to instruct the management end to delete the failed execution end based on the identity information.
8. A cache device, characterized in that: Each script execution end is associated with a cache library, and the device includes a parsing module, a broadcasting module and a feedback module, wherein: The parsing module is used to parse the to-be-executed task upon receiving the to-be-executed task sent by the management terminal, and obtain the hash value of the task script corresponding to the to-be-executed task; A broadcast module, for generating a query request based on the hash value of the task script if the target execution result corresponding to the hash value of the task script is not found in the associated cache library, broadcasting the query request to the remaining script execution ends, and receiving the query results fed back by the remaining script execution ends based on the query request; A feedback module is used for, if it is determined that the target execution result exists in each of the query results, using the target execution result as the execution result of the task to be executed, and feeding back the execution result of the task to be executed to the management end.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.