Method for realizing multi-task scheduling and load balancing based on springboot

Through the multi-task scheduling and load balancing method based on SpringBoot, the problems of low resource utilization and long response time in traditional single-task scheduling are solved, the flexibility and fault tolerance of task scheduling are achieved, and the automatic expansion and module of system capacity are supported. Automatic handling of faults.

CN119336495AActive Publication Date: 2025-01-21EASTERN COMM
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202411363381.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-27
Publication Date
2025-01-21
Estimated Expiration
2044-09-27

AI Technical Summary

Technical Problem

Traditional single-task scheduling processing has problems such as low resource utilization, long response time, high pressure and lack of flexibility, and cannot be dynamically adjusted and fault tolerance.

Method used

Adopting multi -tasking scheduling and load balancing methods based on SpringBoot, through combinations of marginal task plug -in modules, central task scheduling modules, NACOS and database clusters to achieve multi -module deployment and load balancing scheduling of tasks.

Benefits of technology

Realize the flexibility and fault tolerance of task scheduling, improve the resource utilization and response time, and support the automatic expansion of the system capacity and the automatic processing of the module failure.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119336495A_ABST
    Figure CN119336495A_ABST
Patent Text Reader

Abstract

The invention relates to a method for realizing multi-task scheduling and load balancing based on springboot. The method is completed through cooperation of an edge task plug-in module, a central task scheduling module, Nacos and a database cluster. According to the invention, based on a SpringBoot framework, any application program developed based on SpringBoot can integrate an edge task plug-in module to realize message interaction with a central task scheduling module. Therefore, functions of task control message issuing and task state message reporting can be realized. Therefore, the development workload and the later maintenance workload of developers are reduced; the problems that a single application program is low in resource utilization rate, long in response time, large in pressure and lack of flexibility (dynamic adjustment cannot be achieved, and a fault-tolerant mechanism is lacked) are solved through operations such as multi-task load balancing scheduling, module fault automatic offline and module expansion automatic online. The method can be applied to various software systems related to multi-task scheduling and load balancing requirements.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a method for realizing multi-task scheduling and load balancing based on springboot. Background Art

[0002] Task scheduler is an indispensable part of modern software system, especially in the fields of distributed computing, cloud computing, big data processing, enterprise-level applications and service automation. Traditional single-task scheduling is handled by one application to handle all tasks, which has problems such as low resource utilization, long response time, high pressure, lack of flexibility (unable to adjust dynamically, lack of fault tolerance mechanism). The method of implementing multi-task scheduling and load balancing based on SpringBoot can be deployed through multiple modules, and Nacos load balancing is used to schedule to each module for processing. When a module fails or other emergency situations occur, Nacos does not receive the heartbeat message of this module within a certain period of time, immediately deletes this module information from the module list, and schedules the task to other normal modules. When the system capacity needs to be expanded, the new module is started and automatically registered to Nacos to realize the automatic online expansion of the module. The design and implementation of multi-task scheduling machine load involves a variety of complex technologies and concepts. Its main technical points include operating system scheduling principles, distributed systems, parallel and concurrent processing, resource management, dependency management, fault tolerance and recovery, time management and periodic management, API and integration, etc. A deep understanding of these background technologies is crucial for designing and implementing efficient, reliable and scalable task scheduling systems. Summary of the invention

[0003] In view of the problems existing in the prior art, the purpose of the present invention is to provide a technical solution for a method for realizing multi-task scheduling and load balancing based on springboot.

[0004] The method for realizing multi-task scheduling and load balancing based on springboot is characterized by comprising an edge task plug-in module, a central task scheduling module, Nacos and a database cluster; The edge task plug-in module is used to be integrated in related applications. After the edge task plug-in module completes module registration on Nacos, it only needs to call the relevant API to complete the communication and related operations between modules; including: sending task control messages according to user instructions; reporting task status messages according to task execution status; receiving task control messages and task status messages, and performing corresponding operations; The central task scheduling module is used for centralized scheduling and management of multiple tasks. After the central task scheduling module completes module registration on Nacos, it only needs to call the relevant API to complete the communication and related operations between modules; including: receiving the task control message sent by the source edge task plug-in module, parsing the message and saving it in the database cluster, and forwarding the message to the destination edge task plug-in module; regularly querying the task information saved in the database cluster, and actively sending the task control message to the destination edge task plug-in module when the task processing is abnormal; receiving the task status message reported by the destination edge task plug-in module, parsing the message and updating it in the database cluster, and forwarding the message to the source edge task plug-in module; Nacos is used for module registration and configuration center management, including: registering and discovering the central task scheduling module and edge task plug-in module running in the server, and distributing message requests through load balancing strategies; saving various configuration files required by the module; reading relevant configuration files from Nacos when the module starts, and implementing configuration hot updates by modifying the Nacos configuration files when the module is running; The database cluster is used to save task information. The task information table contains: unique ID, task unique number, task type, source service, destination service, task start time, task end time, task details, task status, creation time, update time, task group, cache identifier, and remarks information. When the central task scheduling module receives the task information, it saves the task information to the task information table of the database cluster to support subsequent related operations and management of the task.

[0005] The method for realizing multi-task scheduling and load balancing based on springboot is characterized in that it includes the following processes: module registration, task control message sending, and task status message reporting; when the module is registered, the edge task plug-in module and the central task processing module register their own relevant information in Nacos, and each module finds the corresponding module information through the service name; when the task control message is sent, the source edge task plug-in module calls the API, sends the task control message to the central task scheduling module, and the central task scheduling module forwards the message to the corresponding destination edge task plug-in module, and the destination edge task plug-in module performs corresponding operation processing after receiving the message; when the task status message is reported, the destination edge task plug-in module calls the API according to the task processing situation, reports the task status message to the central task scheduling module, and the central task scheduling module forwards the message to the corresponding source edge task plug-in module, and the source edge task plug-in module performs corresponding operation processing after receiving the message.

[0006] The method for realizing multi-task scheduling and load balancing based on springboot is characterized in that the task control message field includes a unique ID, a task unique number, a task type, a source service, a destination service, a task start time, a task end time, task details, a task group, a cache identifier and remarks information; the task status message field includes: a task unique number, a time and a task status.

[0007] The method for implementing multi-task scheduling and load balancing based on springboot is characterized by comprising the following steps: 1) Before starting the edge task plug-in module, package the edge task plug-in module into a jar package, integrate the edge task plug-in module jar package into the application and develop it, and finally package it into an executable application and configure the corresponding gRPC information; 2) When the edge task plug-in module is started, it obtains relevant configuration parameters from the Nacos configuration center, obtains the external IP information of the server, starts its own service IP, port, gRPC IP and gRPC port, and registers the gRPC IP, gRPC port address and weight to Nacos; starts the task monitoring thread and reports the health status of the tasks being executed at regular intervals; 3) Before the central task scheduling module runs, perform the asynchronous task delivery thread pool configuration, task restriction information configuration, gRPC information configuration, and database cluster configuration, and finally start the database cluster service; 4) When the central task scheduling module is started, it obtains relevant configuration parameters from the Nacos configuration center, connects to the database cluster according to the configuration, obtains the external IP information of the server, starts its own service IP, port, gRPC IP and gRPC port, and registers the gRPC IP and gRPC port addresses in Nacos; starts the task processing thread and processes the task control message and task status message; 5) The user sends task control messages through the edge task plug-in module, including: Sending new task messages: The source edge task plug-in module sends new task messages, calls the load balancing strategy interface configured by Nacos to obtain the information of the central task scheduling module, and sends the new task messages to the central task scheduling module through the gRPC protocol; after receiving the new message, the central task scheduling module determines whether the message is legal. If it is legal, it saves the task information to the database cluster; then determines whether the task reaches the concurrency limit and whether it is cached. If there is no limit or it is less than the concurrency limit, the message is forwarded directly, otherwise the task is cached or rejected; when forwarding the message, the central task scheduling module calls the load balancing strategy interface configured by Nacos to obtain the destination edge task plug-in module information, and forwards the message to the destination edge task plug-in module through the gRPC protocol; after the destination edge task plug-in module successfully receives the new task message, it processes it according to the task information; Sending a task deletion message: The source edge task plug-in module sends a task deletion message, calls the load balancing strategy interface configured by Nacos to obtain the central task scheduling module information, and sends a task deletion message to the central task scheduling module through the gRPC protocol; when the central task scheduling receives the deletion message or monitors the task processing exception regularly, it calls the load balancing strategy interface configured by Nacos to obtain the destination edge task plug-in module information, and sends a message to the destination edge task plug-in module through the gRPC protocol; after the destination edge task plug-in module successfully receives the task deletion message, it deletes the task according to the task unique number; 6) The edge task plug-in module reports the task status when processing the task, including: Task health status reporting: The destination edge task plug-in module periodically queries the health status of the task being executed, calls the load balancing strategy interface configured by Nacos to obtain the central task scheduling module information, and reports the task health status message to the central task scheduling module through the gRPC protocol; when the central task scheduling module receives the task health status message, it determines whether the message is legal. If legal, the task status in the database cluster is updated to healthy according to the task unique number, and the update time is the time carried by the message. At the same time, the load balancing strategy interface configured by Nacos is called to obtain the source edge task plug-in module information, and the task information is forwarded to the source edge task plug-in module; if illegal, the message is discarded and not processed; Task completion status reporting: After the destination edge task plug-in module completes the task normally, it calls the load balancing strategy interface configured by Nacos to obtain the central task scheduling module information, and reports the task completion status message to the central task scheduling module through the gRPC protocol; when the central task scheduling module receives the task completion status message, it determines whether the message is legal; if it is legal, it deletes the task information in the database cluster according to the task unique number, indicating that the task has been executed normally, and at the same time calls the load balancing strategy interface configured by Nacos to obtain the source edge task plug-in module information, and forwards the task information to the source edge task plug-in module; if it is illegal, the message is discarded and not processed; Task abnormality status reporting: When an abnormality occurs during task execution by the destination edge task plug-in module, the load balancing strategy interface configured by Nacos is called to obtain the information of the central task scheduling module, and the task abnormality status message is reported to the central task scheduling module through the gRPC protocol; when the central task scheduling module receives the task abnormality status message, it determines whether the message is legal; if it is legal, the task status in the database cluster is updated as abnormal according to the task unique number, and the update time is the time carried by the message. At the same time, the load balancing strategy interface configured by Nacos is called to obtain the source edge task plug-in module information, and the task information is forwarded to the source edge task plug-in module; if it is illegal, the message is discarded and not processed; 7) When Nacos load balancing distributes messages, it includes: Edge task plug-in module message load balancing: When the edge task plug-in module needs to report task health, completion, and abnormal status messages to the central task scheduling module, call the load balancing strategy interface configured by Nacos to obtain the central task scheduling module information. After receiving the interface request, Nacos obtains all IP, port, and weight information of the central task scheduling module through the interface parameter service name and group information; through random, polling, weight, and minimum number of connections, these load balancing strategies are used to return the optimal central task scheduling module IP and port; Central task scheduling module message load balancing: When the central task scheduling module needs to send task addition and deletion messages to the edge task plug-in module, it calls the load balancing strategy interface configured by Nacos to obtain the edge task plug-in module information; after receiving the interface request, Nacos obtains all IP, port, and weight information of the edge task plug-in module through the interface parameter service name and group information; through the random, polling, weight, and minimum number of connections, these load balancing strategies are used to return the optimal central task scheduling module IP and port.

[0008] The method for realizing multi-task scheduling and load balancing based on springboot is characterized in that the polling means: selecting modules in sequence according to the order of the module list, which is suitable for the situation that all modules need to have uniform load; random means: randomly selecting a module for calling, which is suitable for the situation that the number of modules is large and the load difference is large; weight means: selecting modules according to the weight of the modules, and the modules with higher weights have a higher probability of being selected; the minimum number of connections means: selecting the module with the least current number of connections, which is suitable for the situation that each module needs to balance the current number of connections.

[0009] The method for implementing multi-task scheduling and load balancing based on springboot is characterized in that the application integrates the edge task plug-in module, which means that the SpringBoot version of the edge task plug-in module must be consistent with the SpringBoot version of the application, the edge task plug-in module is packaged into a jar package and uploaded to the Maven library, and the application service introduces the edge task plug-in module jar package Maven information in the POM; The gRPC information configuration refers to: creating a new gRPC configuration file in the Nacos configuration center, configuring the gRPC port information required by the module, and the gRPC IP information will automatically obtain the local external IP during system startup; The asynchronous task issuing thread pool configuration refers to: creating a new thread pool configuration file in the Nacos configuration center, configuring relevant thread pool information, including: the number of core threads, the maximum number of threads, the buffer queue, the system shutdown thread pool waiting time, the thread name, and the thread pool strategy; The task restriction information configuration refers to: a task restriction configuration file in the Nacos configuration center, task restriction information in JSON string format, Key is the group to be restricted, and Value is a set of restricted quantities.

[0010] The method for implementing multi-task scheduling and load balancing based on springboot is characterized in that the conditions for judging whether the task message is legal in step 5) are as follows: whether it is an empty request, whether the task unique label is not empty and unique, whether the type is empty, whether the source service is empty, whether the destination service is empty, whether the task start time is empty and less than the task end time, whether the task end time is empty and greater than the task start time, whether the task details are empty and are JSON strings, whether the task group is empty, and whether the cache identifier is empty. If any of the above conditions is not met, it is illegal.

[0011] The method for implementing multi-task scheduling and load balancing based on springboot is characterized in that the condition for judging whether the task is limited in concurrency in step 5) is as follows: when the task group exists in the set of concurrency restrictions and the number of tasks being executed by the task group is greater than the restricted number, concurrency is restricted.

[0012] The method for implementing multi-task scheduling and load balancing based on springboot is characterized in that the condition for judging whether the task status message is legal in step 6) is as follows: if the reporting time in the task status message is less than the current system time, it is legal.

[0013] The present invention is based on the SpringBoot framework. Any application developed based on SpringBoot can integrate the edge task plug-in module to realize message interaction with the central task scheduling module, so as to realize the functions of task control message sending and task status message reporting, thereby reducing the development workload and later maintenance workload of developers; through multi-task load balancing scheduling, automatic offline of module failure, automatic online of module expansion and other operations, the problems of low resource utilization, long response time, high pressure, lack of flexibility (unable to adjust dynamically, lack of fault tolerance mechanism) of single application are solved, and the present invention can be applied to various software systems involving multi-task scheduling and load balancing requirements. BRIEF DESCRIPTION OF THE DRAWINGS

[0014] Figure 1 This is a schematic diagram of the entire process of multi-task scheduling and load balancing of the present invention; Figure 2 It is a flow chart of module registration of the present invention; Figure 3 A new message sending flow chart is added for the task of the present invention; Figure 4 This is a flow chart of sending a task deletion message of the present invention; Figure 5 The task health status reporting flow chart of the present invention; Figure 6 This is a flowchart for reporting the task completion status of the present invention; Figure 7 This is a flowchart for reporting abnormal status of tasks in the present invention. DETAILED DESCRIPTION

[0015] The present invention will be further described below in conjunction with the accompanying drawings: A method for implementing multi-task scheduling and load balancing based on SpringBoot includes an edge task plug-in module, a central task scheduling module, Nacos and a database cluster.

[0016] The edge task plug-in module is used to be integrated in related applications. When the edge task plug-in module completes module registration on Nacos (including service name, group name, weight, IP address and port, etc.), it only needs to call the relevant API to complete the communication and related operations between modules. Including: sending task control messages according to user instructions (such as: adding tasks, deleting tasks); reporting task status messages according to task execution status (such as: task health, task completion, task abnormality); receiving task control messages and task status messages, and performing corresponding operations.

[0017] The central task scheduling module is used for centralized scheduling and management of multiple tasks. After the central task scheduling module completes module registration on Nacos (including service name, group name, weight, IP address and port, etc.), it only needs to call the relevant API to complete the communication and related operations between modules. Including: receiving the task control message sent by the source edge task plug-in module, parsing the message and saving it in the database cluster, and forwarding the message to the destination edge task plug-in module; regularly querying the task information saved in the database cluster, when the task processing is abnormal (such as: task timeout), actively sending the task control message (such as: deleting the task) to the destination edge task plug-in module; receiving the task status message reported by the destination edge task plug-in module, parsing the message and updating it in the database cluster, and forwarding the message to the source edge task plug-in module.

[0018] Nacos is used for module registration and configuration center management, including: registering and discovering the central task scheduling module and edge task plug-in module running in the server, distributing message requests through load balancing strategies (such as random, polling, weight, minimum number of connections, etc.); saving various configuration files required by the module. When the module starts, it reads the relevant configuration files from Nacos. When the module is running, it can modify the Nacos configuration file to achieve hot update of the configuration.

[0019] The database cluster is used to save task information. The task information table mainly includes: unique ID, task unique number, task type, source service, destination service, task start time, task end time, task details, task status, creation time, update time, task group, cache identifier, and remarks. When the central task scheduling module receives the task information, it saves the task information to the task information table of the database cluster to support subsequent operations and management of the task.

[0020] The process of the present invention includes: module registration, task control message sending, and task status message reporting. When the module is registered, the edge task plug-in module and the central task processing module register their own relevant information (including service name, group name, weight, IP address and port, etc.) in Nacos, and each module finds the corresponding module information through the service name. When the task control message is sent, the source edge task plug-in module calls the API, sends the task control message to the central task scheduling module, and the central task scheduling module forwards the message to the corresponding destination edge task plug-in module. The destination edge task plug-in module performs corresponding operation processing after receiving the message. When the task status message is reported, the destination edge task plug-in module calls the API according to the task processing situation, reports the task status message to the central task scheduling module, and the central task scheduling module forwards the message to the corresponding source edge task plug-in module. The source edge task plug-in module performs corresponding operation processing after receiving the message.

[0021] The task control message field of the present invention includes unique ID, task unique number, task type, source service, destination service, task start time, task end time, task details, task group, cache identifier, and remarks information; the task status message field includes: task unique number, time, and task status.

[0022] The method of the present invention comprises the following steps: 1) Start the Nacos service and database cluster service first; before the application is started, the edge task plug-in module will be integrated and registered in Nacos; before the central task scheduling module is started, it will be registered in Nacos and the database cluster will be configured; the details are as follows: Edge task plug-in module integration: Package the edge task plug-in module into a jar package, integrate the edge task plug-in module jar package into the application and develop it. The application SpringBoot version must be consistent with the edge task plug-in module version. Finally, package the executable program containing the edge task plug-in module and configure the corresponding gRPC information. Nacos configuration: Use the java startup command: -Dnacos.config.server-addr and -Dnacos.config.namespace. nacos.config.server-addr includes the IP address and port of Nacos, and nacos.config.namespace is the namespace name of Nacos; Start Nacos service: Unzip Nacos and unzip the downloaded Nacos package to the specified directory. Run Nacos, enter the bin directory of Nacos, and run the corresponding startup script. For stand-alone mode, you can directly run the startup script of Nacos. In Linux environment, you can use the following command: . / bin / startup.sh -m standalone.

[0023] 2) When the edge task plug-in module is started, it obtains relevant configuration parameters from the Nacos configuration center, obtains the external IP information of the server, starts its own service IP, port, gRPC IP and port, and registers the gRPC IP, port address and weight to the Nacos list. Start the task monitoring thread and report the health status of the tasks being executed regularly.

[0024] 3) Before the central task scheduling module runs, perform the asynchronous task delivery thread pool configuration, task restriction information configuration, gRPC information configuration, and database cluster configuration, and finally start the database cluster service.

[0025] 4) When the central task scheduling module is started, it obtains relevant configuration parameters from the Nacos configuration center, connects to the database cluster according to the configuration, obtains the external IP information of the server, starts its own service IP, port, gRPC IP and port, and registers the gRPC IP and port address to Nacos. Start the task processing thread to process the task control message and task status message.

[0026] 5) The user sends task control messages through the edge task plug-in module, including: Sending new task messages: The source edge task plug-in module sends new task messages (unique ID, task unique number, task type, source service, destination service, task start time, task end time, task details, task group, cache identifier, and remarks), calls the load balancing strategy interface configured by Nacos (such as random, round-robin, weight, minimum number of connections, etc.) to obtain the central task scheduling module information, and sends new task messages to the central task scheduling module through the gRPC protocol. After receiving the new message, the central task scheduling module determines whether the message is legal (such as whether it is an empty request, whether the task unique number is not empty and unique, whether the type is empty, whether the source service is empty, whether the destination service is empty, whether the task start time is empty and less than the task end time, whether the task end time is empty and greater than the task start time, whether the task details are empty and a JSON string, whether the task group is empty, and whether the cache identifier is empty). If it is legal, the task information is saved in the database cluster. Then determine whether the task reaches the concurrency limit (for example, when the task group is in the set of concurrency limits, and the number of tasks being executed by the task group is greater than the limit) and whether to cache. If there is no limit or it is less than the concurrency limit, the message is forwarded directly, otherwise the task is cached or rejected. When forwarding messages, the central task scheduling module calls the load balancing strategy interface configured by Nacos (such as random, polling, weight, minimum number of connections, etc.) to obtain the destination edge task plug-in module information, and forwards the message to the destination edge task plug-in module through the gRPC protocol. After the destination edge task plug-in module successfully receives the task addition message, it processes it according to the task information.

[0027] Sending a task deletion message: The source edge task plug-in module sends a task deletion message (such as unique ID, task unique number, and remarks), calls the load balancing strategy interface configured by Nacos (such as random, round-robin, weight, minimum number of connections, etc.) to obtain the central task scheduling module information, and sends the task deletion message to the central task scheduling module through the gRPC protocol. When the central task scheduling receives the deletion message or monitors the task processing exception regularly, it calls the load balancing strategy interface configured by Nacos (such as random, round-robin, consistent hashing and weighted round-robin, etc.) to obtain the destination edge task plug-in module information, and sends a message to the destination edge task plug-in module through the gRPC protocol. After the destination edge task plug-in module successfully receives the task deletion message, it deletes the task according to the task unique number.

[0028] 6) The edge task plug-in module reports the task status when processing the task, including: Task health status reporting: The destination edge task plug-in module periodically queries the health status of the task being executed, calls the load balancing strategy interface configured by Nacos (such as random, polling, consistent hashing and weighted polling, etc.) to obtain the central task scheduling module information, and reports the task health status message (task unique number, time, task status) to the central task scheduling module through the gRPC protocol. When the central task scheduling module receives the task health status message, it determines whether the message is legal (such as: the reporting time is less than the current system time). If legal, the task status in the database cluster is updated to healthy according to the task unique number, and the update time is the time carried by the message. At the same time, the load balancing strategy interface configured by Nacos (such as random, polling, weight, minimum number of connections, etc.) is called to obtain the source edge task plug-in module information, and the task information is forwarded to the source edge task plug-in module; if illegal, the message is discarded and not processed.

[0029] Task completion status reporting: After the destination edge task plug-in module completes the task normally, it calls the load balancing strategy interface configured by Nacos (such as random, polling, consistent hashing and weighted polling, etc.) to obtain the central task scheduling module information, and reports the task completion status message (task unique number, time, task status) to the central task scheduling module through the gRPC protocol. When the central task scheduling module receives the task completion status message, it determines whether the message is legal (such as: the reporting time is less than the current system time). If legal, the task information in the database cluster is deleted according to the task unique number, indicating that the task has been executed normally. At the same time, the load balancing strategy interface configured by Nacos (such as random, polling, weight, minimum number of connections, etc.) is called to obtain the source edge task plug-in module information, and the task information is forwarded to the source edge task plug-in module; if illegal, the message is discarded and not processed.

[0030] Reporting of task abnormality status: When an abnormality occurs during the execution of a task by the destination edge task plug-in module, the load balancing strategy interface configured by Nacos (such as random, round-robin, weight, minimum number of connections, etc.) is called to obtain the information of the central task scheduling module, and the task abnormality status message (task unique number, time, task status) is reported to the central task scheduling module through the gRPC protocol. When the central task scheduling module receives the task abnormality status message, it determines whether the message is legal (such as: the reporting time is less than the current system time). If legal, the task status in the database cluster is updated as abnormal according to the task unique number, and the update time is the time carried by the message. At the same time, the load balancing strategy interface configured by Nacos (such as random, round-robin, weight, minimum number of connections, etc.) is called to obtain the source edge task plug-in module information, and the task information is forwarded to the source edge task plug-in module; if illegal, the message is discarded and not processed.

[0031] 7) When Nacos load balancing distributes messages, it includes: Edge task plug-in module message load balancing: When the edge task plug-in module needs to report task health, completion, exception and other status messages to the central task scheduling module, call the load balancing strategy interface configured by Nacos (where parameters include service name, group name, strategy mode, etc.) to obtain the central task scheduling module information. After receiving the interface request, Nacos obtains all IP, port, and weight information of the central task scheduling module through the interface parameter service name and group information. Through random, polling, weight, minimum number of connections and other load balancing strategies, return the optimal central task scheduling module IP and port; Central task scheduling module message load balancing: When the central task scheduling module needs to send messages such as task addition and deletion to the edge task plug-in module, it calls the load balancing strategy interface configured by Nacos (where the parameters include service name, group name, strategy mode, etc.) to obtain the edge task plug-in module information. After receiving the interface request, Nacos obtains all IP, port, and weight information of the edge task plug-in module through the interface parameter service name and group information. Through random, polling, weight, minimum number of connections and other load balancing strategies, it returns the optimal central task scheduling module IP and port.

[0032] Among them, polling means: selecting modules in the order of the module list, which is suitable for the situation where all modules need to have a balanced load. Random means: randomly selecting a module to call, which is suitable for the situation where there are a large number of modules and the load difference is large. Weight means: selecting modules according to the weight of the module, and the module with a higher weight is more likely to be selected. Minimum number of connections means: selecting the module with the least current number of connections, which is suitable for the situation where each module needs to balance the current number of connections.

[0033] The application of the present invention integrates the edge task plug-in module, which means that the SpringBoot version of the edge task plug-in module must be consistent with the SpringBoot version of the application. The edge task plug-in module is packaged into a jar package and uploaded to the Maven library, and the application service introduces the edge task plug-in module jar package Maven information in the POM.

[0034] gRPC information configuration means: create a new gRPC configuration file in the Nacos configuration center, configure the gRPC port information required by the module, and the gRPC IP information will automatically obtain the local external IP when the system starts.

[0035] Asynchronous task delivery thread pool configuration means: creating a new thread pool configuration file in the Nacos Configuration Center and configuring related thread pool information, including: number of core threads, maximum number of threads, buffer queue, system shutdown thread pool waiting time, thread name, and thread pool strategy.

[0036] Task restriction information configuration refers to: task restriction configuration file in Nacos configuration center, task restriction information is in JSON string format, Key is the group to be restricted, and Value is the set of restricted quantities.

[0037] The conditions for judging whether the task message is legal in the above step 5) are as follows: whether it is an empty request, whether the task unique number is not empty and unique, whether the type is empty, whether the source service is empty, whether the destination service is empty, whether the task start time is empty and less than the task end time, whether the task end time is empty and greater than the task start time, whether the task details are empty and a JSON string, whether the task group is empty, whether the cache identifier is empty. If any of the above conditions is not met, the judgment is illegal.

[0038] The condition for determining whether the task is restricted in concurrency in the above step 5) is as follows: when the task group exists in the set of concurrency restrictions and the number of tasks being executed by the task group is greater than the restricted number, concurrency is restricted.

[0039] The condition for judging whether the task status message is legal in the above step 6) is as follows: if the reporting time in the task status message is less than the current system time, it is legal.

[0040] The present invention will be further described with reference to the accompanying drawings: The edge task plug-in module is used to integrate into related applications. When the edge task plug-in module completes module registration on Nacos (see Figure 1 After that, you only need to call the relevant API to complete the communication and related operations between modules.

[0041] The module task process includes: sending task control and reporting task status. Sending task control means that the source edge task plug-in module calls the Nacos API to obtain the central task scheduling module information (see Appendix Figure 1 ②), the task control message is sent to the central task scheduling module through the gRPC protocol (see Appendix Figure 1 After receiving the control message, the central task scheduling module saves the task information to the database cluster (see Appendix Figure 1 At the same time, the central task scheduling module calls the Nacos API to obtain the target edge task plug-in module information (see Appendix Figure 1 ⑤), forward the message to the destination edge task plug-in module (see Appendix) through the gRPC protocol. Figure 1 After the destination edge task plug-in module successfully receives the task control message, it performs corresponding operations according to the task control information.

[0042] When the central task scheduling module detects task processing exceptions, it calls the Nacos API to obtain the target edge task plug-in module information (see Appendix Figure 1 ⑤), send task control messages to the destination edge task plug-in module through the gRPC protocol (see Appendix Figure 1 After the destination edge task plug-in module successfully receives the task control message, it performs corresponding operations according to the task control information.

[0043] Reporting task status means that the target edge task plug-in module calls the Nacos API to obtain the central task scheduling module information (see Appendix Figure 1 ⑧), report the task status message to the central task scheduling module through the gRPC protocol (see Appendix Figure 1 After receiving the message, the central task scheduling module updates the task information to the database cluster (see Appendix Figure 1 At the same time, the central task scheduling module calls the Nacos API to obtain the source edge task plug-in module information (see Appendix Figure 1 ⑤), forward the message to the source edge task plug-in module (see Appendix) through the gRPC protocol. Figure 1 After the source edge task plug-in module successfully receives the task control message, it performs corresponding operations according to the task status information.

[0044] The edge task plug-in module of the present invention can be integrated into any application developed based on the SpringBoot framework. The central task scheduling module centrally manages tasks, and R&D personnel can improve efficiency, enhance code quality, promote agile development, reduce risks, and promote innovation. Enterprises can reduce personnel costs, improve efficiency, and promote innovation capabilities and market competitiveness.

[0045] Notes: SpringBoot: is an open source project based on the Spring framework, which aims to simplify the initial construction of Spring applications and the complexity of the development process. Spring Boot provides an out-of-the-box experience that allows developers to quickly build independent, production-level Spring-based applications.

[0046] Nacos: is the acronym for Dynamic Naming and Configuration Service, a dynamic service discovery, configuration management and service management platform that makes it easier to build cloud-native applications. Nacos is committed to helping you discover, configure and manage microservices. Nacos provides a set of simple and easy-to-use feature sets to help you quickly implement dynamic service discovery, service configuration, service metadata and traffic management. Nacos helps you build, deliver and manage microservice platforms more agilely and easily. Nacos is a service infrastructure for building modern application architectures centered on "services" (such as microservice paradigms and cloud-native paradigms).

[0047] gRPC: gRPC is a modern, open source, high-performance remote procedure call (RPC) framework that can run in any environment. It can efficiently connect services within and across data centers, supporting load balancing, tracking, health checks, and authentication. It is also suitable for the last mile of distributed computing, connecting devices, mobile applications, and browsers to backend services.

[0048] API: (Application Programming Interface) is a software architecture design that defines how different software components interact with each other. API allows different software modules to communicate with each other without knowing each other's internal implementation details. API plays a vital role in modern software development, especially in the fields of distributed systems, microservice architecture, mobile application development, and web services.

[0049] jar: In Java projects, .jar (Java ARchive) files are a commonly used packaging format for packaging multiple class files, related metadata, and other resources (such as images, configuration files, etc.). .jar files can contain not only compiled bytecode files (.class files), but also dependent libraries and other resource files.

[0050] POM: In Java projects, especially those using Maven build tools, the pom.xml (ProjectObject Model) file is the core configuration file of the project. It contains the metadata and build settings of the project, including dependency management, build lifecycle, plug-in configuration, and other project-related information.

[0051] Maven: Maven is a popular Java project management and build tool that helps developers manage project builds, dependencies, and documentation by providing a project object model (POM). Maven's design philosophy is "convention over configuration", which means that Maven simplifies project management and build processes through predefined directory structures and build lifecycles.

Claims

1. A method for implementing multi-task scheduling and load balancing based on springboot, characterized in that Includes edge task plug-in module, central task scheduling module, Nacos and database cluster; The edge task plug-in module is used to be integrated in related applications. After the edge task plug-in module completes module registration on Nacos, it only needs to call the relevant API to complete the communication and related operations between modules; including: sending task control messages according to user instructions; reporting task status messages according to task execution status; receiving task control messages and task status messages, and performing corresponding operations; The central task scheduling module is used for centralized scheduling and management of multiple tasks. After the central task scheduling module completes module registration on Nacos, it only needs to call the relevant API to complete the communication and related operations between modules; including: receiving the task control message sent by the source edge task plug-in module, parsing the message and saving it in the database cluster, and forwarding the message to the destination edge task plug-in module; regularly querying the task information saved in the database cluster, and actively sending the task control message to the destination edge task plug-in module when the task processing is abnormal; receiving the task status message reported by the destination edge task plug-in module, parsing the message and updating it in the database cluster, and forwarding the message to the source edge task plug-in module; Nacos is used for module registration and configuration center management, including: registering and discovering the central task scheduling module and edge task plug-in module running in the server, and distributing message requests through load balancing strategies; saving various configuration files required by the module; reading relevant configuration files from Nacos when the module starts, and implementing configuration hot updates by modifying the Nacos configuration files when the module is running; The database cluster is used to save task information. The task information table contains: unique ID, task unique number, task type, source service, destination service, task start time, task end time, task details, task status, creation time, update time, task group, cache identifier, and remarks information. When the central task scheduling module receives the task information, it saves the task information to the task information table of the database cluster to support subsequent related operations and management of the task.

2. According to claim 1, a method for realizing multi-task scheduling and load balancing based on springboot is characterized in that It includes the following processes: module registration, task control message sending, and task status message reporting; when registering the module, the edge task plug-in module and the central task processing module register their own relevant information in Nacos, and each module finds the corresponding module information through the service name; when the task control message is sent, the source edge task plug-in module calls the API to send the task control message to the central task scheduling module, and the central task scheduling module forwards the message to the corresponding destination edge task plug-in module. After receiving the message, the destination edge task plug-in module performs the corresponding operation processing; when reporting the task status message, the destination edge task plug-in module calls the API according to the task processing situation and reports the task status message to the central task scheduling module. The central task scheduling module forwards the message to the corresponding source edge task plug-in module. After receiving the message, the source edge task plug-in module performs the corresponding operation processing.

3. According to claim 2, a method for realizing multi-task scheduling and load balancing based on springboot is characterized in that The task control message fields include unique ID, task unique number, task type, source service, destination service, task start time, task end time, task details, task group, cache identifier and remarks; The task status message fields include: task unique number, time and task status.

4. According to claim 1, a method for realizing multi-task scheduling and load balancing based on springboot is characterized in that The steps include: 1) Before starting the edge task plug-in module, package the edge task plug-in module into a jar package, integrate the edge task plug-in module jar package into the application and develop it, and finally package it into an executable application and configure the corresponding gRPC information; 2) When the edge task plug-in module is started, it obtains relevant configuration parameters from the Nacos configuration center, obtains the external IP information of the server, starts its own service IP, port, gRPC IP and gRPC port, and registers the gRPC IP, gRPC port address and weight to Nacos; Start the task monitoring thread and report the health status of the tasks being executed regularly; 3) Before the central task scheduling module runs, perform the asynchronous task delivery thread pool configuration, task restriction information configuration, gRPC information configuration, and database cluster configuration, and finally start the database cluster service; 4) When the central task scheduling module is started, it obtains relevant configuration parameters from the Nacos configuration center, connects to the database cluster according to the configuration, obtains the external IP information of the server, starts its own service IP, port, gRPC IP and gRPC port, and registers the gRPC IP and gRPC port addresses in Nacos; Start the task processing thread to process the task control message and task status message; 5) The user sends task control messages through the edge task plug-in module, including: Sending new task messages: The source edge task plug-in module sends new task messages, calls the load balancing strategy interface configured by Nacos to obtain the information of the central task scheduling module, and sends the new task messages to the central task scheduling module through the gRPC protocol; after receiving the new message, the central task scheduling module determines whether the message is legal. If it is legal, it saves the task information to the database cluster; then determines whether the task reaches the concurrency limit and whether it is cached. If there is no limit or it is less than the concurrency limit, the message is forwarded directly, otherwise the task is cached or rejected; when forwarding the message, the central task scheduling module calls the load balancing strategy interface configured by Nacos to obtain the destination edge task plug-in module information, and forwards the message to the destination edge task plug-in module through the gRPC protocol; after the destination edge task plug-in module successfully receives the new task message, it processes it according to the task information; Sending a task deletion message: The source edge task plug-in module sends a task deletion message, calls the load balancing strategy interface configured by Nacos to obtain the central task scheduling module information, and sends a task deletion message to the central task scheduling module through the gRPC protocol; when the central task scheduling receives the deletion message or monitors the task processing exception regularly, it calls the load balancing strategy interface configured by Nacos to obtain the destination edge task plug-in module information, and sends a message to the destination edge task plug-in module through the gRPC protocol; after the destination edge task plug-in module successfully receives the task deletion message, it deletes the task according to the task unique number; 6) The edge task plug-in module reports the task status when processing the task, including: Task health status reporting: The destination edge task plug-in module periodically queries the health status of the task being executed, calls the load balancing strategy interface configured by Nacos to obtain the central task scheduling module information, and reports the task health status message to the central task scheduling module through the gRPC protocol; when the central task scheduling module receives the task health status message, it determines whether the message is legal. If legal, the task status in the database cluster is updated to healthy according to the task unique number, and the update time is the time carried by the message. At the same time, the load balancing strategy interface configured by Nacos is called to obtain the source edge task plug-in module information, and the task information is forwarded to the source edge task plug-in module; if illegal, the message is discarded and not processed; Task completion status reporting: After the destination edge task plug-in module completes the task normally, it calls the load balancing strategy interface configured by Nacos to obtain the central task scheduling module information, and reports the task completion status message to the central task scheduling module through the gRPC protocol; when the central task scheduling module receives the task completion status message, it determines whether the message is legal; if it is legal, it deletes the task information in the database cluster according to the task unique number, indicating that the task has been executed normally, and at the same time calls the load balancing strategy interface configured by Nacos to obtain the source edge task plug-in module information, and forwards the task information to the source edge task plug-in module; if it is illegal, the message is discarded and not processed; Task abnormality status reporting: When an abnormality occurs during task execution by the destination edge task plug-in module, the load balancing strategy interface configured by Nacos is called to obtain the information of the central task scheduling module, and the task abnormality status message is reported to the central task scheduling module through the gRPC protocol; when the central task scheduling module receives the task abnormality status message, it determines whether the message is legal; if it is legal, the task status in the database cluster is updated as abnormal according to the task unique number, and the update time is the time carried by the message. At the same time, the load balancing strategy interface configured by Nacos is called to obtain the source edge task plug-in module information, and the task information is forwarded to the source edge task plug-in module; if it is illegal, the message is discarded and not processed; 7) When Nacos load balancing distributes messages, it includes: Edge task plug-in module message load balancing: When the edge task plug-in module needs to report task health, completion, and abnormal status messages to the central task scheduling module, call the load balancing strategy interface configured by Nacos to obtain the central task scheduling module information. After receiving the interface request, Nacos obtains all IP, port, and weight information of the central task scheduling module through the interface parameter service name and group information; through random, polling, weight, and minimum number of connections, these load balancing strategies are used to return the optimal central task scheduling module IP and port; Central task scheduling module message load balancing: When the central task scheduling module needs to send task addition and deletion messages to the edge task plug-in module, it calls the load balancing strategy interface configured by Nacos to obtain the edge task plug-in module information; after receiving the interface request, Nacos obtains all IP, port, and weight information of the edge task plug-in module through the interface parameter service name and group information; through the random, polling, weight, and minimum number of connections, these load balancing strategies are used to return the optimal central task scheduling module IP and port.

5. According to claim 4, a method for realizing multi-task scheduling and load balancing based on springboot is characterized in that The polling means: selecting modules in the order of the module list, which is suitable for the situation where all modules need to have a uniform load; random means: randomly selecting a module for calling, which is suitable for the situation where there are a large number of modules and the load difference is large; weight means: selecting modules according to the weight of the modules, and the modules with higher weights have a higher probability of being selected; the minimum number of connections means: selecting the module with the least current number of connections, which is suitable for the situation where each module needs to balance the current number of connections.

6. According to claim 4, a method for realizing multi-task scheduling and load balancing based on springboot is characterized in that The application integrates the edge task plug-in module means: the SpringBoot version of the edge task plug-in module must be consistent with the SpringBoot version of the application, the edge task plug-in module is packaged into a jar package and uploaded to the Maven library, and the application service introduces the edge task plug-in module jar package Maven information in the POM; The gRPC information configuration refers to: creating a new gRPC configuration file in the Nacos configuration center, configuring the gRPC port information required by the module, and the gRPC IP information will automatically obtain the local external IP during system startup; The asynchronous task issuing thread pool configuration refers to: creating a new thread pool configuration file in the Nacos configuration center, configuring relevant thread pool information, including: the number of core threads, the maximum number of threads, the buffer queue, the system shutdown thread pool waiting time, the thread name, and the thread pool strategy; The task restriction information configuration refers to: a task restriction configuration file in the Nacos configuration center, task restriction information in JSON string format, Key is the group to be restricted, and Value is a set of restricted quantities.

7. According to claim 4, a method for realizing multi-task scheduling and load balancing based on springboot is characterized in that The conditions for judging whether the task message is legal in step 5) are as follows: whether it is an empty request, whether the task unique label is not empty and unique, whether the type is empty, whether the source service is empty, whether the destination service is empty, whether the task start time is empty and less than the task end time, whether the task end time is empty and greater than the task start time, whether the task details are empty and a JSON string, whether the task group is empty, whether the cache identifier is empty. If any of the above conditions is not met, the judgment is illegal.

8. According to claim 4, a method for realizing multi-task scheduling and load balancing based on springboot is characterized in that The condition for determining whether the task is restricted in concurrency in step 5) is as follows: when the task group exists in the set of concurrency restrictions and the number of tasks being executed by the task group is greater than the restricted number, concurrency is restricted.

9. According to claim 4, a method for realizing multi-task scheduling and load balancing based on springboot is characterized in that The condition for judging whether the task status message is legal in step 6) is as follows: if the reporting time in the task status message is less than the current system time, it is legal.

Citation Information

Patent Citations

  • Method, device and system for controlling Internet of Things equipment

    CN112995348A

  • Plug-in scheduling method, system and device based on Elastic job and storage medium

    CN113703940A

  • Client load balancing method and system with Kong adapted to Nacos

    CN115225641A

  • Gateway load balancing method based on Nacos

    CN116346725A

  • Distributed task scheduling method, system and equipment and storage medium

    CN118069319A