CN111813515A - Multi-process-based task scheduling method and device, computer equipment and medium - Google Patents

Multi-process-based task scheduling method and device, computer equipment and medium Download PDF

Info

Publication number
CN111813515A
CN111813515A CN202010610172.6A CN202010610172A CN111813515A CN 111813515 A CN111813515 A CN 111813515A CN 202010610172 A CN202010610172 A CN 202010610172A CN 111813515 A CN111813515 A CN 111813515A
Authority
CN
China
Prior art keywords
task
basic
new
node
time
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202010610172.6A
Other languages
Chinese (zh)
Other versions
CN111813515B (en
Inventor
邹芳
黄鹏
赵永超
李彦良
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Life Insurance Company of China Ltd
Original Assignee
Ping An Life Insurance Company of China Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Life Insurance Company of China Ltd filed Critical Ping An Life Insurance Company of China Ltd
Priority to CN202010610172.6A priority Critical patent/CN111813515B/en
Publication of CN111813515A publication Critical patent/CN111813515A/en
Application granted granted Critical
Publication of CN111813515B publication Critical patent/CN111813515B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • G06F9/485Task life-cycle, e.g. stopping, restarting, resuming execution
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • G06F9/4881Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • G06F9/5038Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals considering the execution order of a plurality of tasks, e.g. taking priority or time dependency constraints into consideration

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a method, a device, computer equipment and a medium for task scheduling based on multiprocess, which comprises the following steps: analyzing each basic task to obtain a start time and an end time, sequencing according to the start time to obtain a task sequence, initializing a minimum heap binary tree, writing the end time of a first basic task of the task sequence into a node key value of the minimum heap binary tree, constructing a task process to execute the first basic task, generating a new branch for the minimum heap binary tree according to an ith basic task in the task sequence when the current time is the start time of the basic task and if a time point corresponding to a root node key value in the minimum heap binary tree is behind the current time, writing the corresponding end time into a node key value of the new branch, and constructing a task process corresponding to the new branch to execute the ith basic task. The invention improves the task scheduling efficiency. The invention also relates to a block chain technology, and the obtained minimum heap binary tree is stored in the block chain.

Description

Multi-process-based task scheduling method and device, computer equipment and medium
Technical Field
The present invention relates to the field of data processing, and in particular, to a method, an apparatus, a computer device, and a medium for scheduling a task based on multiple processes.
Background
Many fields relate to task scheduling, which is a decision problem in reality, such as cluster task allocation, factory pipeline task allocation, task allocation of RAP robots, etc., how to reasonably allocate various limited resources to each pipeline/sub-node, so that obtaining a large benefit with relatively low cost investment is a goal pursued by each task scheduling. The task scheduling problem meets certain conditions: the resources to be allocated are limited; the benefits created by allocating resources to different projects are different, and thus the problem arises of how to allocate tasks to optimize the project objectives or production goals.
For the task scheduling problem, the prior art uses the ideas of the traditional artificial intelligence search method and the recalling method, and optimizes the task scheduling problem by a pruning method. Theoretically, the algorithm can calculate the problem of optimal allocation resources. However, for a comparatively large resource and task number, the search method and backtracking method obviously take time, the time complexity is very fast to increase the exponential order O (2^ n), otherwise even if n is only 100, the method consumes extremely much running time, and the execution efficiency is too low to be applied to practical engineering, so that finding a method for efficiently scheduling tasks becomes an urgent problem to be solved.
Disclosure of Invention
The embodiment of the invention provides a task scheduling method and device based on multiple processes, computer equipment and a storage medium, so as to improve the task scheduling efficiency.
In order to solve the above technical problem, an embodiment of the present application provides a method for task scheduling based on multiple processes, including:
acquiring each basic task to be processed, and analyzing the basic task to obtain the starting time and the ending time of the basic task;
sequencing the basic tasks based on the sequence of the starting time to obtain a task sequence;
initializing a minimum heap binary tree, writing the end time of a first basic task of the task sequence into a node key value of the minimum heap binary tree, constructing a task process, and executing the first basic task in the task sequence by using the task process, wherein each branch of the minimum heap binary tree indicates one task process;
for the ith basic task in the task sequence, when the current time is the starting time of the basic task, if the time point corresponding to the root node key value in the minimum heap binary tree is behind the current time, generating a new branch for the minimum heap binary tree, and writing the end time corresponding to the ith basic task into the node key value of the new branch, wherein i is a positive integer greater than 1;
and constructing a task process corresponding to the new branch, and executing the ith basic task by using the task process corresponding to the new branch.
Optionally, after the basic tasks are sequenced based on the sequence of the start times to obtain a task sequence, the method for scheduling tasks based on multiple processes further includes:
receiving new task data, and acquiring the starting time of the new task data and the ending time of the new task data;
randomly selecting a position from the task sequence as an initial position of the new task data;
and adjusting and sequencing by adopting a dichotomy method based on the initial position and the start time of the new task data to obtain an updated task sequence.
Optionally, the constructing a task process, and the executing a first basic task in the task sequence using the task process includes:
establishing a fixed-length thread pool in the task process according to a preset thread number;
and executing the basic task in the task process through the fixed-length thread pool.
Optionally, after the initializing the minimum heap binary tree, writing the end time of the first basic task of the task sequence into the node key value of the minimum heap binary tree, and constructing a task process, and executing the first basic task of the task sequence using the task process, the method for scheduling a task based on multiprocessing further includes:
regularly acquiring a time point corresponding to a root node key value, and comparing the time point corresponding to the root node key value with the acquired time point to obtain a comparison result;
if the comparison result is that the time point corresponding to the root node key assignment is before the acquisition time point, node sinking is carried out on the root node to serve as an updated child node, and a new root node is constructed;
and destroying the task process corresponding to the updated child node.
Optionally, if the comparison result is that the time point corresponding to the root node key value is before the obtaining time point, performing node sinking on the root node to serve as an updated child node, and constructing a new root node includes:
selecting any child node from the child nodes of the root node as a target child node;
inserting a new node into the root node and the target child node to serve as an intermediate node, wherein the initial value of the key value of the intermediate node is null;
and exchanging the key assignments of the root node and the intermediate node, updating the node index, taking the sunk root node as an updated child node, and taking the updated intermediate node as the new root node.
Optionally, the method for scheduling tasks based on multiple processes further includes: the resulting minimum heap binary tree is stored in the blockchain network nodes.
In order to solve the foregoing technical problem, an embodiment of the present application further provides a task scheduling apparatus based on multiple processes, including:
the information analysis module is used for acquiring each basic task to be processed, analyzing the basic task and obtaining the starting time and the ending time of the basic task;
the task sequencing module is used for sequencing the basic tasks based on the sequence of the starting time to obtain a task sequence;
a process construction module, configured to initialize a minimum heap binary tree, write an end time of a first basic task of the task sequence into a node key value of the minimum heap binary tree, construct a task process, and execute the first basic task in the task sequence using the task process, where each branch of the minimum heap binary tree indicates one task process;
a branch generating module, configured to generate, for an ith basic task in a task sequence, a new branch for the minimum heap binary tree if a time point corresponding to a root node key value in the minimum heap binary tree is after a current time when the current time is a start time of the basic task, and write an end time corresponding to the ith basic task into a node key value of the new branch, where i is a positive integer greater than 1;
and the multi-process construction module is used for constructing the task process corresponding to the new branch and executing the ith basic task by using the task process corresponding to the new branch.
Optionally, the multiprocess-based task scheduling apparatus further includes:
the new task receiving module is used for receiving new task data and acquiring the starting time of the new task data and the ending time of the new task data;
the position selection module is used for randomly selecting a position from the task sequence as the initial position of the new task data;
and the sequence updating module is used for adjusting and sequencing by adopting a dichotomy based on the initial position and the start time of the new task data to obtain an updated task sequence.
Optionally, the process building module includes:
the thread pool creating module is used for creating a fixed-length thread pool in the task process according to the preset thread quantity;
and the multithreading execution module is used for executing the basic task in the task process through the fixed-length thread pool.
Optionally, the multiprocess-based task scheduling apparatus further includes:
the timing check module is used for regularly acquiring a time point corresponding to a root node key value and comparing the time point corresponding to the root node key value with the acquisition time point to obtain a comparison result;
a node updating module, configured to perform node sinking on the root node as an updated child node and construct a new root node if the comparison result indicates that the time point corresponding to the root node key value is before the obtaining time point;
and the process destroying module is used for destroying the task process corresponding to the updated child node.
Optionally, the node update module includes:
a target node selecting unit, configured to select any child node from the child nodes of the root node as a target child node;
a node inserting unit, configured to insert a new node as an intermediate node into the root node and the target child node, where an initial value of a key value of the intermediate node is null;
and the node updating unit is used for exchanging the key assignments of the root node and the intermediate node, updating the node index, taking the sunk root node as an updated child node, and taking the updated intermediate node as the new root node.
Optionally, the multiprocess-based task scheduling apparatus further includes: the resulting minimum heap binary tree is stored in the blockchain network nodes.
In order to solve the technical problem, an embodiment of the present application further provides a computer device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor implements the steps of the multi-process based task scheduling method when executing the computer program.
In order to solve the above technical problem, an embodiment of the present application further provides a computer-readable storage medium, where a computer program is stored, and the computer program, when executed by a processor, implements the steps of the multi-process based task scheduling method.
The task scheduling method, the device, the computer equipment and the storage medium based on the multiprocess provided by the embodiment of the invention analyze each basic task to be processed to obtain the starting time and the ending time of the basic task, sequence the basic tasks according to the sequence of the starting time to obtain a task sequence, initialize a minimum heap binary tree, write the ending time of a first basic task of the task sequence into a node key value of the minimum heap binary tree, construct a task process, execute the first basic task in the task sequence by using the task process, generate a new branch for the minimum heap binary tree aiming at an ith basic task in the task sequence when the current time is the starting time of the basic task and if a time point corresponding to a root node key value in the minimum heap binary tree is behind the current time, and write the ending time corresponding to the ith basic task into a new node key value of the branch, and finally, constructing a new task process corresponding to the branch, executing the ith basic task by using the task process corresponding to the new branch, and monitoring the task process by adopting a binary tree mode, thereby greatly optimizing the time complexity of task scheduling and improving the efficiency of task scheduling.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the description of the embodiments of the present invention will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art that other drawings can be obtained according to these drawings without inventive labor.
FIG. 1 is an exemplary system architecture diagram in which the present application may be applied;
FIG. 2 is a flow diagram of one embodiment of a multi-process based task scheduling method of the present application;
FIG. 3 is a schematic block diagram illustrating an embodiment of a multiprocess-based task scheduler according to the present application;
FIG. 4 is a schematic block diagram of one embodiment of a computer device according to the present application.
Detailed Description
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs; the terminology used in the description of the application herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application; the terms "including" and "having," and any variations thereof, in the description and claims of this application and the description of the above figures are intended to cover non-exclusive inclusions. The terms "first," "second," and the like in the description and claims of this application or in the above-described drawings are used for distinguishing between different objects and not for describing a particular order.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the application. The appearances of the phrase in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. It is explicitly and implicitly understood by one skilled in the art that the embodiments described herein can be combined with other embodiments.
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Referring to fig. 1, as shown in fig. 1, a system architecture 100 may include terminal devices 101, 102, 103, a network 104 and a server 105. The network 104 serves as a medium for providing communication links between the terminal devices 101, 102, 103 and the server 105. Network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
The user may use the terminal devices 101, 102, 103 to interact with the server 105 via the network 104 to receive or send messages or the like.
The terminal devices 101, 102, 103 may be various electronic devices having display screens and supporting web browsing, including but not limited to smart phones, tablet computers, E-book readers, MP3 players (Moving Picture E interface displays a properties Group Audio Layer III, mpeg compression standard Audio Layer 3), MP4 players (Moving Picture E interface displays a properties Group Audio Layer IV, mpeg compression standard Audio Layer 4), laptop and desktop computers, and the like.
The server 105 may be a server providing various services, such as a background server providing support for pages displayed on the terminal devices 101, 102, 103.
It should be noted that, the multi-process based task scheduling method provided in the embodiments of the present application is executed by a server, and accordingly, a multi-process based task scheduling apparatus is disposed in the server.
It should be understood that the number of terminal devices, networks, and servers in fig. 1 is merely illustrative. Any number of terminal devices, networks and servers may be provided according to implementation needs, and the terminal devices 101, 102 and 103 in this embodiment may specifically correspond to an application system in actual production.
Referring to fig. 2, fig. 2 shows a task scheduling method based on multiple processes according to an embodiment of the present invention, which is described by taking the method applied to the server in fig. 1 as an example, and is detailed as follows:
s201: and acquiring each basic task to be processed, and analyzing the basic task to obtain the starting time and the ending time of the basic task.
Specifically, after receiving the basic tasks to be processed, the start time and the end time of each basic task are obtained by performing data analysis on the basic tasks.
In this embodiment, the start time and the end time are both preset and are fixed times.
For example, in one embodiment, 5 basic tasks to be processed, a1, a2, A3, a4 and a5 are obtained, and after data parsing, the meta-ancestor identifiers of the start time and the end time are obtained as follows: (1, 20), (15, 25), (8, 28), (2, 15) and (21, 50), wherein the first value is the start time and the second value is the end time, (1, 20) indicates that the task start time is 1 and the task end time is 20.
S202: and sequencing the basic tasks based on the sequence of the starting time to obtain a task sequence.
Specifically, a preset ordering mode is adopted, and a task sequence is obtained according to the sequence of the starting time of the basic tasks.
The preset sorting method includes, but is not limited to: bubble sort, selection sort, insertion sort, and count sort, among others.
Continuing with the example in step S10, after the tasks are sorted according to the start time, the obtained sequence is 1, 2, 8, 15, and 21, and the corresponding task sequence is { a1, a4, A3, a2, a5 }.
Preferably, the preset sorting method in this embodiment is an insertion sorting method.
Among them, the Insertion sort (Insertion sort) method is the simplest sort method, and its basic idea is to insert a record into an already sorted list, so that a new sorted list with the number of records increased by 1. The implementation process uses double-layer circulation, the outer layer circulation searches the position to be inserted of the ordered list in front of the current element for all the elements except the first element, and the inner layer circulation searches the position to be inserted of the ordered list in front of the current element and moves the ordered list.
S203: initializing a minimum heap binary tree, writing the end time of a first basic task of a task sequence into a node key value of the minimum heap binary tree, constructing a task process, and executing the first basic task in the task sequence by using the task process, wherein each branch of the minimum heap binary tree indicates one task process.
Specifically, after a task sequence is determined according to task start time, a minimum heap binary tree is initialized, the end time of a first basic task in the task sequence is written into a node key value of the minimum heap binary tree, meanwhile, a task process is constructed, and the constructed task process is used for executing the first basic task in the task sequence.
It should be noted that, in this embodiment, each branch of the minimum heap binary tree is used to indicate a task process.
The minimum heap binary tree is a sorted complete binary tree, wherein the key value of any non-root node is not larger than the key values of the left child node and the right child node of the whole binary tree, and the key value of the root node is the minimum value of the key values of all nodes of the minimum heap binary tree.
The task process is a process for performing basic task processing, and the process is a process of one-time dynamic execution of a program with a certain independent function on one data set, is an independent unit for performing resource allocation and scheduling by an operating system, and is a carrier (or container) for performing basic tasks.
The task process can be constructed in a system command mode or a self-defined function mode.
It should be understood that, in this embodiment, the task end time is stored by using the node key value of the minimum heap to monitor the current state of the task process, and compared with the backtracking method or the depth-first search based on the pruning function, the advantages of the method are that the dynamic maintainability is good, and the time complexity is low, and the backtracking method isOr depth-first search based on a pruning function, and when the number of basic tasks is n, the time complexity is an exponential order O (2)n) When the number of tasks is large, a large amount of time is consumed, and task scheduling efficiency is low. In the embodiment, the minimum heap mode is adopted, and the maximum consumption time is O (nlogn). In the worst case, all n tasks will conflict with each other. In any case, n insert operations are performed to the heap. In the worst case, we have to do n find and delete min operations on the heap, because find and delete min operations only consume o (logn) time. In the worst case, the heap needs to accommodate all n elements, so the spatial complexity is o (n).
S204: aiming at the ith basic task in the task sequence, when the current time is the starting time of the basic task, if the time point corresponding to the root node key value in the minimum heap binary tree is behind the current time, generating a new branch for the minimum heap binary tree, and writing the ending time corresponding to the ith basic task into the node key value of the new branch, wherein i is a positive integer greater than 1.
Specifically, for each subsequent basic task, when the task is started, it is only necessary to determine whether an idle task process is available, and if an idle task process is available, the idle task process is preferentially used, and when no idle task process is available, a new task process is started, and in step S203, the state of the task process is expressed by the key value in the minimum heap binary tree, so that it is only necessary to determine the key value of the root node in the minimum heap, and it can be determined whether an idle task process exists. Aiming at the ith basic task in the task sequence, when the current time is the starting time of the basic task, namely when the ith basic task needs to be started, the precedence relationship between the time point corresponding to the root node key value in the minimum heap binary tree and the current time is judged, when the time point corresponding to the root node key value in the minimum heap binary tree is behind the current time, it is shown that no idle task process exists in the task process corresponding to the minimum heap binary tree at the current time, at the moment, a new branch is generated for the minimum heap binary tree, and the ending time corresponding to the ith basic task is written into the node key value of the new branch, wherein i is a positive integer greater than 1.
The root node (root) is a component of the tree, also called a tree root, and all non-empty binary trees have one and only one root node introduction, which is an ancestor of all nodes except the root node in the same tree and has no father node.
In this embodiment, the adopted binary tree is a minimum heap binary tree, the end time stored by the root node of the binary tree is the minimum time point in all nodes, and when the time point corresponding to the root node key value in the minimum heap binary tree is after the current time, it can be determined that no idle task process exists at the current time point.
It should be understood that when the time point corresponding to the key value of the root node in the minimum heap binary tree is before the current time, it may be determined that an idle task process exists at the current time point, a new node is added, the end time of the ith task is stored in the node, and the nodes of the binary tree are sorted to implement updating of the minimum heap binary tree.
S205: and constructing a task process corresponding to the new branch, and executing the ith basic task by using the task process corresponding to the new branch.
Specifically, a new branch needs to be generated, which indicates that the basic task corresponding to the node in the existing minimum heap binary tree is not completely executed, that is, there is no idle task process, and therefore, a corresponding task process needs to be constructed for the new branch, and the ith basic task is executed by using the task process corresponding to the new branch.
Obtaining each basic task to be processed, analyzing the basic tasks to obtain the starting time and the ending time of the basic tasks, sequencing the basic tasks according to the sequence of the starting time to obtain a task sequence, initializing a minimum heap binary tree, writing the ending time of a first basic task of the task sequence into a node key value of the minimum heap binary tree, constructing a task process, executing the first basic task in the task sequence by using the task process, generating a new branch for the minimum heap binary tree and writing the ending time corresponding to the ith basic task into the node key value of the new branch if a time point corresponding to a root node key value in the minimum heap binary tree is behind the current time when the current time is the starting time of the basic task aiming at the ith basic task in the task sequence, and finally constructing the task process corresponding to the new branch, and the ith basic task is executed by using the task process corresponding to the new branch, and the task process is monitored by adopting a binary tree mode, so that the time complexity of task scheduling is greatly optimized, and the task scheduling efficiency is improved.
In an embodiment, after the finally updated minimum heap binary tree is obtained, the minimum heap binary tree is stored in the block chain network node, and the block chain storage is used for realizing the sharing of the minimum heap binary tree among different platforms and preventing data from being tampered.
The blockchain is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, a consensus mechanism and an encryption algorithm. A block chain (Blockchain), which is essentially a decentralized database, is a series of data blocks associated by using a cryptographic method, and each data block contains information of a batch of network transactions, so as to verify the validity (anti-counterfeiting) of the information and generate a next block. The blockchain may include a blockchain underlying platform, a platform product services layer, and an application services layer.
In some optional implementation manners of this embodiment, after step S202, the method for scheduling tasks based on multiple processes further includes:
receiving new task data, and acquiring the starting time of the new task data and the ending time of the new task data;
randomly selecting a position from the task sequence as an initial position of new task data;
and adjusting and sequencing by adopting a dichotomy method based on the initial position and the start time of the new task data to obtain an updated task sequence.
Specifically, in the task scheduling process, if a new task is received, new task data is received, the start time of the new task data and the end time of the new task data are obtained, and the new task data is inserted into a task sequence by a Binary insert ordering method (also called Binary insert ordering method), so as to obtain an updated task sequence.
The method for implementing the binary search comprises the steps of firstly taking the middle element of a sequenced sequence and comparing the middle element with data to be inserted, wherein if the value of the middle element is larger than the data to be inserted, the data to be inserted belongs to the first half of an array, and otherwise, the data to be inserted belongs to the second half of the array. And by analogy, continuously reducing the range and determining the position to be inserted.
In the embodiment, new task data is received and scheduled at any time by a binary insertion sorting method, so that the robustness of task scheduling is improved.
In some optional implementation manners of this embodiment, in step S203, constructing a task process, and executing a first basic task in the task sequence using the task process includes:
according to the number of preset threads, a fixed-length thread pool is established in a task process;
and executing the basic task in the task process through the fixed-length thread pool.
Specifically, the embodiment of the present invention creates a thread pool with a preset thread number by using a multithreading manner provided by the thread pool, and processes a basic task in a task process.
The preset thread data may be set according to the requirement of the actual task, for example, the number of threads is set to 6.
The Thread Pool includes, but is not limited to, a cacheable Thread Pool (Cached Thread Pool), a Fixed-length Thread Pool (Fixed Thread Pool), a Single-threaded Thread Pool (Single Thread execution), a Scheduled Thread Pool (Scheduled Thread Pool), and the like.
Preferably, the thread pool adopted in the embodiment of the present invention is a fixed-length thread pool, and the multithread operation is performed by controlling the maximum concurrency number of threads, and an excess thread waits in the queue.
For example, in one embodiment, a fixed-length thread pool is created by using execute.newfixedthreadpool (6), which can control the maximum thread number to be 6, and the excess thread will wait in the queue. When the basic task is executed, the thread pool can simultaneously adopt 6 threads to execute processing instructions on the basic task, and the mode of using multiple threads saves the calculation time and improves the efficiency of task processing.
It should be noted that, the constructing of the task process and the executing of the basic task in the task sequence by using the task process provided in this embodiment are not only applicable to the first basic task of the task sequence, but also applicable to other tasks of the task sequence.
In the embodiment, the processing of the basic task in the task process is realized by creating the thread pool and using a multi-thread mode, which is beneficial to improving the efficiency of task processing.
In some optional implementation manners of this embodiment, after step S203, the method for scheduling a task based on multiple processes further includes:
regularly acquiring time points corresponding to the root node key assignments, and comparing the time points corresponding to the root node key assignments with the acquired time points to obtain a comparison result;
if the comparison result is that the time point corresponding to the key value of the root node is before the acquisition time point, performing node sinking on the root node to serve as an updated child node, and constructing a new root node;
and destroying the task process corresponding to the updated child node.
Specifically, a time point corresponding to the root node key value is read from the minimum heap binary tree at regular time through a timing script, and then the time point corresponding to the root node key value is compared with the acquisition time point to obtain a comparison result, when the comparison result is that the time point corresponding to the root node key value is before the acquisition time point, it is indicated that the end time corresponding to the root node key value has passed when the root node key value is acquired, that is, when the time point is acquired, the basic task corresponding to the end time stored in the root node key value is executed, a task process for processing the basic task is idle, at this time, the minimum heap binary tree is updated, and the task corresponding to the completed basic task is destroyed to save system resources.
The obtaining time point refers to a time node obtaining a time point corresponding to the key value of the root node.
The node sinking of the root node refers to sinking the following node into child nodes of other nodes, and in this embodiment, specifically refers to sinking the root node into child nodes of the updated root node, so as to update the minimum heap binary tree. For the specific process, reference may be made to the description of the subsequent embodiments, and in order to avoid repetition, the detailed description is omitted here.
Wherein, the task destroying process can be realized by using system instructions or functions.
In this embodiment, the minimum heap binary tree is updated in time by regularly checking and judging the key values of the root nodes, and meanwhile, the idle tasks completing the tasks are destroyed in time, so that system resources are saved.
In some optional implementation manners of this embodiment, if the comparison result is that the time point corresponding to the root node key value is before the obtaining time point, performing node sinking on the root node as an updated child node, and constructing a new root node includes:
selecting any child node from child nodes of the root node as a target child node;
inserting new nodes into the root node and the target child node to serve as intermediate nodes, wherein the initial value of the key value of the intermediate nodes is null;
and exchanging the key assignments of the root node and the intermediate node, updating the node index, taking the sunk root node as an updated child node, and taking the updated intermediate node as a new root node.
Specifically, the root node in this embodiment has one or more child nodes, and when the comparison result is that the time point corresponding to the key value of the root node is before the acquisition time point, that is, the basic task corresponding to the end time stored in the root node is executed completely, at this time, the root node is sunk as a child node in a node sinking (element sinking) manner, and a new node is constructed as a new root node.
In this embodiment, when it is detected that the time point corresponding to the root node key value is before the acquisition time point, the minimum heap binary tree is updated in time, which is beneficial to improving the verification speed when the subsequent basic task starts, and meanwhile, according to the comparison and judgment, the idle task process is discovered in time and recovered in time, which is beneficial to saving system resources.
It should be understood that, the sequence numbers of the steps in the foregoing embodiments do not imply an execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present invention.
Fig. 3 is a schematic block diagram of a multi-process based task scheduling apparatus in one-to-one correspondence with the multi-process based task scheduling method according to the above-described embodiment. As shown in fig. 3, the multi-process based task scheduling apparatus includes an information parsing module 31, a task ordering module 32, a process building module 33, a branch generating module 34, and a multi-process building module 35. The functional modules are explained in detail as follows:
the information analysis module 31 is configured to obtain each basic task to be processed, and analyze the basic task to obtain a start time and an end time of the basic task;
the task sequencing module 32 is configured to sequence the basic tasks based on the sequence of the start times to obtain a task sequence;
the process building module 33 is configured to initialize the minimum heap binary tree, write the end time of the first basic task of the task sequence into the node key value of the minimum heap binary tree, build a task process, and execute the first basic task in the task sequence using the task process, where each branch of the minimum heap binary tree indicates one task process;
a branch generating module 34, configured to generate, for an ith basic task in the task sequence, a new branch for the minimum heap binary tree if a time point corresponding to a root node key value in the minimum heap binary tree is after the current time when the current time is the start time of the basic task, and write an end time corresponding to the ith basic task into a node key value of the new branch, where i is a positive integer greater than 1;
and the multi-process building module 35 is configured to build a task process corresponding to the new branch, and execute the ith basic task by using the task process corresponding to the new branch.
Optionally, the multi-process based task scheduling apparatus further includes:
the new task receiving module is used for receiving new task data and acquiring the starting time of the new task data and the ending time of the new task data;
the position selection module is used for randomly selecting a position from the task sequence as the initial position of new task data;
and the sequence updating module is used for adjusting and sequencing by adopting a dichotomy based on the initial position and the start time of the new task data to obtain an updated task sequence.
Optionally, the process building module 33 includes:
the thread pool creating unit is used for creating a fixed-length thread pool in the task process according to the preset thread quantity;
and the multithreading execution unit is used for executing the basic task in the task process through the fixed-length thread pool.
Optionally, the multi-process based task scheduling apparatus further includes:
the timing check module is used for regularly acquiring time points corresponding to the root node key assignments and comparing the time points corresponding to the root node key assignments with the acquired time points to obtain a comparison result;
the node updating module is used for sinking the root node as an updated child node and constructing a new root node if the comparison result shows that the time point corresponding to the key value of the root node is before the acquisition time point;
and the process destroying module is used for destroying the task process corresponding to the updated child node.
Optionally, the node update module includes:
the target node selection unit is used for selecting any child node from child nodes of the root node as a target child node;
the node inserting unit is used for inserting a new node into the root node and the target child node to serve as an intermediate node, wherein the initial value of the key value of the intermediate node is null;
and the node updating unit is used for exchanging the key assignments of the root node and the intermediate node, updating the node index, taking the sunk root node as an updated child node and taking the updated intermediate node as a new root node.
Optionally, the multi-process based task scheduling apparatus further includes: the resulting minimum heap binary tree is stored in the blockchain network nodes.
For specific limitations of the multiprocess-based task scheduling apparatus, reference may be made to the above limitations of the multiprocess-based task scheduling method, which are not described herein again. The modules in the multi-process based task scheduling device can be wholly or partially implemented by software, hardware and a combination thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
In order to solve the technical problem, an embodiment of the present application further provides a computer device. Referring to fig. 4, fig. 4 is a block diagram of a basic structure of a computer device according to the present embodiment.
The computer device 4 comprises a memory 41, a processor 42, a network interface 43 communicatively connected to each other via a system bus. It is noted that only the computer device 4 having the components connection memory 41, processor 42, network interface 43 is shown, but it is understood that not all of the shown components are required to be implemented, and that more or fewer components may be implemented instead. As will be understood by those skilled in the art, the computer device is a device capable of automatically performing numerical calculation and/or information processing according to a preset or stored instruction, and the hardware includes, but is not limited to, a microprocessor, an Application Specific Integrated Circuit (ASIC), a Programmable Gate Array (FPGA), a Digital Signal Processor (DSP), an embedded device, and the like.
The computer device can be a desktop computer, a notebook, a palm computer, a cloud server and other computing devices. The computer equipment can carry out man-machine interaction with a user through a keyboard, a mouse, a remote controller, a touch panel or voice control equipment and the like.
The memory 41 includes at least one type of readable storage medium including a flash memory, a hard disk, a multimedia card, a card-type memory (e.g., SD or D interface display memory, etc.), a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a Read Only Memory (ROM), an Electrically Erasable Programmable Read Only Memory (EEPROM), a Programmable Read Only Memory (PROM), a magnetic memory, a magnetic disk, an optical disk, etc. In some embodiments, the memory 41 may be an internal storage unit of the computer device 4, such as a hard disk or a memory of the computer device 4. In other embodiments, the memory 41 may also be an external storage device of the computer device 4, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, which are provided on the computer device 4. Of course, the memory 41 may also include both internal and external storage devices of the computer device 4. In this embodiment, the memory 41 is generally used for storing an operating system installed in the computer device 4 and various types of application software, such as program codes for controlling electronic files. Further, the memory 41 may also be used to temporarily store various types of data that have been output or are to be output.
The processor 42 may be a Central Processing Unit (CPU), controller, microcontroller, microprocessor, or other data Processing chip in some embodiments. The processor 42 is typically used to control the overall operation of the computer device 4. In this embodiment, the processor 42 is configured to execute the program code stored in the memory 41 or process data, such as program code for executing control of an electronic file.
The network interface 43 may comprise a wireless network interface or a wired network interface, and the network interface 43 is generally used for establishing communication connection between the computer device 4 and other electronic devices.
The present application further provides another embodiment, which is to provide a computer readable storage medium storing an interface display program, which is executable by at least one processor to cause the at least one processor to execute the steps of the multi-process based task scheduling method as described above.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solutions of the present application may be embodied in the form of a software product, which is stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal device (such as a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present application.
It is to be understood that the above-described embodiments are merely illustrative of some, but not restrictive, of the broad invention, and that the appended drawings illustrate preferred embodiments of the invention and do not limit the scope of the invention. This application is capable of embodiments in many different forms and is provided for the purpose of enabling a thorough understanding of the disclosure of the application. Although the present application has been described in detail with reference to the foregoing embodiments, it will be apparent to one skilled in the art that the present application may be practiced without modification or with equivalents of some of the features described in the foregoing embodiments. All equivalent structures made by using the contents of the specification and the drawings of the present application are directly or indirectly applied to other related technical fields and are within the protection scope of the present application.

Claims (10)

1. A task scheduling method based on multiprocess is characterized in that the task scheduling method based on multiprocess comprises the following steps:
acquiring each basic task to be processed, and analyzing the basic task to obtain the starting time and the ending time of the basic task;
sequencing the basic tasks based on the sequence of the starting time to obtain a task sequence;
initializing a minimum heap binary tree, writing the end time of a first basic task of the task sequence into a node key value of the minimum heap binary tree, constructing a task process, and executing the first basic task in the task sequence by using the task process, wherein each branch of the minimum heap binary tree indicates one task process;
for the ith basic task in the task sequence, when the current time is the starting time of the basic task, if the time point corresponding to the root node key value in the minimum heap binary tree is behind the current time, generating a new branch for the minimum heap binary tree, and writing the end time corresponding to the ith basic task into the node key value of the new branch, wherein i is a positive integer greater than 1;
and constructing a task process corresponding to the new branch, and executing the ith basic task by using the task process corresponding to the new branch.
2. The multiprocess-based task scheduling method according to claim 1, wherein after said sequencing the base tasks based on the precedence order of the start times to obtain a task sequence, the multiprocess-based task scheduling method further comprises:
receiving new task data, and acquiring the starting time of the new task data and the ending time of the new task data;
randomly selecting a position from the task sequence as an initial position of the new task data;
and adjusting and sequencing by adopting a dichotomy method based on the initial position and the start time of the new task data to obtain an updated task sequence.
3. The multi-process based task scheduling method of claim 1, wherein the building of the task process, after executing the first base task in the task sequence using the task process, the multi-process based task scheduling method further comprises:
establishing a fixed-length thread pool in the task process according to a preset thread number;
and executing a first basic task in the task process through the fixed-length thread pool.
4. The multiprocessing-based task scheduling method according to any one of claims 1 to 3, wherein after the initializing the minimum heap binary tree, writing an end time of a first base task of the task sequence into a node key value of the minimum heap binary tree, and constructing a task process, and executing the first base task of the task sequence using the task process, the multiprocessing-based task scheduling method further comprises:
regularly acquiring a time point corresponding to a root node key value, and comparing the time point corresponding to the root node key value with the acquired time point to obtain a comparison result;
if the comparison result is that the time point corresponding to the root node key assignment is before the acquisition time point, node sinking is carried out on the root node to serve as an updated child node, and a new root node is constructed;
and destroying the task process corresponding to the updated child node.
5. The multiprocess-based task scheduling method of claim 4, wherein if the comparison result is that the time point corresponding to the root node key value is before the obtaining time point, performing node sinking on the root node as an updated child node, and constructing a new root node comprises:
selecting any child node from the child nodes of the root node as a target child node;
inserting a new node into the root node and the target child node to serve as an intermediate node, wherein the initial value of the key value of the intermediate node is null;
and exchanging the key assignments of the root node and the intermediate node, updating the node index, taking the sunk root node as an updated child node, and taking the updated intermediate node as the new root node.
6. The multiprocessing based task scheduling method according to claim 1, wherein after constructing the task process corresponding to the new branch and executing an i-th base task using the task process corresponding to the new branch, the multiprocessing based task scheduling method further comprises: the resulting minimum heap binary tree is stored in the blockchain network nodes.
7. A multiprocess-based task scheduling apparatus, wherein the multiprocess-based task scheduling apparatus comprises:
the information analysis module is used for acquiring each basic task to be processed, analyzing the basic task and obtaining the starting time and the ending time of the basic task;
the task sequencing module is used for sequencing the basic tasks based on the sequence of the starting time to obtain a task sequence;
a process construction module, configured to initialize a minimum heap binary tree, write an end time of a first basic task of the task sequence into a node key value of the minimum heap binary tree, construct a task process, and execute the first basic task in the task sequence using the task process, where each branch of the minimum heap binary tree indicates one task process;
a branch generating module, configured to generate, for an ith basic task in a task sequence, a new branch for the minimum heap binary tree if a time point corresponding to a root node key value in the minimum heap binary tree is after a current time when the current time is a start time of the basic task, and write an end time corresponding to the ith basic task into a node key value of the new branch, where i is a positive integer greater than 1;
and the multi-process construction module is used for constructing the task process corresponding to the new branch and executing the ith basic task by using the task process corresponding to the new branch.
8. The multiprocess-based task scheduler of claim 7, wherein said multiprocess-based task scheduler further comprises:
the new task receiving module is used for receiving new task data and acquiring the starting time of the new task data and the ending time of the new task data;
the position selection module is used for randomly selecting a position from the task sequence as the initial position of the new task data;
and the sequence updating module is used for adjusting and sequencing by adopting a dichotomy based on the initial position and the start time of the new task data to obtain an updated task sequence.
9. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that the processor implements the multiprocess-based task scheduling method according to any of the claims 1 to 6 when executing the computer program.
10. A computer-readable storage medium, in which a computer program is stored which, when being executed by a processor, implements a method for multi-process based task scheduling according to any one of claims 1 to 6.
CN202010610172.6A 2020-06-29 2020-06-29 Multi-process-based task scheduling method, device, computer equipment and medium Active CN111813515B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010610172.6A CN111813515B (en) 2020-06-29 2020-06-29 Multi-process-based task scheduling method, device, computer equipment and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010610172.6A CN111813515B (en) 2020-06-29 2020-06-29 Multi-process-based task scheduling method, device, computer equipment and medium

Publications (2)

Publication Number Publication Date
CN111813515A true CN111813515A (en) 2020-10-23
CN111813515B CN111813515B (en) 2024-08-23

Family

ID=72856275

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010610172.6A Active CN111813515B (en) 2020-06-29 2020-06-29 Multi-process-based task scheduling method, device, computer equipment and medium

Country Status (1)

Country Link
CN (1) CN111813515B (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112560789A (en) * 2020-12-28 2021-03-26 平安银行股份有限公司 Image object detection method and device, electronic equipment and storage medium
CN112633710A (en) * 2020-12-26 2021-04-09 中国农业银行股份有限公司 Job task scheduling method, device, equipment and storage medium
CN112685181A (en) * 2020-12-29 2021-04-20 成都科来网络技术有限公司 Push task scheduling method and system for balancing CPU resources
CN113965391A (en) * 2021-10-27 2022-01-21 成都数默科技有限公司 Method for bubble sorting of multiple data packet files

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102541051A (en) * 2012-01-11 2012-07-04 山西万立科技有限公司 Explosion-proof embedded type front-end controller for special monitoring network for coal output
CN107689010A (en) * 2017-07-25 2018-02-13 平安科技(深圳)有限公司 Method, apparatus, computer equipment and the storage medium of batch processing declaration form task
CN110412869A (en) * 2019-06-21 2019-11-05 中南大学 A kind of Spatial distributions object real-time tracking method that more stellar associations are same

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102541051A (en) * 2012-01-11 2012-07-04 山西万立科技有限公司 Explosion-proof embedded type front-end controller for special monitoring network for coal output
CN107689010A (en) * 2017-07-25 2018-02-13 平安科技(深圳)有限公司 Method, apparatus, computer equipment and the storage medium of batch processing declaration form task
WO2019019381A1 (en) * 2017-07-25 2019-01-31 平安科技(深圳)有限公司 Batch processing method and apparatus for insurance slip tasks, computer device and storage medium
CN110412869A (en) * 2019-06-21 2019-11-05 中南大学 A kind of Spatial distributions object real-time tracking method that more stellar associations are same

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
徐秀: "多层子树堆排序任务匹配调度算法", 《通信学报》, vol. 31, no. 8, 31 August 2010 (2010-08-31), pages 81 - 86 *

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112633710A (en) * 2020-12-26 2021-04-09 中国农业银行股份有限公司 Job task scheduling method, device, equipment and storage medium
CN112633710B (en) * 2020-12-26 2023-10-13 中国农业银行股份有限公司 Job task scheduling method, device, equipment and storage medium
CN112560789A (en) * 2020-12-28 2021-03-26 平安银行股份有限公司 Image object detection method and device, electronic equipment and storage medium
CN112560789B (en) * 2020-12-28 2024-06-04 平安银行股份有限公司 Image object detection method, device, electronic equipment and storage medium
CN112685181A (en) * 2020-12-29 2021-04-20 成都科来网络技术有限公司 Push task scheduling method and system for balancing CPU resources
CN112685181B (en) * 2020-12-29 2024-06-04 科来网络技术股份有限公司 Push task scheduling method and system for balancing CPU resources
CN113965391A (en) * 2021-10-27 2022-01-21 成都数默科技有限公司 Method for bubble sorting of multiple data packet files
CN113965391B (en) * 2021-10-27 2023-10-20 成都数默科技有限公司 Method for bubble sorting of multi-data packet files

Also Published As

Publication number Publication date
CN111813515B (en) 2024-08-23

Similar Documents

Publication Publication Date Title
CN111813515B (en) Multi-process-based task scheduling method, device, computer equipment and medium
CN108848039B (en) Server, message distribution method and storage medium
CN102695999B (en) Domain specific language, compiler and JIT for dynamic power management
CN111813517B (en) Task queue allocation method and device, computer equipment and medium
CN109840142A (en) Thread control method, device, electronic equipment and storage medium based on cloud monitoring
CN113254445B (en) Real-time data storage method, device, computer equipment and storage medium
US7243354B1 (en) System and method for efficiently processing information in a multithread environment
CN111782304A (en) Logic control method and device for paging loading data, computer equipment and medium
CN112199442A (en) Distributed batch file downloading method and device, computer equipment and storage medium
CN115455058A (en) Cache data processing method and device, computer equipment and storage medium
US8589942B2 (en) Non-real time thread scheduling
CN114281552A (en) Task scheduling method, device, equipment and medium based on directed acyclic graph
CN113254106A (en) Task execution method and device based on Flink, computer equipment and storage medium
CN110908644B (en) Configuration method and device of state node, computer equipment and storage medium
CN112363814A (en) Task scheduling method and device, computer equipment and storage medium
CN115061916B (en) Method for automatically generating interface test case and related equipment thereof
CN115562662A (en) Application page creating method and device, computer equipment and storage medium
CN114968719A (en) Thread running state classification method and device, computer equipment and storage medium
CN115328764A (en) Test code optimization method based on automatic test and related equipment thereof
CN114756362A (en) Resource quota management method and system, intelligent terminal and storage medium
CN114626352A (en) Report automatic generation method and device, computer equipment and storage medium
CN103870313A (en) Virtual machine task scheduling method and system
CN112328381A (en) Decision-making method and device for starting task execution sequence, computer equipment and medium
CN112579280A (en) Scheduling method and device of cloud resources and computer storage medium
CN110795117A (en) Method, system, electronic device and storage medium for updating configuration file

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant