Summary of the invention
In order to solve problems in the prior art, the embodiment of the invention provides a kind of dispatching method of distributed task scheduling and it isSystem, not only realizes the monitoring of the real time health state of real-time task, and ensure that the global High Availabitity of integrity service simultaneouslyDesign and can horizontal scalable appearance, while functions such as flexible configuration for also achieving monitor task.
To solve said one or multiple technical problems, the technical solution adopted by the present invention is that:
On the one hand, a kind of dispatching method of distributed task scheduling is provided, this method comprises the following steps:
Master node is elected in the cluster of application server by Zookeeper;
Being collected into for task is written under the respective directories node in the specified task list of the Zookeeper;
The Master node starts timed task, reads the task under the directory node, obtains task list;
The Master node starts thread pool, the task in task list described in asynchronous allocation;
The task after disposing asynchronous allocation by load-balanced server equilibrium is into the application server clusterEach node executed.
Further, the Master node starts thread pool, and the task in task list described in asynchronous allocation includes:
It loses in the thread pool and executes after task in the task list is packaged as sub thread.
Further, the Master node starts thread pool, the task in task list described in asynchronous allocation further include:
The service logic of the task is packaged into http request and is sent to the load-balanced server by the sub thread.
Further, before the Master node starting timed task, the method also includes:
The relevant operation in the specified task list of the Zookeeper is monitored, obtains the more new content of task in real time, andUpdate the task list.
Further, the method also includes:
When the Master node delay machine, Zookeeper is re-elected out newly in the cluster of the application serverMaster node execute relevant operation.
Further, the method also includes:
The node in the cluster of the application server is increased or decreased by redeploying the application server realizingQuantity.
On the other hand, a kind of scheduling system of distributed task scheduling is provided, the system comprises:
Host node elects module, for electing Master node in the cluster of application server by Zookeeper;
Task collection module, for being collected into for task to be written to the phase in the specified task list of the ZookeeperIt answers under directory node;
List obtains module, starts timed task for the Master node, reads described under the directory nodeTask obtains task list;
Task allocating module starts thread pool for the Master node, appointing in task list described in asynchronous allocationBusiness;
Balanced deployment module, for disposing the task after asynchronous allocation by load-balanced server equilibrium to describedEach node in application server cluster is executed.
Further, the task allocating module includes:
Sub thread encapsulation unit, for being lost after being packaged the task in the task list as sub thread into describedIt is executed in thread pool.
Further, the task allocating module further include:
Encapsulation unit is requested, the service logic of the task is packaged into http request for the sub thread and is sent to instituteState load-balanced server.
Further, the system also includes:
Catalogue update module obtains in real time for monitoring the relevant operation in the specified task list of the ZookeeperThe more new content of task, and update the task list.
Further, the system also includes:
Module is re-elected, collection of the Zookeeper in the application server when the Master node delay machine is used forNew Master node is re-elected out in group executes relevant operation.
Further, the system also includes:
Scalable molar block, for increasing or decreasing the application server by redeploying the application server realizingCluster in node quantity.
Technical solution provided in an embodiment of the present invention has the benefit that
1, the dispatching method and system of distributed task scheduling provided in an embodiment of the present invention solves and appoints including monitoring operation etc.In scheduling process of being engaged in, the distributed lock and cluster multinode principal and subordinate's election issues of multi-node cluster timed task, and be not limited toThe business processing scene of processing monitoring operation, is equally applicable to other task schedule scenes without dependence operation;
2, the dispatching method and system of distributed task scheduling provided in an embodiment of the present invention is based on Zookeeper frame natureReasonable utilization, realize the flexible configuration of task, registration, cancellation, alarm content item, alarm threshold value comprising task and appointThe functions such as the real-time dynamic adjustment for dispatching cycle of being engaged in;
3, the dispatching method and system of distributed task scheduling provided in an embodiment of the present invention realizes point of real-time calculating taskThe scheme of cloth business scenario, the overall situation are designed using HA High Availabitity characteristic, for the growth for monitoring the business scales such as operation or are subtractedIt is few, dynamic may be implemented and do not shut down scalable appearance.
Specific embodiment
To make the object, technical solutions and advantages of the present invention clearer, below in conjunction with attached in the embodiment of the present inventionFigure, technical scheme in the embodiment of the invention is clearly and completely described, it is clear that described embodiment is only thisInvention a part of the embodiment, instead of all the embodiments.Based on the embodiments of the present invention, those of ordinary skill in the art existEvery other embodiment obtained under the premise of creative work is not made, shall fall within the protection scope of the present invention.
The main application scenarios of the embodiment of the present invention are that the stream calculation operation run in convection current computing platform is monitored in real time.Specifically use monitor mode for using timed task (such as 1 minute fixed time interval period), the operating status of timing acquiring taskCollected parameter is carried out being persisted to DB server, and is configured simultaneously according to business monitoring by parameter, specified to business personnelThe abnormal index for needing to alarm carries out Realtime Alerts.The schedule job of the embodiment of the present invention is not limited to above-mentioned monitoring operation and patrolsVolume, other business scenarios equally can be laterally generalized to, here only using monitoring business as description distributed scheduling of the inventionThe special case of method and system is illustrated.
Fig. 1 is the flow chart of the dispatching method of distributed task scheduling shown according to an exemplary embodiment, referring to Fig.1 instituteShow, this method comprises the following steps:
Master node is elected in the cluster of application server by Zookeeper.
Specifically, used Zookeeper cluster as distributed type assemblies dispatch coordination service in the embodiment of the present invention, andThe Master node for providing application server cluster elects service, while the distributed lock for also solving cluster timed task is askedTopic.In addition, Zookeeper cluster equally plays storage job configuration information and monitors the registration center role of operation.The scale of Zookeeper cluster usually takes the deployment mode of 2N+1 node.
What needs to be explained here is that when the application server in the embodiment of the present invention starts, it is necessary first to be initializedOperation.The content mainly initialized is the interaction with Zookeeper cluster, and all nodes in application server cluster requireConnection is established with the same Zookeeper cluster, and creates client instance.Then the node of all application servers need to makeIt uses and specifies the same directory path as parameter, create Leader Latch example on Zookeeper respectively, and exist simultaneouslyLeaderLatchListener monitor is added in Leader Latch example.
Being collected into for task is written under the respective directories node in the specified task list of the Zookeeper.
Specifically, in the embodiment of the present invention, task registration can be set and submit center to carry out the registration of task, update,The operation such as deletion.When it is implemented, can be by monitoring the task in the inter-related task catalogue that task registration submits center to submitThe operation such as creation or registration, to collect whole mission bit streams, and the whole tasks that will acquire are written to what Zookeeper was specifiedUnder respective directories node in task list.
The Master node reads the task under the directory node, obtains task list.
Specifically, after some node in Zookeeper election application server cluster is as Master node,Master node starts timed task, such as triggers the isLeader method of monitor.At this point, Master node can beThe specified ZK catalogue for monitoring job logging information is begun listening in isLeader method, and (i.e. Zookeeper is specified to be appointedBusiness catalogue), to collect the whole mission bit streams for needing to monitor.
The Master node starts thread task pool, the task in task list described in asynchronous allocation.
The task after disposing asynchronous allocation by load-balanced server equilibrium is into the application server clusterEach node executed.
Specifically, load-balanced server in the embodiment of the present invention uses Nginx, Nginx is by all task balancesThe cluster for being distributed to application server each child node processing.
As a kind of preferably embodiment, in the embodiment of the present invention, the Master node starts thread pool, and asynchronous pointInclude: with the task in the task list
It loses in the thread pool and executes after task in the task list is packaged as sub thread.
Specifically, will start thread pool after Master node obtains task list, using the task in task list as sonThread is lost in thread pool after being packaged to be executed.What needs to be explained here is that the thread pool in the embodiment of the present invention usesScheduledExecutorService。
As a kind of preferably embodiment, in the embodiment of the present invention, the Master node starts thread pool, and asynchronous pointWith the task in the task list further include:
The service logic of the task is packaged into http request and is sent to the load-balanced server by the sub thread.
Specifically, task schedule sub thread configures (i.e. service logic) when handling specific service logic, by job parameterIt is packaged into http request, then load balancing is carried out by Nginx service (i.e. load-balanced server), equilibrium assignment takes to applicationEach node being engaged in the cluster of device realizes asynchronous process.It, can also be with if the process performance of the node of each application server is differentOther allocation strategies such as distribution are weighted by adjusting the configuration of load-balanced server.
As a kind of preferably embodiment, in the embodiment of the present invention, before the Master node starting timed task, instituteState method further include:
The relevant operation in the specified task list of the Zookeeper is monitored, obtains the more new content of task in real time, andUpdate the task list.
Specifically, the relevant operation in task list includes the operations such as creation, update, deletion in the embodiment of the present invention.PrisonThe relevant operation in task list for listening Zookeeper specified, the root content information including collecting including task registration etc. are rightTask list is updated.
Below by taking the scheduling of monitor task as an example, the scheme for collecting task registration information is illustrated.Setting is unified firstMission Monitor path, such as can be set Mission Monitor path be /xxx/jobs, then start a monitor monitor the meshRecord, for finding/the operation such as creation, update, the deletion of subdirectory of xxx/jobs catalogue.When task submits center to have new taskWhen (such as job1) is registered, can zookeeper /xxx/jobs catalogue under creation/xxx/jobs/job1, and register correspondingMonitor control index item.When the monitor discovery of monitoring and dispatching system has newly created subdirectory (/xxx/jobs/job1), it is meant thatThere is new operation to joined monitoring queue, monitor can trigger corresponding monitoring movement, can read newly created subdirectory hereNodal information, pass through parsing node content (Json character string), obtain the monitoring configuration information of corresponding operation.Simultaneously according to workIndustry configuration information creates a specific business processing thread.The thread is put into thread pool simultaneously, with the timing week of configurationPhase timer-triggered scheduler executes.
When submission center have task (such as job1) it is offline when, zookeeper/xxx/jobs/job1 subdirectory can be deletedIt removes.The monitor discovery (/xxx/jobs/job1) of task scheduling system disappears at this time, shows that job1 does not need to monitor already.The snoop-operations of monitor triggering at this time are to kill timer-triggered scheduler task.
If system needs in the process of running, the specific task timer-triggered scheduler period to be customized again, at this point it is possible to pass throughMore new node/xxx/jobs/jobN configuration information.When the value value that Master node listens to the node updates, meetingKill falls original timer-triggered scheduler task, and timed task is restarted in the configuration after reusing change.
As a kind of preferably embodiment, in the embodiment of the present invention, the method also includes:
When the Master node delay machine, Zookeeper is re-elected out newly in the cluster of the application serverMaster node execute relevant operation.
Specifically, the characteristic of the High Availabitity of the dispatching method in order to realize distributed task scheduling, in the embodiment of the present invention, when answeringWhen with Master node delay machine in the cluster of server, Zookeeper, which can be triggered, re-elects the operation of Master node (such asTriggered using the LeaderLatch mechanism of Zookeeper), after new Mater node is elected, it can re-start initialChange operation, refreshes the task list for needing to dispatch, the scheduling flow before reentering.What needs to be explained here is that when oldWhen Master node restores, it can default and schedule job distribution is participated in the identity of slave node.
When Slave node delay machine (such as service processes are lost or network is obstructed) in the cluster of application server, thenThe integrated scheduling of task is not influenced, can only reduce the concurrency performance of system.Slave node serve restarts or when network recovery,It can state before seamless recovery.When ensure that arbitrary node exception in application server above, the High Availabitity of integrity service.
It is further to note that in the embodiment of the present invention, when certain node state exception in Zookeeper cluster(including leader node or other follower nodes), the ZAB agreement being had by oneself by Zookeeper ensure that the weight of leaderThe consistency of new election and clustered node data.Therefore, the node of Zookeeper cluster also meets the feature of High Availabitity.
As a kind of preferably embodiment, in the embodiment of the present invention, the method also includes:
The node in the cluster of the application server is increased or decreased by redeploying the application server realizingQuantity.
Specifically, can be realized by simply modifying the configuration file of load-balanced server in the embodiment of the present inventionThe dilatation of application server cluster and capacity reducing.It can also be made built in load-balanced server by modification configuration file simultaneouslyLoad balancing is adjusted.
For example, when business game quantity (i.e. task quantity) dramatically increases, if application server cluster process performanceReach bottleneck, horizontal extension can be carried out by newly-increased application server node.Simplified deployment application service is only needed at this timeThe configuration of device and modification load-balanced server.It equally, can also be direct when business game quantity (i.e. task quantity) is lessThe mode of offline application server node realizes horizontal capacity reducing.In the embodiment of the present invention, 1 application server node of minimum supportOperation, both having served as the progress task schedule distribution of Master node can also be used as the processing that Work node carries out service logic.ThisIn it should be noted that if the process performance of each application server node is different, can also be by adjusting load balancing serviceThe configuration of device is weighted other allocation strategies such as distribution.
Fig. 2 is the structural schematic diagram of the scheduling system of distributed task scheduling shown according to an exemplary embodiment, referring to Fig. 2Shown, which includes:
Host node elects module, for electing Master node in the cluster of application server by Zookeeper;
Task collection module, for being collected into for task to be written to the phase in the specified task list of the ZookeeperIt answers under directory node;
List obtains module, starts timed task for the Master node, reads described under the directory nodeTask obtains task list;
Task allocating module starts thread pool for the Master node, appointing in task list described in asynchronous allocationBusiness;
Balanced deployment module, for disposing the task after asynchronous allocation by load-balanced server equilibrium to describedEach node in application server cluster is executed.
Specifically, middleware and deployment architecture that the distributed task dispatching system in the embodiment of the present invention uses are as schemedShown in 3, wherein the application server for being responsible for processing business logic includes but is not limited to the Jboss in legend, other similar functionWeb container be also able to satisfy demand, such as Tomcat etc..The machine quantity of Jboss cluster is determined by actual portfolio, needsMeet the service logic that all operations can have been handled in the timed task period.Distributed type assemblies dispatch coordination service usesZookeeper cluster provides the Master node election service of application server cluster, while also solving cluster timed taskDistributed lock the problem of.In addition, Zookeeper cluster equally plays storage job configuration information and monitors the note of operationVolume center role.Load-balanced server uses Nginx, by each sub- section for being distributed to jboss cluster of all task balancesPoint processing, the i.e. node of load-balanced server are responsible for the load balancing of application server cluster.It is equal that load can equally be set upWeigh server cluster, realizes High Availabitity using the mode of VIP+Nginx cluster.What needs to be explained here is that the embodiment of the present inventionIn, center can also be submitted by one task registration of setting to carry out the registration of task, update, the operation such as deletion.
As a kind of preferably embodiment, in the embodiment of the present invention, the task allocating module includes:
Sub thread encapsulation unit, for being lost after being packaged the task in the task list as sub thread into describedIt is executed in thread pool.
As a kind of preferably embodiment, in the embodiment of the present invention, the task allocating module further include:
Encapsulation unit is requested, the service logic of the task is packaged into http request for the sub thread and is sent to instituteState load-balanced server.
As a kind of preferably embodiment, in the embodiment of the present invention, the system also includes:
Catalogue update module obtains in real time for monitoring the relevant operation in the specified task list of the ZookeeperThe more new content of task, and update the task list.
As a kind of preferably embodiment, in the embodiment of the present invention, the system also includes:
Module is re-elected, collection of the Zookeeper in the application server when the Master node delay machine is used forNew Master node is re-elected out in group executes relevant operation.
As a kind of preferably embodiment, in the embodiment of the present invention, the system also includes:
Scalable molar block, for increasing or decreasing the application server by redeploying the application server realizingCluster in node quantity.
In conclusion technical solution provided in an embodiment of the present invention has the benefit that
1, the dispatching method and system of distributed task scheduling provided in an embodiment of the present invention solves and appoints including monitoring operation etc.In scheduling process of being engaged in, the distributed lock and cluster multinode principal and subordinate's election issues of multi-node cluster timed task, and be not limited toThe business processing scene of processing monitoring operation, is equally applicable to other task schedule scenes without dependence operation;
2, the dispatching method and system of distributed task scheduling provided in an embodiment of the present invention is based on Zookeeper frame natureReasonable utilization, realize the flexible configuration of task, registration, cancellation, alarm content item, alarm threshold value comprising task and appointThe functions such as the real-time dynamic adjustment for dispatching cycle of being engaged in;
3, the dispatching method and system of distributed task scheduling provided in an embodiment of the present invention realizes point of real-time calculating taskThe scheme of cloth business scenario, the overall situation are designed using HA High Availabitity characteristic, for the growth for monitoring the business scales such as operation or are subtractedIt is few, dynamic may be implemented and do not shut down scalable appearance.
It should be understood that the scheduling system of distributed task scheduling provided by the above embodiment is in triggering task schedule businessWhen, only the example of the division of the above functional modules, in practical application, it can according to need and divide above-mentioned functionWith being completed by different functional modules, i.e., the internal structure of system is divided into different functional modules, to complete above descriptionAll or part of function.In addition, the scheduling system of distributed task scheduling provided by the above embodiment and the tune of distributed task schedulingDegree embodiment of the method belongs to same design, i.e. the system is the dispatching method based on the distributed task scheduling, is implementedJourney is detailed in embodiment of the method, and which is not described herein again.
The foregoing is merely presently preferred embodiments of the present invention, is not intended to limit the invention, it is all in spirit of the invention andWithin principle, any modification, equivalent replacement, improvement and so on be should all be included in the protection scope of the present invention.