CN114003316A - Cluster timing task execution method and device, electronic equipment and storage medium - Google Patents

Cluster timing task execution method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN114003316A
CN114003316A CN202111271009.2A CN202111271009A CN114003316A CN 114003316 A CN114003316 A CN 114003316A CN 202111271009 A CN202111271009 A CN 202111271009A CN 114003316 A CN114003316 A CN 114003316A
Authority
CN
China
Prior art keywords
task
target
cluster
execution
timing
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.)
Pending
Application number
CN202111271009.2A
Other languages
Chinese (zh)
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 Yizhangtong Cloud Technology Shenzhen Co ltd
Original Assignee
Ping An Yizhangtong Cloud Technology Shenzhen Co 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 Yizhangtong Cloud Technology Shenzhen Co ltd filed Critical Ping An Yizhangtong Cloud Technology Shenzhen Co ltd
Priority to CN202111271009.2A priority Critical patent/CN114003316A/en
Publication of CN114003316A publication Critical patent/CN114003316A/en
Pending legal-status Critical Current

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/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4488Object-oriented
    • G06F9/449Object-oriented method invocation or resolution
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2282Tablespace storage structures; Management thereof
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/25Integrating or interfacing systems involving database management systems
    • G06F16/252Integrating or interfacing systems involving database management systems between a Database Management System and a front-end application
    • 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
    • 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/5061Partitioning or combining of resources

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention relates to an artificial intelligence technology, and provides a cluster timing task execution method, which comprises the steps of judging whether a local server has an execution condition for executing a timing task corresponding to preset time or not by acquiring parameters of the local server, and taking the timing task as a target timing task if the local server has the execution condition; then, whether a data name and a task variable corresponding to the target execution task exist or not is searched in a database table, and if the data name and the task variable exist, the target timing task is executed according to the state pertinence of the task variable; if the data name and the task variable do not exist, the target data name and the target task variable related to the target timing task are created, the target timing task is executed, and the state of the target task variable is changed into the executed state.

Description

Cluster timing task execution method and device, electronic equipment and storage medium
Technical Field
The invention relates to the field of server clusters, relates to an artificial intelligence technology, and particularly relates to a cluster timing task execution method and device, electronic equipment and a computer readable storage medium.
Background
With the rapid development of economy and computer technology, a server cluster is widely used, wherein the server cluster refers to the way that a plurality of servers are concentrated together to perform the same service, a client looks like only one server, the server cluster can utilize a plurality of computers to perform parallel computing so as to obtain high computing speed, and the plurality of computers can also be used for backup, so that any one machine can damage the whole system or can normally operate.
In the operation process of the server cluster, egg is an enterprise-level node.js framework, is concentrated on providing a core function of web development, and can be conveniently expanded based on a self service scene. Js itself provides a mechanism for ensuring that only one process under a single server executes a timing task, but in some cases, the service is not deployed on a single server, and thus, a requirement for ensuring that only one process under the whole cluster executes the timing task is generated.
Js is usually realized by introducing a third-party tool, such as Redis, but the system architecture is further complicated by the additional addition of new tools, and the additional system risk and operation and maintenance cost are increased.
Therefore, a method for executing a server cluster timing task, which can simplify the cluster system architecture, simplify the system maintenance, and maximize the resource utilization efficiency, is needed.
Disclosure of Invention
The invention provides a cluster timing task execution method, which aims to solve the problems that the system architecture becomes more complex and extra system risk and operation and maintenance cost are increased due to the fact that a new tool is additionally added to improve the computing speed.
In order to achieve the above object, a method for executing a cluster timing task provided by the present invention includes:
deploying a cluster instance on each server in a server cluster and deploying a timed task under the cluster instance;
storing a data name corresponding to the created timing task in a newly-built database table, and defining a task variable corresponding to the data name in the database table;
when the preset time for executing the timing task is reached, judging whether the local server has an execution condition for executing the timing task corresponding to the preset time or not by acquiring parameters of the local server, and if the execution condition is met, setting the timing task as a target timing task;
searching whether a data name and a task variable corresponding to the target execution task exist in the database table, and if the data name and the task variable exist, executing the target timing task according to the state of the task variable; and if the data name and the task variable do not exist, creating a target data name and a target task variable related to the target timing task, executing the target timing task, and changing the state of the target task variable into the executed state.
Optionally, the deploying a cluster instance on each server in a server cluster and deploying a timing task under the cluster instance includes:
building a server cluster;
deploying a cluster case on the server cluster;
connecting the cluster case with a preset database;
all preset timing tasks are deployed in each cluster case, and all data about the timing tasks in the cluster cases are transmitted to the database.
Optionally, storing a data name corresponding to the created timed task in a newly created database table, and defining a task variable corresponding to the data name, including:
defining task variables corresponding to the timing tasks in the database table, and data name columns, task variable columns, task execution ip columns and remark columns corresponding to the task variables, wherein the task variables are used for reflecting the states of the timing tasks;
populating the database table according to the timed task, including: and storing a data name corresponding to the created timing task in the data name column, filling the task variable in the task variable column, storing a server IP for executing the timing task in the task execution IP column, and storing the completion status of the timing task execution in the remark column.
Optionally, when the preset time for executing the timing task is reached, determining, by obtaining a parameter of the local server, whether the local server has an execution condition for executing the timing task corresponding to the preset time, includes:
the method comprises the steps that the preset time for executing a timing task is monitored in real time, and when the preset time is reached, the timing task triggers an information capturing program;
acquiring specification information of a local server through the information capture program; the specification information comprises a local IP address of the local server, a local CPU utilization rate and a local memory utilization rate;
searching whether an executing task related to the local IP address exists in the database table according to the local IP address;
if the task which is about to be executed by the local IP address does not exist, judging whether the utilization rate of the local CPU and the utilization rate of the local memory are not lower than a preset condition threshold value or not; wherein, in this embodiment, the condition threshold is eighty percent;
and if the execution condition is not lower than the condition threshold, the execution condition is met.
Optionally, if the execution condition is met, locking the timing task;
the locked timed task is taken as a target timed task, and the local server can not execute any more tasks except the target timed task during the locking.
Optionally, if the data name and the task variable exist, executing the target timing task according to the state of the task variable in a targeted manner, where the executing includes:
if the data name and the task variable corresponding to the target timing task exist, acquiring the real-time state of the state variable and a task execution ip column corresponding to the target timing task from the database table;
if the real-time state is a waiting state and the task execution IP column is empty, executing the target timing task, changing the real-time state into a positive execution state, and filling the IP of the local server into the task execution IP column; wherein,
if the real-time state is an error state and other IPs except the local server are filled in the task execution IP column, executing the target timing task, changing the real-time state into a positive execution state, filling the IP of the local server in the task execution IP column and covering the other IPs;
if the real-time state is an executing state or an executed state, the local server is caused to terminate executing the target timing task;
and if the data name and the task variable do not exist, creating a target data name and a target task variable related to the target timing task, executing the target timing task, and changing the state of the target task variable into the executed state.
Optionally, the executing the target timing task includes:
analyzing the target timing task to obtain task logic;
and executing the task through a preset execution statement according to the task logic to obtain a task result, and remarking the task in a remark column in the database table to complete the identification symbol.
In order to solve the above problem, the present invention further provides a device for executing a cluster timed task, where the device includes:
the system comprises a cluster deployment unit, a task scheduling unit and a task scheduling unit, wherein the cluster deployment unit is used for deploying a cluster example on each server in a server cluster and deploying a timing task under the cluster example;
the task definition unit is used for newly building a database table, storing a data name corresponding to the created timing task in the database table, and defining a task variable corresponding to the data name in the database table;
the target locking unit is used for judging whether the local server has an execution condition for executing the timing task corresponding to the preset time or not by acquiring the parameters of the local server when the preset time for executing the timing task is reached, and setting the timing task as the target timing task if the execution condition is met;
the task execution unit is used for searching whether a data name and a task variable corresponding to the target execution task exist in the database table, and if the data name and the task variable exist, the target timing task is executed according to the state of the task variable; and if the data name and the task variable do not exist, creating a target data name and a target task variable related to the target timing task, executing the target timing task, and changing the state of the target task variable into the executed state.
In order to solve the above problem, the present invention also provides an electronic device, including:
a memory storing at least one instruction; and
and the processor executes the instructions stored in the memory to realize the steps in the cluster timing task execution method.
In order to solve the above problem, the present invention further provides a computer-readable storage medium, which stores at least one instruction, where the at least one instruction is executed by a processor in an electronic device to implement the above cluster timing task execution method.
The embodiment of the invention firstly deploys a cluster example on each server in a server cluster, deploys a timing task under the cluster example, then creates a database table, stores a data name corresponding to the created timing task in the database table, and defines a task variable corresponding to the data name; when the preset time is reached, judging whether the local server has an execution condition for executing a timing task corresponding to the preset time or not by acquiring the parameters of the local server, and if the execution condition is met, taking the timing task as a target timing task; then, whether a data name and a task variable corresponding to the target execution task exist or not is searched in a database table, and if the data name and the task variable exist, the target timing task is executed according to the state pertinence of the task variable; if the data name and the task variable do not exist, the target data name and the target task variable related to the target timing task are created, the target timing task is executed, and the state of the target task variable is changed into the executed state.
Drawings
Fig. 1 is a schematic flowchart of a method for executing a cluster timing task according to an embodiment of the present invention;
fig. 2 is a schematic block diagram of a cluster timed task execution device according to an embodiment of the present invention;
fig. 3 is a schematic internal structural diagram of an electronic device according to a cluster timing task execution method provided in an embodiment of the present invention;
the implementation, functional features and advantages of the objects of the present invention will be further explained with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
In the operation process of the server cluster, egg is an enterprise-level node.js framework, is concentrated on providing a core function of web development, and can be conveniently expanded based on a self service scene. Js itself provides a mechanism for ensuring that only one process under a single server executes a timing task, but in some cases, the service is not deployed on a single server, and thus, a requirement for ensuring that only one process under the whole cluster executes the timing task is generated.
Js is usually realized by introducing a third-party tool, such as Redis, but the system architecture is further complicated by the additional addition of new tools, and the additional system risk and operation and maintenance cost are increased.
In order to solve the above problem, an embodiment of the present invention provides a method for executing a cluster timing task.
In this embodiment, the execution subject is a cluster timing task execution system of the whole server cluster, and the cluster timing task execution system is integrated in the server cluster, that is, different modules of the cluster timing task execution system under the server cluster respectively perform different operation steps, where an architecture of the server cluster includes a plurality of servers, a plurality of cluster instances run under each server, and a plurality of timing tasks are stored under each cluster instance, so that the sequential execution of the timing tasks is realized through the following steps.
It should be noted that, the embodiment of the present application may acquire and process related data based on an artificial intelligence technique. Among them, Artificial Intelligence (AI) is a theory, method, technique and application system that simulates, extends and expands human Intelligence using a digital computer or a machine controlled by a digital computer, senses the environment, acquires knowledge and uses the knowledge to obtain the best result.
As shown in fig. 1, in this embodiment, a method for executing a cluster timing task includes:
s1: deploying a cluster instance on each server in a server cluster and deploying a timed task under the cluster instance;
s2: storing a data name corresponding to the established timing task in a newly-established database table, and defining a task variable corresponding to the data name in the database table;
s3: when the preset time for executing the timing task is reached, judging whether the local server has an execution condition for executing the timing task corresponding to the preset time or not by acquiring parameters of the local server, and if the execution condition is met, setting the timing task as a target timing task;
s4: searching whether a data name and a task variable corresponding to the target execution task exist in a database table, and if the data name and the task variable exist, executing the target timing task according to the state of the task variable; and if the data name and the task variable do not exist, creating a target data name and a target task variable related to the target timing task, executing the target timing task, and changing the state of the target task variable into the executed state.
In the embodiment shown in fig. 1, step S1 is a process of deploying a cluster instance on each server in the server cluster and deploying a timed task under the cluster instance; a process for deploying a cluster instance on each server in a cluster of servers and a timed task under the cluster instance, comprising:
s11: building a server cluster;
s12: deploying a cluster case on a server cluster;
s13: connecting the cluster case with a preset database;
s14: all preset timing tasks are deployed in each cluster case, and all data about the timing tasks in the cluster cases are transmitted to the database.
Specifically, in the process of building the server cluster in step S11, the method includes:
firstly, creating a cluster installation tool in a server node, determining all members and a member list in the server cluster through the cluster installation tool, and then adding a shared data storage device for all the members in the member list, so that the cluster is provided with the node, a local data storage device of the node and a shared data storage device, wherein the shared data storage device is used for storing shared resources of all the nodes in the shared cluster; in this embodiment, the storage device may be a disk, may also be a simple database, and may even be a connection medium resource;
step S12 is a process of deploying cluster instances on the server cluster, which is a process of performing cluster planning, network configuration, security configuration, time synchronization, and the like on each node, where the process may be any complete server cluster instance, each instance runs a set of complete codes, and each set of codes includes all timing tasks;
step S13 and step S14 are processes of connecting the cluster cases with a preset database, deploying all preset timing tasks in each cluster case, and transmitting all data related to the timing tasks in the cluster cases to the database, wherein the connection is not a connection in an actual sense, but a relationship between the cluster cases and the database is established, so that data generated after each timing task in a data case is completed is stored in the database; in other words, physically, in step S1, the nodes of the cluster are connected to the common data storage device, and the connection relationship between the cluster case and the database is established correspondingly in terms of software, so that the data generated by each cluster instance in each node for executing the timing task is stored in the database, and in this embodiment, an exclusive lock mechanism is provided between the instances, that is, a write operation lock mechanism of the mongodb database is relied on to ensure that only one instance will execute the business operation.
In the embodiment shown in fig. 1, step S2 is a process of storing a data name corresponding to the created timed task in a newly created database table, and defining a task variable corresponding to the data name; the process of creating a database table, storing a data name corresponding to the created timing task in the database table, and defining a task variable corresponding to the data name includes:
s21: creating a database table and defining task variables corresponding to the timing tasks;
s22: defining task variables corresponding to a timing task in a database table, and a data name column, a task variable column, a task execution ip column and a remark column corresponding to the task variables, wherein the task variables are used for reflecting the state of the timing task;
s23: populating the database table according to the timed task, including: a data name column stores data names corresponding to the created timed tasks, a task variable column is filled with task variables, a task execution IP column stores server IPs for executing the timed tasks, and a remark column stores the completion status of the timed task execution.
Specifically, in this embodiment, for example, a server cluster calls an egg-mongoose class library to operate a mongoodb database, where the database table is schedule in this embodiment, a data name of the database is name _ n, if a task execution ip is a local server, the task execution ip is locaipip, and a task variable is defined as status; the data name (name _ n) may be the name of the timing task itself, or may be a self-defined name, which is not limited herein;
step S21 is a process of creating schedule, in this embodiment, a piece of data with name as a corresponding name is stored in the schedule for each timing task, the timing task has multiple operating states, which may be waiting, doing, etc., so that a mechanism of a database write operation lock is utilized to ensure that only a timing task under one cluster instance can modify the operating state of the corresponding timing task in the database;
step S22 is a process of defining a data name column, a task variable column, a task execution ip column, and a remark column in a database table, that is, the data list is divided into columns to describe each timing task, wherein the described contents are respectively stored in the data name column, the task variable column, the task execution ip column, and the remark column according to the classification;
step S23 is to store the data name corresponding to the created timed task in the data name column, i.e. the name of the timed task in this embodiment, store the task volume including "waiting", "processing", and "processed + processing time" in the task volume column, store the server IP executing the timed task in the task execution IP column, such as the IP of the local server or the IP of other servers in the server cluster except the local server, store the completion status of the timed task execution in the remark column, and if the timed task has been completed by other servers, note the execution success (uetr) or execution error (error) in the remark column.
In the embodiment shown in fig. 1, step S3 is a process of determining whether the local server has an execution condition for executing the timed task corresponding to the preset time by obtaining the parameter of the local server when the preset time is reached, and if the execution condition is met, taking the timed task as the target timed task; when the preset time for executing the timing task is reached, a process for judging whether the local server has an execution condition for executing the timing task corresponding to the preset time or not by acquiring parameters of the local server comprises the following steps:
s31: the method comprises the steps that the preset time for executing a timing task is monitored in real time, and when the preset time is reached, the timing task triggers an information capturing program;
s32: acquiring specification information of a local server through the information capture program; the specification information comprises a local IP address of the local server, a local CPU utilization rate and a local memory utilization rate;
s33: searching whether an executing task related to the local IP address exists in the database table according to the local IP address;
s34: if the task which is about to be executed by the local IP address does not exist, judging whether the utilization rate of the local CPU and the utilization rate of the local memory are not lower than a preset condition threshold value or not; wherein, in this embodiment, the condition threshold is eighty percent;
s35: and if the execution condition is not lower than the condition threshold, the execution condition is met.
S36: if the execution condition is met, then,
locking the timing task;
the locked timed task is taken as a target timed task, and the local server can not execute any more tasks except the target timed task during the locking.
Specifically, step S31 is a process of triggering an information capturing program, where the information capturing program is used to obtain parameters and various status data of a local server, so as to determine whether the local server can execute the target timing task;
step S32 is a specific process of obtaining specification information of the local server by the information capture program, in this embodiment, the information capture program may be any program, plug-in, or statement that has the specification information of the local server, in this embodiment, the specification information of the local server is obtained by os and os-utilis dependent calculation, and the specification information includes an IP address locaipip, a CPU utilization rate cpuprate, a memory utilization rate memRate, and the like;
step S33 is a process of determining whether the local server is executing other tasks according to the obtained local IP address, where the specific determination means is to search whether there is data with IP being locaipip and status being state during execution in the database table through an inquiry statement, so as to determine whether there is other timing task running on the current server;
step S34 is to determine whether the memory usage rate and the CPU usage rate obtained in step S32 reach preset conditions, where in this embodiment, the preset conditions are eighty percent, that is, only when the cpuprate and the memRate are both less than 80%, and the current server is not running other timing tasks, the preset conditions are met for executing the timing task;
step S36 is a process of taking the timing task as a target timing task, when the target timing task is locked, the local server cannot simultaneously start the execution of other timing tasks, so as to ensure that the CPU utilization rate and the memory utilization rate always reach the standard in the time difference from waiting for execution to specific execution;
more specifically, in the present embodiment, the timed task name _ n starts to be executed when the preset fixed time is reached every day. Firstly, obtaining a local IP address localIp, a CPU utilization rate cpuRate and a memory utilization rate memRate through os and os-utils dependence calculation. Because the data volume of the timing task operation is larger, the occupied resource is more, and besides the data volume is also used for bearing a large amount of other real-time services, a threshold value of 80% is set for preventing the response speed of other real-time services from being influenced when the timing task runs. Only when the cpuRate and the memRate are both less than 80 percent and the current server is not running other timing tasks, the downward execution is continued; otherwise, repeating the judgment after waiting for 10 seconds; under the same local area network, the local IP of each server is unique, so that whether the current server runs other timing tasks or not can be judged by executing SQL to search whether data of the executing state of which the IP is localIP and the status is going exists in the schedule table.
In the embodiment shown in fig. 1, step S4 is to search in a database table whether a data name and a task variable corresponding to the target execution task exist, and if so, execute the target timing task according to the state of the task variable; if the data name and the task variable do not exist, creating a target data name and a target task variable related to the target timing task, executing the target timing task, and changing the state of the target task variable into the executed state; wherein, include:
s41: searching whether a data name and a task variable corresponding to the target execution task exist in the database table;
s42: if the data name and the task variable corresponding to the target timing task exist, the target timing task is executed according to the state pertinence of the task variable;
if the data name and the task variable exist, the target timing task is executed according to the state pertinence of the task variable, and the method comprises the following steps:
s421: if the data name and the task variable corresponding to the target timing task exist, acquiring the real-time state of the state variable and a task execution ip column corresponding to the target timing task from the database table;
s422: if the real-time state is a waiting state and the task execution IP column is empty, executing the target timing task, changing the real-time state into a positive execution state, and filling the IP of the local server into the task execution IP column; wherein,
if the real-time state is an error state and other IPs except the local server are filled in the task execution IP column, executing the target timing task, changing the real-time state into a positive execution state, filling the IP of the local server in the task execution IP column and covering the other IPs;
if the real-time state is an executing state or an executed state, the local server is caused to terminate executing the target timing task;
s423: if the data name and the task variable do not exist, creating a target data name and a target task variable related to the target timing task, executing the target timing task, and changing the state of the target task variable into the executed state;
wherein the process of executing the target timing task comprises:
analyzing the target timing task to obtain task logic;
and executing the task through a preset execution statement according to the task logic to obtain a task result, and remarking the task in a remark column in the database table to complete the identification symbol.
In this embodiment, step S41 is to record the log first: [ timed task ] Server $ { localIp $ { name _ n } starts executing. Searching SQL (search statement) for searching if the schedule table has a timing task with the name being name _ n, if not, executing SQL (execution statement) to create a timing task with the name being name _ n and the status being state during execution, and then jumping to execute step S43; if so, go to step S42;
step S42 is a case where a data name and a task variable corresponding to the target timing task exist, in this embodiment, SQL is executed to search whether a timing task whose name is name _ n and status is waiting status exists in the schedule table, if yes, status is set to done and ip is localpi, that is, if found, the operation of the target timing task is executed, if not found, SQL is executed to search whether data whose name is name _ n, ip is not localpi and status is error exists, if yes, status is updated to done and ip is localpi, the next operation of executing the target timing task is performed, and if not, the operation is ended;
step S43 is that no data name and task variable exist, then create the target data name and target task variable related to the target timing task, execute the target timing task, and change the state of the target task variable into the executed process, namely, execute SQL to create the timing task with name _ n and status as state during execution;
in this embodiment, the specific process of executing the target timing task is as follows: executing the specific business logic of the scheduled name _ n of the timing task; after the successful execution is finished, SQL searches the timing task with the name being the name _ n and the state being the ding in the schedule table, sets the state as success, and records the log: [ timed task ] Server $ { localIp $ { name _ n } successfully ends.
It should be noted that, when the target timing task is re-executed, the method further includes:
defining a counting variable;
monitoring whether the execution statement completely executes the task according to the task logic or not through a preset retry mechanism, if the execution statement executes the task according to the task logic, adding 1 to the counting variable, starting to execute the task for the second time, if the execution statement executes the task according to the task logic during the second time, adding 1 to the counting variable, starting to execute the task for the third time, if the execution task for the third time is not executed according to the task logic, terminating the execution of the target timing task, and changing the real-time state into an error state in the database table;
specifically, the link for executing the target task includes a retry mechanism, and when the preset time is reached, if an error is executed in each step, the error retry mechanism is entered, specifically, by defining a variable num, each retry may add 1 to num, and after 3 times of retrying, that is, num > is 3, if the error still fails, the timing task whose name is name _ n and status is state during execution in the schedule table is searched, and the status is error, and the log is recorded: [ timed task ] the failure ends after $ { name _ n } on $ { locaipip } retry for 3 times.
And because the mechanism of the write exclusive lock is arranged when the cluster is built in the step S1, it can be ensured that only one instance can enter the next step when an execution operation needs to be performed on one timed task, and other instances all end the operation, and when a database table is newly created in the step S2, the statuses of the timed task share 4 states of waiting for execution, going (executing), success, and error, so that the execution synchronization problem of multiple instances and multiple timed tasks is converted into the operation lock problem of data, thereby implementing the asynchronous execution and preventing the repeated execution of the timed task. The parameters of the local server are obtained through the step S3, so that the timing task can be executed on a proper machine without influencing the response speed of other real-time services; by performing the classification in step S4 in a targeted manner, it is possible to avoid the situation that the execution of the timing task fails due to the difference between the servers themselves, so as to ensure that the timing task is finally executed successfully.
In this embodiment, the server may be an independent server, or may be a cloud server that provides basic cloud computing services such as a cloud service, a cloud database, cloud computing, a cloud function, cloud storage, a Network service, cloud communication, a middleware service, a domain name service, a security service, a Content Delivery Network (CDN), a big data and an artificial intelligence platform, and the like.
As described above, the cluster timed task execution method provided by the present invention first deploys a cluster example on each server in a server cluster, deploys a timed task under the cluster example, creates a new database table, stores a data name corresponding to the created timed task in the database table, and defines a task variable corresponding to the data name; when the preset time is reached, judging whether the local server has an execution condition for executing a timing task corresponding to the preset time or not by acquiring the parameters of the local server, and if the execution condition is met, taking the timing task as a target timing task; then, whether a data name and a task variable corresponding to the target execution task exist or not is searched in a database table, and if the data name and the task variable exist, the target timing task is executed according to the state pertinence of the task variable; if the data name and the task variable do not exist, the target data name and the target task variable related to the target timing task are created, the target timing task is executed, and the state of the target task variable is changed into the executed state.
As shown in fig. 2, the present invention provides a cluster timed task execution device 100, which can be installed in an electronic device. According to the implemented functions, the cluster timing task execution device 100 may include a cluster deployment unit 101, a task definition unit 102, an object locking unit 103, and a task execution unit 104. The module of the present invention, which may also be referred to as a unit, refers to a series of computer program segments that can be executed by a processor of an electronic device and that can perform a fixed function, and that are stored in a memory of the electronic device.
In the present embodiment, the functions regarding the respective modules/units are as follows:
a cluster deployment unit 101, configured to deploy a cluster example on each server in a server cluster, and deploy a timing task under the cluster example;
a task defining unit 102, configured to create a database table, store a data name corresponding to the created timing task in the database table, and define a task variable corresponding to the data name in the database table;
the target locking unit 103 is configured to, when a preset time for executing a timing task is reached, determine whether the local server has an execution condition for executing the timing task corresponding to the preset time by acquiring a parameter of the local server, and if the execution condition is met, set the timing task as a target timing task;
the task execution unit 104 is configured to search, in the database table, whether a data name and a task variable corresponding to the target execution task exist, and if the data name and the task variable exist, execute the target timing task according to a state of the task variable; and if the data name and the task variable do not exist, creating a target data name and a target task variable related to the target timing task, executing the target timing task, and changing the state of the target task variable into the executed state.
As described above, the cluster timed task execution device 100 provided by the present invention first deploys a cluster instance on each server in a server cluster through the cluster deployment unit 101, deploys a timed task under the cluster instance, and then creates a database table through the task definition unit 102, stores a data name corresponding to the created timed task in the database table, and defines a task variable corresponding to the data name; further, by using the target locking unit 103, when the preset time is reached, whether the local server has an execution condition for executing a timing task corresponding to the preset time is judged by acquiring the parameter of the local server, and if the execution condition is met, the timing task is taken as a target timing task; then, whether a data name and a task variable corresponding to the target execution task exist or not is searched in a database table through the task execution unit 104, and if the data name and the task variable exist, the target timing task is executed according to the state pertinence of the task variable; if the data name and the task variable do not exist, the target data name and the target task variable related to the target timing task are created, the target timing task is executed, and the state of the target task variable is changed into the executed state.
As shown in fig. 3, the present invention provides an electronic device 1 for performing a cluster timed task.
The electronic device 1 may comprise a processor 10, a memory 11 and a bus, and may further comprise a computer program, such as a cluster timed task execution program 12, stored in the memory 11 and executable on said processor 10.
The memory 11 includes at least one type of readable storage medium, which includes flash memory, removable hard disk, multimedia card, card-type memory (e.g., SD or DX memory, etc.), magnetic memory, magnetic disk, optical disk, etc. The memory 11 may in some embodiments be an internal storage unit of the electronic device 1, such as a removable hard disk of the electronic device 1. The memory 11 may also be an external storage device of the electronic device 1 in other embodiments, such as a plug-in mobile 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 electronic device 1. Further, the memory 11 may also include both an internal storage unit and an external storage device of the electronic device 1. The memory 11 may be used not only for storing application software installed in the electronic device 1 and various types of data, such as codes executed by a cluster timing task, etc., but also for temporarily storing data that has been output or is to be output.
The processor 10 may be composed of an integrated circuit in some embodiments, for example, a single packaged integrated circuit, or may be composed of a plurality of integrated circuits packaged with the same or different functions, including one or more Central Processing Units (CPUs), microprocessors, digital Processing chips, graphics processors, and combinations of various control chips. The processor 10 is a Control Unit (Control Unit) of the electronic device, connects various components of the electronic device by using various interfaces and lines, and executes various functions and processes data of the electronic device 1 by running or executing programs or modules (e.g., cluster timing task execution programs, etc.) stored in the memory 11 and calling data stored in the memory 11.
The bus may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. The bus is arranged to enable connection communication between the memory 11 and at least one processor 10 or the like.
Fig. 3 shows only an electronic device with components, and it will be understood by those skilled in the art that the structure shown in fig. 3 does not constitute a limitation of the electronic device 1, and may comprise fewer or more components than those shown, or some components may be combined, or a different arrangement of components.
For example, although not shown, the electronic device 1 may further include a power supply (such as a battery) for supplying power to each component, and preferably, the power supply may be logically connected to the at least one processor 10 through a power management device, so as to implement functions of charge management, discharge management, power consumption management, and the like through the power management device. The power supply may also include any component of one or more dc or ac power sources, recharging devices, power failure detection circuitry, power converters or inverters, power status indicators, and the like. The electronic device 1 may further include various sensors, a bluetooth module, a Wi-Fi module, and the like, which are not described herein again.
Further, the electronic device 1 may further include a network interface, and optionally, the network interface may include a wired interface and/or a wireless interface (such as a WI-FI interface, a bluetooth interface, etc.), which are generally used for establishing a communication connection between the electronic device 1 and other electronic devices.
Optionally, the electronic device 1 may further comprise a user interface, which may be a Display (Display), an input unit (such as a Keyboard), and optionally a standard wired interface, a wireless interface. Alternatively, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode) touch device, or the like. The display, which may also be referred to as a display screen or display unit, is suitable for displaying information processed in the electronic device 1 and for displaying a visualized user interface, among other things.
It is to be understood that the described embodiments are for purposes of illustration only and that the scope of the appended claims is not limited to such structures.
The memory 11 in the electronic device 1 stores a cluster timing task execution program 12, which is a combination of instructions that, when executed in the processor 10, can implement:
deploying a cluster example on each server in the server cluster, and deploying a timing task under the cluster example;
storing a data name corresponding to the established timing task in a newly-established database table, and defining a task variable corresponding to the data name in the database table;
when the preset time for executing the timing task is reached, judging whether the local server has an execution condition for executing the timing task corresponding to the preset time or not by acquiring the parameters of the local server, and if the execution condition is met, setting the timing task as a target timing task;
searching whether a data name and a task variable corresponding to the target execution task exist in a database table, and if the data name and the task variable exist, executing the target timing task according to the state of the task variable; and if the data name and the task variable do not exist, creating a target data name and a target task variable related to the target timing task, executing the target timing task, and changing the state of the target task variable into the executed state.
Specifically, the specific implementation method of the processor 10 for the instruction may refer to the description of the relevant steps in the embodiment corresponding to fig. 1, which is not described herein again. It should be emphasized that, in order to further ensure the privacy and security of the execution of the cluster timing task, the data executed by the cluster timing task is stored in the node of the block chain where the server cluster is located.
The server may be an independent server, or may be a cloud server that provides basic cloud computing services such as a cloud service, a cloud database, cloud computing, a cloud function, cloud storage, a Network service, cloud communication, a middleware service, a domain name service, a security service, a Content Delivery Network (CDN), and a big data and artificial intelligence platform.
Further, the integrated modules/units of the electronic device 1, if implemented in the form of software functional units and sold or used as separate products, may be stored in a computer readable storage medium. The computer-readable medium may include: any entity or device capable of carrying said computer program code, recording medium, U-disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM).
An embodiment of the present invention further provides a computer-readable storage medium, where the storage medium may be nonvolatile or volatile, and the storage medium stores a computer program, and when the computer program is executed by a processor, the computer program implements:
deploying a cluster example on each server in the server cluster, and deploying a timing task under the cluster example;
storing a data name corresponding to the established timing task in a newly-established database table, and defining a task variable corresponding to the data name in the database table;
when the preset time for executing the timing task is reached, judging whether the local server has an execution condition for executing the timing task corresponding to the preset time or not by acquiring the parameters of the local server, and if the execution condition is met, setting the timing task as a target timing task;
searching whether a data name and a task variable corresponding to the target execution task exist in a database table, and if the data name and the task variable exist, executing the target timing task according to the state of the task variable; and if the data name and the task variable do not exist, creating a target data name and a target task variable related to the target timing task, executing the target timing task, and changing the state of the target task variable into the executed state.
Specifically, for a specific implementation method of the computer program when being executed by the processor, reference may be made to the description of the relevant steps in the cluster timing task execution method in the embodiment, which is not described herein again.
In the embodiments provided in the present invention, it should be understood that the disclosed apparatus, device and method can be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the modules is only one logical functional division, and other divisions may be realized in practice.
The modules described as separate parts may or may not be physically separate, and parts displayed as modules may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment.
In addition, functional modules in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, or in a form of hardware plus a software functional module.
It will be evident to those skilled in the art that the invention is not limited to the details of the foregoing illustrative embodiments, and that the present invention may be embodied in other specific forms without departing from the spirit or essential attributes thereof.
The present embodiments are therefore to be considered in all respects as illustrative and not restrictive, the scope of the invention being indicated by the appended claims rather than by the foregoing description, and all changes which come within the meaning and range of equivalency of the claims are therefore intended to be embraced therein. Any reference signs in the claims shall not be construed as limiting the claim concerned.
The block chain is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, a consensus mechanism, an encryption algorithm and the like. 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 service layer, an application service layer, and the like.
Furthermore, it is obvious that the word "comprising" does not exclude other elements or steps, and the singular does not exclude the plural. A plurality of units or means recited in the system claims may also be implemented by one unit or means in software or hardware. The terms second, etc. are used to denote names, but not any particular order.
Finally, it should be noted that the above embodiments are only for illustrating the technical solutions of the present invention and not for limiting, and although the present invention is described in detail with reference to the preferred embodiments, it should be understood by those skilled in the art that modifications or equivalent substitutions may be made on the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention.

Claims (10)

1. A cluster timed task execution method is characterized by comprising the following steps:
deploying a cluster instance on each server in a server cluster and deploying a timed task under the cluster instance;
storing a data name corresponding to the created timing task in a newly-built database table, and defining a task variable corresponding to the data name in the database table;
when the preset time for executing the timing task is reached, judging whether the local server has an execution condition for executing the timing task corresponding to the preset time or not by acquiring parameters of the local server, and if the execution condition is met, setting the timing task as a target timing task;
searching whether a data name and a task variable corresponding to the target execution task exist in the database table, and if the data name and the task variable exist, executing the target timing task according to the state of the task variable; and if the data name and the task variable do not exist, creating a target data name and a target task variable related to the target timing task, executing the target timing task, and changing the state of the target task variable into the executed state.
2. The method of cluster timed task execution according to claim 1, wherein said deploying a cluster instance on each server in a cluster of servers and a timed task under said cluster instance comprises:
building a server cluster;
deploying a cluster case on the server cluster;
connecting the cluster case with a preset database;
all preset timing tasks are deployed in each cluster case, and all data about the timing tasks in the cluster cases are transmitted to the database.
3. The cluster timed task execution method according to claim 1, wherein storing the data name corresponding to the created timed task in a newly created database table and defining the task variable corresponding to the data name comprises:
defining task variables corresponding to the timing tasks in the database table, and data name columns, task variable columns, task execution ip columns and remark columns corresponding to the task variables, wherein the task variables are used for reflecting the states of the timing tasks;
populating the database table according to the timed task, including: and storing a data name corresponding to the created timing task in the data name column, filling the task variable in the task variable column, storing a server IP for executing the timing task in the task execution IP column, and storing the completion status of the timing task execution in the remark column.
4. The cluster timed task execution method according to claim 1, wherein when the preset time for executing the timed task is reached, judging whether the local server has an execution condition for executing the timed task corresponding to the preset time by obtaining parameters of the local server includes:
the method comprises the steps that the preset time for executing a timing task is monitored in real time, and when the preset time is reached, the timing task triggers an information capturing program;
acquiring specification information of a local server through the information capture program; the specification information comprises a local IP address of the local server, a local CPU utilization rate and a local memory utilization rate;
searching whether an executing task related to the local IP address exists in the database table according to the local IP address;
if the task which is about to be executed by the local IP address does not exist, judging whether the utilization rate of the local CPU and the utilization rate of the local memory are not lower than a preset condition threshold value or not; wherein, in this embodiment, the condition threshold is eighty percent;
and if the execution condition is not lower than the condition threshold, the execution condition is met.
5. The cluster timed task execution method according to claim 4, characterized in that if the execution condition is met,
locking the timing task;
the locked timed task is taken as a target timed task, and the local server can not execute any more tasks except the target timed task during the locking.
6. The method for performing cluster timed tasks according to claim 1, wherein if the data name and the task variable exist, the performing the target timed task according to the state of the task variable comprises:
if the data name and the task variable corresponding to the target timing task exist, acquiring the real-time state of the state variable and a task execution ip column corresponding to the target timing task from the database table;
if the real-time state is a waiting state and the task execution IP column is empty, executing the target timing task, changing the real-time state into a positive execution state, and filling the IP of the local server into the task execution IP column; wherein,
if the real-time state is an error state and other IPs except the local server are filled in the task execution IP column, executing the target timing task, changing the real-time state into a positive execution state, filling the IP of the local server in the task execution IP column and covering the other IPs;
if the real-time state is an executing state or an executed state, the local server is caused to terminate executing the target timing task;
and if the data name and the task variable do not exist, creating a target data name and a target task variable related to the target timing task, executing the target timing task, and changing the state of the target task variable into the executed state.
7. The cluster timed task execution method according to claim 6, characterized in that said executing of said target timed task comprises:
analyzing the target timing task to obtain task logic;
and executing the task through a preset execution statement according to the task logic to obtain a task result, and remarking the task in a remark column in the database table to complete the identification symbol.
8. A cluster timed task execution apparatus, the apparatus comprising:
the system comprises a cluster deployment unit, a task scheduling unit and a task scheduling unit, wherein the cluster deployment unit is used for deploying a cluster example on each server in a server cluster and deploying a timing task under the cluster example;
the task definition unit is used for newly building a database table, storing a data name corresponding to the created timing task in the database table, and defining a task variable corresponding to the data name in the database table;
the target locking unit is used for judging whether the local server has an execution condition for executing the timing task corresponding to the preset time or not by acquiring the parameters of the local server when the preset time for executing the timing task is reached, and setting the timing task as the target timing task if the execution condition is met;
the task execution unit is used for searching whether a data name and a task variable corresponding to the target execution task exist in the database table, and if the data name and the task variable exist, the target timing task is executed according to the state of the task variable; and if the data name and the task variable do not exist, creating a target data name and a target task variable related to the target timing task, executing the target timing task, and changing the state of the target task variable into the executed state.
9. An electronic device, characterized in that the electronic device comprises:
at least one processor; and the number of the first and second groups,
a memory communicatively coupled to the at least one processor; wherein,
the memory stores a computer program executable by the at least one processor to enable the at least one processor to perform the steps of the method of cluster timed task execution as claimed in any one of claims 1 to 7.
10. A computer-readable storage medium, storing a computer program, wherein the computer program, when executed by a processor, implements the cluster timed task execution method according to any of claims 1 to 7.
CN202111271009.2A 2021-10-29 2021-10-29 Cluster timing task execution method and device, electronic equipment and storage medium Pending CN114003316A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111271009.2A CN114003316A (en) 2021-10-29 2021-10-29 Cluster timing task execution method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111271009.2A CN114003316A (en) 2021-10-29 2021-10-29 Cluster timing task execution method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114003316A true CN114003316A (en) 2022-02-01

Family

ID=79925052

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111271009.2A Pending CN114003316A (en) 2021-10-29 2021-10-29 Cluster timing task execution method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114003316A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115460194A (en) * 2022-08-20 2022-12-09 杭州沧浪健康管理有限公司 Applet construction uploading method and device, computer equipment and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2012052775A1 (en) * 2010-10-21 2012-04-26 Bluwireless Technology Limited Data processing systems
CN110018893A (en) * 2019-03-12 2019-07-16 平安普惠企业管理有限公司 A kind of method for scheduling task and relevant device based on data processing
CN111459951A (en) * 2020-02-25 2020-07-28 深圳联友科技有限公司 Method and device for supporting cluster through timing task
CN112416581A (en) * 2020-11-13 2021-02-26 五八同城信息技术有限公司 Distributed calling system for timed tasks

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2012052775A1 (en) * 2010-10-21 2012-04-26 Bluwireless Technology Limited Data processing systems
CN110018893A (en) * 2019-03-12 2019-07-16 平安普惠企业管理有限公司 A kind of method for scheduling task and relevant device based on data processing
CN111459951A (en) * 2020-02-25 2020-07-28 深圳联友科技有限公司 Method and device for supporting cluster through timing task
CN112416581A (en) * 2020-11-13 2021-02-26 五八同城信息技术有限公司 Distributed calling system for timed tasks

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115460194A (en) * 2022-08-20 2022-12-09 杭州沧浪健康管理有限公司 Applet construction uploading method and device, computer equipment and storage medium

Similar Documents

Publication Publication Date Title
CN112134739A (en) Link state tracking method and device, electronic equipment and computer storage medium
CN113342472A (en) Micro-service cluster creating method and device, electronic equipment and readable storage medium
CN112085217A (en) Method, device, equipment and computer medium for deploying artificial intelligence service
CN112506779A (en) Software interface testing method and device, electronic equipment and storage medium
CN111897548A (en) Front-end resource publishing method and device, electronic equipment and computer storage medium
CN114881616A (en) Business process execution method and device, electronic equipment and storage medium
CN111694844A (en) Enterprise operation data analysis method and device based on configuration algorithm and electronic equipment
CN113741909A (en) Micro-service deployment method, device, electronic equipment and storage medium
CN113704665A (en) Dynamic service publishing method, device, electronic equipment and storage medium
CN114356530A (en) Task scheduling method and device, electronic equipment and storage medium
CN112256783A (en) Data export method and device, electronic equipment and storage medium
CN115392501A (en) Data acquisition method and device, electronic equipment and storage medium
CN111897599A (en) Service method, device, equipment and storage medium based on microkernel model plug-in mode
CN114385497A (en) Test environment generation method and device, electronic equipment and storage medium
CN114003316A (en) Cluster timing task execution method and device, electronic equipment and storage medium
CN113986924A (en) Intelligent data filling method, device, equipment and storage medium
CN113542387A (en) System publishing method, device, electronic equipment and storage medium
CN115757121A (en) Test method, device, equipment and storage medium built based on test environment
CN114510400A (en) Task execution method and device, electronic equipment and storage medium
CN115687384A (en) UUID (user identifier) identification generation method, device, equipment and storage medium
CN114625712A (en) Data synchronization method and device, electronic equipment and storage medium
CN114911479A (en) Interface generation method, device, equipment and storage medium based on configuration
CN114625512A (en) Task scheduling method and device, electronic equipment and storage medium
CN114626103A (en) Data consistency comparison method, device, equipment and medium
CN115145870A (en) Method and device for positioning reason of failed task, electronic equipment and storage medium

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