quartz的负载均衡

两台机器分别启动quartz设置成集群,配置相同。定义了20秒一次调度和60秒一次调度两个间隔时间调度。

每20秒调度,3009几乎都是3008的两倍。

每60秒调度,几乎都在3008上调度

查看下Quartz Job Scheduling Framework.chm里怎么说

Load Balancing

As part of achieving good scalability, the capability to distribute work across the nodes in the cluster is very important. Spreading out work ensures that each node in the cluster is footing its share of the workload. Imagine if all the work was being given to one node in the cluster while the other nodes remained idle. If this pattern continued, eventually the overworked node would not be able to handle the increased work, and this would result in a failure.

In the best scenario, work is spread evenly across all instances in the cluster. Several different algorithms can be used to distribute the work, including random, round-robin, and weighted round-robin, just to name a few.

Currently, Quartz provides a minimal load-balancing capability using a random algorithm. Each Scheduler instance in the cluster attempts to fire scheduled triggers as fast as the Scheduler permits. The Scheduler instances compete (using database locks) for the right to execute a job by firing its trigger. When a trigger for a job has been fired, no other Scheduler will attempt to fire that particular trigger until the next scheduled firing time. This mechanism works better than you might infer from its simplicity. This is because the Scheduler that is "most busy" will be the one least likely to find the next job to fire. Hence, it's possible to achieve something near to a true balancing of the load.

百度翻译成中文如下:    

目前,Quartz使用随机算法提供最小的负载平衡能力。集群中的每个调度程序实例都试图以调度程序允许的速度触发调度触发器。调度程序实例通过触发某个作业的触发器来争夺(使用数据库锁)执行该作业的权限。当一个作业的触发器被触发时,在下一个预定的触发时间之前,没有其他调度程序会尝试触发该特定触发器。这个机制比你从它的简单性推断的要好。这是因为“最忙”的调度程序最不可能找到要触发的下一个作业。因此,有可能实现接近真正的负载平衡。

说是使用了随机算法实际就是让各调度实例争抢触发Job,性能好的一般会抢的多,原理简单效果还行。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值