Task slicing method, device and electronic device

By obtaining tasks and node lists from the registration center on the target node of the service platform and completing task sharding independently, the problem of poor task sharding in the existing technology is solved, and the stability and security of the system are improved.

CN114327817BActive Publication Date: 2025-03-21MASHANG CONSUMER FINANCE CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202111579114.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-22
Publication Date
2025-03-21
Estimated Expiration
2041-12-22

AI Technical Summary

Technical Problem

The task sharding method in existing distributed systems has the problem of poor sharding effect, especially when an external scheduling platform fails, which may cause the task sharding process to not proceed normally.

Method used

By obtaining the task list and node list from the registration center of the central node on the target node of the service platform, the task sharding is determined based on these lists. This method does not need to rely on an external scheduling platform, and completes the task sharding process entirely within the service platform.

Benefits of technology

Improve the effect of task sharding, enhance the stability and security of the system, and avoid task sharding failure caused by external scheduling platform failure.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114327817B_ABST
    Figure CN114327817B_ABST
Patent Text Reader

Abstract

The present application provides a task slicing method, device and electronic device, the task slicing method is applied to a target node in a service platform, the service platform includes a central node and at least two service nodes, the method includes: when the target node is in a startup state, obtaining a task list and a node list from a registration center of the central node, the task list includes tasks to be sliced, the node list includes the at least two service nodes, and node information of the service nodes for executing the tasks in the task list; the target node is any service node in the node list; based on the task list and the node list, in the task list, determining the task slicing corresponding to each service node in the node list. The task slicing method, device and electronic device provided by the present application can solve the problem of poor slicing effect in existing task slicing methods.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing, and in particular to a task slicing method, device and electronic device. Background Art

[0002] At present, in distributed systems, it is usually necessary to involve the problem of task slicing, wherein the task slicing refers to slicing all tasks in the distributed system to one or more nodes for processing according to certain rules and algorithms. Existing distributed systems usually need to rely on an external scheduling platform to implement the task slicing process. However, when the external scheduling platform fails, the task slicing process may not proceed normally, which may in turn cause the distributed system to be unable to process tasks normally. It can be seen that the existing task slicing method has the problem of poor slicing effect. Summary of the invention

[0003] The present application provides a task slicing method, device and electronic device, which can solve the problem of poor slicing effect in existing task slicing methods.

[0004] In a first aspect, an embodiment of the present application provides a task slicing method, which is applied to a target node in a service platform, wherein the service platform includes a central node and at least two service nodes, and the method includes:

[0005] When the target node is in the startup state, a task list and a node list are obtained from the registration center of the central node; wherein the task list includes tasks to be sharded; the node list includes node information of the at least two service nodes for executing the tasks in the task list; the target node is any service node in the node list;

[0006] Based on the task list and the node list, in the task list, a task slice corresponding to each service node in the node list is determined.

[0007] In a second aspect, an embodiment of the present application provides a task slicing device, which is applied to a target node in a service platform, wherein the service platform includes a central node and at least two service nodes, and the device includes:

[0008] an acquisition module, configured to acquire a task list and a node list from a registration center of the central node when the target node is in a startup state, wherein the task list includes tasks to be sharded, and the node list includes node information of service nodes, among the at least two service nodes, for executing the tasks in the task list; the target node is any service node in the node list;

[0009] A determination module is used to determine, based on the task list and the node list, in the task list, a task slice corresponding to each service node in the node list.

[0010] In a third aspect, an embodiment of the present application further provides an electronic device, comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein when the computer program is executed by the processor, the method steps described in the first aspect above are implemented.

[0011] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the method steps described in the first aspect above are implemented.

[0012] In the embodiment of the present application, the service node obtains the task list and the node list from the registration center, and then the service node determines the task slice corresponding to the service node in the task list based on the task list and the node list. In this process, since there is no need to rely on an external scheduling platform for task slices, the task slice process can be completed within the service platform, so the effect of task slices can be improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0013] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments of the present application will be 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 any creative labor.

[0014] Figure 1 This is one of the flow charts of the task slicing method provided in the embodiment of the present application;

[0015] Figure 2 This is the second flowchart of the task slicing method provided in the embodiment of the present application;

[0016] Figure 3 It is a schematic diagram of the connection relationship between the service node and the microservice in the embodiment of the present application;

[0017] Figure 4 It is a software architecture diagram in a task platform provided in an embodiment of the present application;

[0018] Figure 5 It is one of the structural diagrams of the task slicing device provided in the embodiments of the present application;

[0019] Figure 6 This is the second structural diagram of the task slicing device provided in the embodiment of the present application. DETAILED DESCRIPTION

[0020] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0021] In the related art, when slicing tasks in a distributed system, it is usually necessary to introduce a software development kit (SDK) of a distributed scheduling solution (elasticjob) in the application of the service node, and it is necessary to rely on a distributed application coordination service (Zookeeper) to complete the task slicing process. Specifically, by introducing the SDK in the application, registering its own information to Zookeeper through the SDK-related interface, monitoring the state changes of tasks and service nodes in Zookeeper, and implementing task slicing based on the monitoring results. In this process, since it is necessary to rely on the external service Zookeeper to implement the task slicing process, when the external service fails, the task slicing process may not be carried out normally, which may cause the distributed system to be unable to process tasks normally.

[0022] Based on this, in the embodiment of the present application, the service node directly obtains the task list and the node list from the registration center, and then the service node determines the task slice corresponding to the service node in the task list based on the task list and the node list. In this process, since there is no need to rely on an external scheduling platform for task slices, the task slice process can be completed within the service platform, so the effect of task slices can be improved.

[0023] See also Figure 1 , is a flowchart of a task slicing method provided in an embodiment of the present application, the task slicing method is applied to a target node in a service platform, the service platform includes a central node and at least two service nodes, the method includes:

[0024] Step 101, when the target node is in the startup state, obtain a task list and a node list from the registration center of the central node; wherein the task list includes tasks to be sharded; the node list includes the node information of the at least two service nodes, which are used to execute the tasks in the task list; the target node is any service node in the node list.

[0025] Step 102: Based on the task list and the node list, determine in the task list the task slice corresponding to each service node in the node list.

[0026] Among them, the central node can be a central server in the service platform, and the service node can be an instance in the service platform for providing services. Since the node information of the service node itself will be registered to the registration center during the startup of the service node, accordingly, when the service node goes offline, the node information corresponding to the offline service node in the registration center will be removed. Therefore, the status information of each node can be maintained in the registration center in the form of a node list. Specifically, a plug-in can be deployed in the central node, and the status information of each service node can be monitored based on the plug-in, so that the node list can be generated in the registration center.

[0027] The tasks in the above-mentioned task list can be various types of tasks pre-deployed in the service platform by relevant personnel. When relevant personnel create a new task in the service platform, the task information of the newly created task will be registered in the registration center. Correspondingly, when a task is closed by a user, or a task meets the closing conditions preset by the user, the task information of the task will be removed from the registration center. Therefore, the tasks that have been deployed and not closed can be maintained in the registration center in the form of a task list. Specifically, a plug-in can be deployed in the central node, and the creation and closing status information of each task can be monitored based on the plug-in, so that the task list can be generated in the registration center.

[0028] It can be understood that any of the at least two service nodes can be used to execute each task in the task list, and after completing the task slices in the task list, the relevant service node will execute all tasks in the corresponding slices. Among them, the tasks in the task list can be continuous tasks, that is, after completing the slices of the task, the corresponding service node can repeatedly execute the task. For example, the task can be a forwarding task for specific data. After completing the slices of the task, the corresponding service node will continue to execute the forwarding task, that is, when the service node receives the data to be forwarded, it will complete the data forwarding process until the forwarding task is closed.

[0029] The above-mentioned node list includes the node information of the service nodes used to execute the tasks in the task list among the at least two service nodes, which may specifically mean: the node list includes the node information of the service nodes in the available state among the at least two service nodes. Specifically, the service node in the available state may refer to a service node that is currently online and can be used to process the tasks in the task list, or a service node that is in the restart process and can be used to process the tasks in the task list. Accordingly, among the at least two service nodes, the service node that is currently offline can be regarded as an unavailable node. Among them, the at least two service nodes may include both service nodes in the available state and unavailable nodes. The node list does not include unavailable nodes.

[0030] Since the total amount of tasks to be sharded is recorded in the task list, and the number of service nodes in an available state is recorded in the node list, each service node can determine the corresponding task shard according to the preset rules after obtaining the task list and the node list. For example, when the total amount of tasks to be sharded in the task list is 100, and the number of service nodes in an available state is 10, that is, the number of target nodes is 10, each target node can determine 10 tasks from the task list as the tasks in the corresponding task shard according to the preset rules. Thus, the process of performing task sharding on each service node in the node list is realized.

[0031] The task slice may be understood as a task set, that is, all tasks corresponding to the target node are divided out from the task list, and the divided tasks are determined as a task slice.

[0032] It can be understood that each service node in the node list can obtain the task list and the node list from the registration center, and after obtaining the task list and the node list, each service node can determine its corresponding task slice based on the above method. After each service node in the node list completes the task slice process, the task slice process in the task list is completed. That is, in the node list, each service node can complete the task slice process independently. Since the slice data relied on in the process is the data of the registration center, and the data security and stability in the registration center are relatively high, the security and stability of the task slice process can be improved.

[0033] In this implementation, the service node obtains the task list and the node list from the registration center, and then the service node determines the task slice corresponding to the service node in the task list based on the task list and the node list. In this process, since there is no need to rely on an external scheduling platform for task slices, the task slice process can be completed within the service platform, so the effect of task slices can be improved.

[0034] Optionally, the acquiring the task list and the node list from the registration center of the central node includes:

[0035] In the case where the target node stores a historical node list within a preset period, acquiring a task list and a node list from a registration center of the central node, wherein the node list includes an online node list, and the historical node list includes node information of service nodes that are online within the preset period;

[0036] In the case that the target node does not store the historical node list, obtaining a task list and a node list from a registration center of the central node, wherein the node list includes the online node list and the historical node list;

[0037] The determining, based on the task list and the node list, in the task list, a task slice corresponding to each service node in the node list includes:

[0038] Based on the task list, the online node list and the historical node list, a task slice corresponding to the target node is determined in the task list.

[0039] Among them, since the service node may restart due to some reasons during the operation of the service platform, the service node is in an offline state during the service node restart process, that is, the node information of the service node in the restart process will be deleted from the node list. After the service node completes the restart process, the service node can be used to execute the tasks in the task list. Therefore, in order to avoid the problem of unreasonable task slicing due to treating the service node in the restart state as an unavailable service node during the task slicing process. In one embodiment of the present application, a period can be pre-set, and the service node that may be in the restart process can be determined based on the historical node list within the preset period.

[0040] Specifically, the preset period may refer to a period of time before the current time point, wherein the duration of the preset period may be a time value preset by relevant personnel, and may be 1 minute, 2 minutes, etc. For example, in one embodiment of the present application, when the duration of the preset period is 1 minute, the historical node list may refer to: a list of all service nodes that are online within 1 minute before the current time point. The current time point refers to the time point when the target node obtains the task list and node list from the registration center.

[0041] It is understandable that the historical node list may be the same as the online node list, or may be different from the online node list. For example, if the startup status of each service node in the service platform has not changed within the preset period, the historical node list is the same as the online node list. Accordingly, if the first service node is restarted within the preset period, and the restart process of the first service node has not been completed when the target node obtains the online node list, the node information of the first service node is included in the historical node list, while the node information of the first service node is not included in the online node list, wherein the first service node is any service node in the service platform.

[0042] Based on this, in an embodiment of the present application, all service nodes in the historical node list and the online node list can be determined as service nodes in an available state, which can avoid the problem of unreasonable task slicing due to treating service nodes in a restarting state as unavailable service nodes during the task slicing process.

[0043] It should be noted that after the first service node completes the restart process, the task list and the node list can be obtained from the registration center to complete the task slicing process of the first service node.

[0044] Since the target node may need to obtain the task list and node list from the registration center in real time or periodically, the target node may store the node list obtained each time locally to form a historical node list. In this case, the target node list may include the historical node list within the preset period. At this time, the target node may only obtain the online node list and task list from the registration center, and then determine the task slice corresponding to the target node based on the obtained online node list and task list, as well as the historical node list stored locally.

[0045] Accordingly, when the target node is a node started for the first time, the target node may not have a historical node list stored locally. In this case, the target node can obtain the task list, the online node list, and the historical node list from the registration center. In addition, when the registration center does not include the historical node list, since other service nodes in the service platform can maintain the historical node list, the target node can obtain the historical node list from other service nodes in the service platform through the registration center. For example, in the online node list, the first service node started (hereinafter referred to as the second service node) can store the historical node list. Therefore, in this case, the target node can obtain the historical node list from the second service node through the registration center.

[0046] It is understandable that, since the target node is any service node in the node list, in order to explain the task slicing process of each service node in the node list, the above embodiment only schematically illustrates the task slicing process of any service node in the node list. In fact, each service node in the node list can obtain the task list and the node list from the registration center respectively, and determine the task slicing corresponding to its own node in the task list based on the task list, the online node list and the historical node list respectively.

[0047] In this implementation, the task slice corresponding to the target node is determined in the task list based on the task list, the online node list and the historical node list, so that the task slice effect of the service platform can be improved.

[0048] Optionally, the node information includes preset attribute information of the service node, and determining the task slice corresponding to the target node in the task list based on the task list, the online node list and the historical node list includes:

[0049] Merging the online node list and the historical node list to obtain a first node list;

[0050] Based on the preset attribute information, the service nodes in the first node list are sorted to obtain a first sequence list;

[0051] Based on the sequence number of the target node in the first sequence table, a task slice corresponding to the target node is determined in the task list.

[0052] Specifically, since the online node list and the historical node list may contain the same node information of the service node, the first node list may be obtained by taking the union of the online node list and the historical node list, wherein the first node list stores the node information of all service nodes in an available state.

[0053] The preset attribute information may be attribute information such as a host name or host IP address of the service node that can be used to identify the service node.

[0054] In this implementation, a first node list is obtained by merging the historical node list with the service nodes in the online node list, and the service nodes in the first node list are sorted based on preset attribute information. This is conducive to orderly slicing the tasks in the task list to improve the effect of task slicing.

[0055] Optionally, determining the task slice corresponding to the target node in the task list based on the sequence number of the target node in the first sequence list includes:

[0056] Sorting the tasks in the task list according to a preset rule to obtain a second sequence list;

[0057] The tasks satisfying the preset conditions in the second sequence table are determined as the tasks in the task slice corresponding to the target node, wherein the preset conditions include that the target calculation value corresponding to the task is a non-negative integer, and the target calculation value is calculated based on the following formula:

[0058] X = (TB) / N;

[0059] Among them, X is the target calculation value, T is the ranking number of the task in the second sequence list, B is the ranking number of the target node in the first sequence list, and N is the number of service nodes in the first sequence list.

[0060] Specifically, the tasks in the task list may be sorted according to the creation time of each task in the task list. In addition, the tasks in the task list may be sorted based on the task number of each task to obtain the second sequence list.

[0061] The order number of the service node in the first sequence list may be a positive integer starting from 1. Correspondingly, the order number of the task in the second sequence list may also be a positive integer starting from 1. In this way, the order number of each task in the task list may be calculated using the above formula to determine whether the corresponding task meets the preset condition.

[0062] For example, in one embodiment of the present application, the target node is ranked 5 in the first sequence list, that is, B=5, the number of service nodes in the first sequence list is 10, that is, N=10, and the number of tasks in the second sequence list is 99. When the ranking number of the task is 1 (that is, T=1), X=(1-5) / 10=-0.4. Since -0.4 is not a non-negative integer at this time, the task with the ranking number 1 does not meet the preset condition. When the ranking number of the task is 5 (that is, T=5), X=(5-5) / 10=0. Since 0 is a non-negative integer at this time, the task with the ranking number 5 meets the preset condition, that is, the task with the ranking number 5 can be determined as the task in the task slice corresponding to the target node. By calculating the 100 tasks in the second sequence list respectively, it can be determined that the tasks in the task slice corresponding to the target node include: the task with sequence number 5, the task with sequence number 15, the task with sequence number 25, the task with sequence number 35, the task with sequence number 45, the task with sequence number 55, the task with sequence number 65, the task with sequence number 75, the task with sequence number 85 and the task with sequence number 95. Accordingly, based on the above formula, it can be calculated in sequence that the number of tasks in the task slice corresponding to the service nodes with sequence numbers 1-9 is 10 respectively, and the number of tasks in the task slice corresponding to the service node with sequence number 10 is 9. It can be seen that by slicing the tasks using the above method, it can be ensured that the number of tasks in the task slice corresponding to each service node is relatively uniform under the premise that all tasks in the task list are divided.

[0063] In addition, after completing the above task slicing process, when the central node receives the next newly added task initiated by the user, since the number of tasks in the current second sequence list is 99, that is, the sequence number of the current task in the second sequence list is sorted to 99, the sequence number of the newly added task in the second sequence list can be determined to be 100, and since (100-10) / 10=9 is a non-negative integer, the newly added task will be divided into the task slice corresponding to the sequence number 10. At this time, the number of tasks in the task slice corresponding to each service node is 10. It can be seen that by adopting the above method to slice the task, when the task in the task list changes, the task slice corresponding to each service node can be dynamically updated, and it can ensure that the number of tasks in the task slice corresponding to each service node after the update is relatively uniform.

[0064] In this implementation, after the first and second sorting tables are sorted, it is only necessary to bring the corresponding sorting number into the above formula to determine the tasks in the task slices corresponding to the target node, thereby completing the task slice process of the target node. And by adopting the above method to slice the tasks, it can be ensured that under the premise that all tasks in the task list are divided, the number of tasks in the task slices corresponding to each service node is relatively uniform. In addition, by adopting the above method to slice the tasks, it is also possible to dynamically update the task slices corresponding to each service node when the tasks in the task list change, and it can be ensured that the number of tasks in the task slices corresponding to each service node after the update is relatively uniform.

[0065] Optionally, the preset attribute information includes attribute information of a target attribute, the target attribute is an attribute used to identify the service node, and the attribute information remains unchanged during the operation of the service node, wherein the preset attribute information of any two of the at least two service nodes is different, and the service nodes in the first node list are sorted based on the preset attribute information to obtain a first sequence list, including:

[0066] Based on the attribute information of the target attribute, the service nodes in the first node list are sorted to obtain a first sequence list.

[0067] The attribute information may refer to the attribute value of an attribute, and the target attribute may refer to an attribute with relatively stable attribute value such as the IP address of a service node, a host name, an instance ID, an instance name, etc.

[0068] Specifically, since the first sequence list is a sequence list obtained by sorting the service nodes in the first node list based on the preset attribute information, if the preset attribute information is attribute information that changes dynamically over time, it may cause the sequence number of a certain service node in the first sequence list to change dynamically over time, and different sequence numbers correspond to different task slices, therefore, the task slice corresponding to the service node will change over time, which will further lead to the problem of frequent changes in the corresponding relationship between the task slice and the service node.

[0069] In this implementation, the service nodes in the first node list are sorted by using preset attribute information whose attribute values ​​remain unchanged. Since the preset attribute information of each service node always remains unchanged, the problem of dynamic changes in the sorting results in the first sequence list due to changes in the preset attribute information over time can be avoided, thereby avoiding frequent changes in the corresponding relationship between task slices and service nodes.

[0070] Optionally, based on the task list and the node list, after determining the task slice corresponding to the target node in the task list, the method further includes:

[0071] Monitoring whether the task list and the node list in the registration center are updated;

[0072] When at least one of the task list and the node list is updated, the task slice corresponding to the target node is updated.

[0073] Specifically, the target node can obtain the task list and node list from the registration center at each preset time, and determine whether the task list and node list obtained this time are updated relative to the task list and node list obtained last time. If at least one of the task list and the node list is updated, the task slice of the target node is updated according to the above method based on the task list and node list obtained this time. The preset time can be set by relevant personnel, for example, it can be a relatively short time such as 1 minute or 2 minutes.

[0074] During the operation of the service platform, relevant personnel may deploy new tasks according to actual needs, or close specific tasks according to actual needs. When relevant personnel deploy new tasks on the service platform, the relevant information of the new tasks will be registered to the registration center, and the task list will be updated accordingly; accordingly, when relevant personnel close a specific task, the task information of the closed task will be deleted from the registration center, and the task list will be updated accordingly. When there is an update to the task list, the tasks in the task list are re-sharded to ensure that the newly deployed tasks can be executed by the corresponding service nodes in a timely manner. At the same time, after the number of tasks changes, the number of tasks in each service node can be balanced by re-sharding to further improve the effect of task sharding.

[0075] In addition, during the operation of the service platform, the relevant personnel can also expand or reduce the number of instances used to process the task list according to actual needs. For example, when the number of tasks in the task list is too large, the relevant personnel can add the number of service nodes used to process the task list, or, when the number of tasks in the task list is too small, the relevant personnel can close a certain number of service nodes. When the number of service nodes changes, the relevant node information in the registration center will also change accordingly, and the node list will also be updated accordingly. When the node list is updated, the tasks in the task list are re-sliced. In this way, when a service node is closed, it can be ensured that the tasks in the task slices corresponding to the closed service node can be transferred to other service nodes in a timely manner; accordingly, in the case of a new service node, some tasks in other service nodes can be transferred to the newly added service node in a timely manner, so as to relieve the task processing pressure of the service platform through the newly added service node.

[0076] In this implementation, by monitoring whether the task list and the node list in the registration center are updated, and when at least one of the task list and the node list is updated, the task slice corresponding to the target node is updated. In this way, the service platform can automatically adjust the task slice of the service node based on the detected update information, thereby further improving the effect of task slice.

[0077] Optionally, based on the task list and the node list, after determining in the task list the task slice corresponding to each service node in the node list, the method further includes:

[0078] When the number of tasks in the task slice corresponding to the target node is less than a first threshold, sending a first prompt message to the central node;

[0079] When the number of tasks in the task slice corresponding to the target node is greater than a second threshold, a second prompt message is sent to the central node, and the first threshold is less than the second threshold.

[0080] Specifically, the first threshold and the second threshold may be thresholds determined by the user based on actual experience. When the number of tasks in the task slice of the target node is less than the first threshold, it can be considered that the target node has insufficient tasks. At this time, there is a problem of waste of resources. Therefore, the target node may send a first prompt message to the central node. After the central node receives the first prompt message, the first prompt message may be forwarded to the client to prompt the user to scale down the service corresponding to the task in the task list to improve resource utilization. Among them, the means of scaling down may specifically be to shut down a certain number of online service nodes.

[0081] Accordingly, when the number of tasks in the task slice of the target node is greater than the second threshold, it can be considered that the task volume of the target node has exceeded the maximum task volume that it can handle at the same time. If it continues in this state, it may lead to problems such as untimely task processing or task processing failure. Based on this, the target node can send a second prompt message to the central node. After the central node receives the second prompt message, the second prompt message can be forwarded to the client to prompt the user to expand the service corresponding to the task in the task list to ensure that the service platform can provide services to the outside normally. Among them, the means of expansion can specifically be to increase a certain number of online service nodes.

[0082] In this implementation, after completing the task slicing for each service node, it is further determined whether the number of tasks for the task slicing corresponding to each service node is reasonable, so as to further improve the effect of the task slicing.

[0083] See also Figure 2 In one embodiment of the present application, when the service node is started, it registers its own service in the registration center of the microservice (Eureka). At the same time, the microservice (Eureka) detects the status of the service node and generates update information based on the monitoring results. The update information includes the update information of the task list and / or the update information of the node list. The service node can obtain the update information and update the corresponding task slice based on the update information. Accordingly, please refer to Figure 3 After the n service nodes of the service platform are started, they can register their own services to the Eureka registration center, and each service node can obtain the task list and node list from the Eureka registration center, and determine the task slice corresponding to its own node in the task list based on the task list and the node list. Thus, the task slice process is completed.

[0084] Also, see Figure 4 , is a software architecture diagram in a task platform provided in an embodiment of the present application. After completing the slicing of the task, the service node can act as a consumer end to execute the task in the corresponding task slicing. The process of the service node executing the task can be: after the production end generates data, the generated data is passed to the database through the generation end agent, the consumer end agent obtains data from the database through Kafka or Redis, and passes the obtained data to the consumer end, and the consumer end processes the received data.

[0085] See also Figure 5, is a schematic diagram of a task slicing device 500 provided in an embodiment of the present application, wherein the task slicing device 500 is applied to a target node in a service platform, wherein the service platform includes a central node and at least two service nodes, and the device includes:

[0086] The acquisition module 501 is used to acquire a task list and a node list from the registration center of the central node when the target node is in the startup state; the task list includes the tasks to be sharded; the node list includes the node information of the at least two service nodes, which are used to execute the tasks in the task list; the target node is any service node in the node list;

[0087] The determination module 502 is used to determine, based on the task list and the node list, in the task list, the task slice corresponding to each service node in the node list.

[0088] Optionally, the acquisition module 501 is specifically configured to acquire a task list and a node list from a registration center of the central node when the target node stores a historical node list within a preset period, the task list including an online node list, and the historical node list including node information of service nodes that are online within the preset period; and acquire a task list and a node list from a registration center of the central node when the target node does not store the historical node list, the task list including the online node list and the historical node list;

[0089] The determination module 502 is specifically configured to determine the task slice corresponding to the target node in the task list based on the task list, the online node list and the historical node list.

[0090] Optionally, the node information includes preset attribute information of the service node, and the determining module 502 includes:

[0091] A merging submodule, used for merging the online node list and the historical node list to obtain a first node list;

[0092] A first sorting submodule, configured to sort the service nodes in the first node list based on the preset attribute information to obtain a first sequence list;

[0093] A first determining submodule is configured to determine, in the task list, a task slice corresponding to the target node based on a sequence number of the target node in the first sequence list.

[0094] Optionally, the first determining submodule includes:

[0095] A sorting unit, used to sort the tasks in the task list according to a preset rule to obtain a second sequence list;

[0096] A determination unit is used to determine the task in the second sequence table that meets the preset condition as a task in the task slice corresponding to the target node, wherein the preset condition includes that the target calculation value corresponding to the task is a non-negative integer, and the target calculation value is calculated based on the following formula:

[0097] X = (TB) / N;

[0098] Among them, X is the target calculation value, T is the ranking number of the task in the second sequence list, B is the ranking number of the target node in the first sequence list, and N is the number of service nodes in the first sequence list.

[0099] Optionally, the preset attribute information includes attribute information of a target attribute, the target attribute is an attribute used to identify the service node, and the attribute information remains unchanged during the operation of the service node, wherein the preset attribute information of any two of the at least two service nodes is different;

[0100] The first sorting submodule is specifically configured to sort the service nodes in the first node list based on the attribute information of the target attribute to obtain a first sequence list.

[0101] Optionally, the device further comprises:

[0102] A detection module, used for monitoring whether the task list and the node list in the registration center are updated;

[0103] An update module is used to update the task slice corresponding to the target node when at least one of the task list and the node list is updated.

[0104] Optionally, the device further comprises:

[0105] A sending module, configured to send a first prompt message to the central node when the number of tasks in the task slice corresponding to the target node is less than a first threshold;

[0106] The sending module is further configured to send second prompt information to the central node when the number of tasks in the task slice corresponding to the target node is greater than a second threshold, and the first threshold is less than the second threshold.

[0107] The task slicing device 500 provided in the embodiment of the present application embodies the various processes in the above-mentioned task slicing method embodiment, and will not be described again here to avoid repetition.

[0108] See also Figure 6 , Figure 6 is a structural diagram of a task slicing device provided by another embodiment of the present application, such as Figure 6 As shown, the task slicing device includes: a processor 601, a memory 602, and a computer program stored in the memory 602 and executable on the processor. The components in the task slicing device are coupled together via a bus interface 603. When the computer program is executed by the processor 601, the following steps are implemented:

[0109] When the target node is in a startup state, a task list and a node list are obtained from a registration center of the central node, wherein the task list includes tasks to be sharded, and the node list includes node information of service nodes in the at least two service nodes for executing the tasks in the task list; the target node is any service node in the node list;

[0110] Based on the task list and the node list, in the task list, a task slice corresponding to each service node in the node list is determined.

[0111] Optionally, the acquiring the task list and the node list from the registration center of the central node includes:

[0112] In the case where the target node stores a historical node list within a preset period, a task list and a node list are obtained from the registration center of the central node, wherein the task list includes an online node list, and the historical node list includes node information of service nodes that are online within the preset period; in the case where the target node does not store the historical node list, a task list and a node list are obtained from the registration center of the central node, wherein the task list includes the online node list and the historical node list;

[0113] The determining, based on the task list and the node list, in the task list, a task slice corresponding to each service node in the node list includes:

[0114] Based on the task list, the online node list and the historical node list, a task slice corresponding to the target node is determined in the task list.

[0115] Optionally, the node information includes preset attribute information of the service node, and determining the task slice corresponding to the target node in the task list based on the task list, the online node list and the historical node list includes:

[0116] Merging the online node list and the historical node list to obtain a first node list;

[0117] Based on the preset attribute information, the service nodes in the first node list are sorted to obtain a first sequence list;

[0118] Based on the sequence number of the target node in the first sequence table, a task slice corresponding to the target node is determined in the task list.

[0119] Optionally, determining the task slice corresponding to the target node in the task list based on the sequence number of the target node in the first sequence list includes:

[0120] Sorting the tasks in the task list according to a preset rule to obtain a second sequence list;

[0121] The tasks satisfying the preset conditions in the second sequence table are determined as the tasks in the task slice corresponding to the target node, wherein the preset conditions include that the target calculation value corresponding to the task is a non-negative integer, and the target calculation value is calculated based on the following formula:

[0122] X = (TB) / N;

[0123] Among them, X is the target calculation value, T is the ranking number of the task in the second sequence list, B is the ranking number of the target node in the first sequence list, and N is the number of service nodes in the first sequence list.

[0124] Optionally, the preset attribute information includes attribute information of a target attribute, the target attribute is an attribute used to identify the service node, and the attribute information remains unchanged during the operation of the service node, wherein the preset attribute information of any two of the at least two service nodes is different, and the service nodes in the first node list are sorted based on the preset attribute information to obtain a first sequence list, including:

[0125] Based on the attribute information of the target attribute, the service nodes in the first node list are sorted to obtain a first sequence list.

[0126] Optionally, based on the task list and the node list, after determining the task slice corresponding to the target node in the task list, the method further includes:

[0127] Monitoring whether the task list and the node list in the registration center are updated;

[0128] When at least one of the task list and the node list is updated, the task slice corresponding to the target node is updated.

[0129] Optionally, based on the task list and the node list, after determining in the task list the task slice corresponding to each service node in the node list, the method further includes:

[0130] When the number of tasks in the task slice corresponding to the target node is less than a first threshold, sending a first prompt message to the central node;

[0131] When the number of tasks in the task slice corresponding to the target node is greater than a second threshold, a second prompt message is sent to the central node, and the first threshold is less than the second threshold.

[0132] An embodiment of the present application also provides an electronic device, including a processor, a memory, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, the various processes of the above-mentioned method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be described here.

[0133] The embodiment of the present application also provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, each process of the above method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it is not repeated here. The computer-readable storage medium is, for example, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0134] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.

[0135] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for enabling an electronic device (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the methods described in each embodiment of the present application.

[0136] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.

Claims

1. A task slicing method, applied to a target node in a service platform, wherein the service platform includes a central node and at least two service nodes, characterized in that: The method comprises: When the target node is in the startup state, a task list and a node list are obtained from the registration center of the central node; wherein the task list includes tasks to be sharded; the node list includes node information of the at least two service nodes for executing the tasks in the task list; the target node is any service node in the node list; Based on the task list and the node list, determine the task slice corresponding to the target node in the task list; Among them, after obtaining the task list and the node list, each service node in the node list determines the corresponding task slice from the task list to implement the process of task slicing for each service node in the node list.

2. The method according to claim 1, characterized in that The obtaining of the task list and the node list from the registration center of the central node includes: In the case where the target node stores a historical node list within a preset period, acquiring a task list and a node list from a registration center of the central node, wherein the node list includes an online node list, and the historical node list includes node information of service nodes that are online within the preset period; In the case that the target node does not store the historical node list, obtaining a task list and a node list from a registration center of the central node, wherein the node list includes the online node list and the historical node list; The determining, based on the task list and the node list, in the task list, the task slice corresponding to the target node comprises: Based on the task list, the online node list and the historical node list, a task slice corresponding to the target node is determined in the task list.

3. The method according to claim 2, characterized in that The node information includes preset attribute information of the service node, and determining the task slice corresponding to the target node in the task list based on the task list, the online node list and the historical node list includes: Merging the online node list and the historical node list to obtain a first node list; Based on the preset attribute information, the service nodes in the first node list are sorted to obtain a first sequence list; Based on the sequence number of the target node in the first sequence table, a task slice corresponding to the target node is determined in the task list.

4. The method according to claim 3, characterized in that: The determining, in the task list, a task slice corresponding to the target node based on the sequence number of the target node in the first sequence list comprises: Sorting the tasks in the task list according to a preset rule to obtain a second sequence list; The tasks satisfying the preset conditions in the second sequence table are determined as the tasks in the task slice corresponding to the target node, wherein the preset conditions include that the target calculation value corresponding to the task is a non-negative integer, and the target calculation value is calculated based on the following formula: X = (TB) / N; Among them, X is the target calculation value, T is the ranking number of the task in the second sequence list, B is the ranking number of the target node in the first sequence list, and N is the number of service nodes in the first sequence list.

5. The method according to claim 3, characterized in that: The preset attribute information includes attribute information of a target attribute, where the target attribute is an attribute used to identify the service node and the attribute information remains unchanged during the operation of the service node, wherein the preset attribute information of any two of the at least two service nodes is different, and the service nodes in the first node list are sorted based on the preset attribute information to obtain a first sequence list, including: Based on the attribute information of the target attribute, the service nodes in the first node list are sorted to obtain a first sequence list.

6. The method according to claim 1, characterized in that After determining the task slice corresponding to the target node in the task list based on the task list and the node list, the method further includes: Monitoring whether the task list and the node list in the registration center are updated; When at least one of the task list and the node list is updated, the task slice corresponding to the target node is updated.

7. The method according to claim 1, characterized in that After determining the task slice corresponding to the target node in the task list based on the task list and the node list, the method further includes: When the number of tasks in the task slice corresponding to the target node is less than a first threshold, sending a first prompt message to the central node; When the number of tasks in the task slice corresponding to the target node is greater than a second threshold, a second prompt message is sent to the central node, and the first threshold is less than the second threshold.

8. A task slicing device, applied to a target node in a service platform, wherein the service platform includes a central node and at least two service nodes, characterized in that: The device comprises: An acquisition module is used to acquire a task list and a node list from a registration center of the central node when the target node is in a startup state; wherein the task list includes tasks to be sharded, and the node list includes node information of the at least two service nodes for executing the tasks in the task list; and the target node is any service node in the node list; A determination module, configured to determine, based on the task list and the node list, a task slice corresponding to the target node in the task list; Among them, after obtaining the task list and the node list, each service node in the node list determines the corresponding task slice from the task list to implement the process of task slicing for each service node in the node list.

9. An electronic device, characterized in that: The method comprises a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the computer program implements the method steps according to any one of claims 1 to 7 when executed by the processor.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Acquisition method and device for service node

    CN108055157A

  • Distributed task management method and management system

    CN110673945A

  • Micro-service-based low-intrusion distributed timed task scheduling system and method

    CN111190736A

  • Task processing method, apparatus and device and storage medium

    CN112231098A