[quartznet:4125] Waiting jobs

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[quartznet:4125] Waiting jobs

Олександр Калиняк
Hi!

Under heavy load some jobs can not be executed.
Let me explain on simple example.

I have job which imitate long running computation:

[DisallowConcurrentExecution]
class DummyJob : IJob
{
public void Execute(IJobExecutionContext context)
{
System.Diagnostics.Trace.WriteLine("DummyJob '" + context.JobDetail.Key.Name + "' executed: " + DateTime.Now.ToString("G"));
Thread.Sleep(10000);
}
}

Max threads in ThreadPool equal 1.
I create two instances of job with 5 seconds interval.

var props = new NameValueCollection
{
{ "quartz.threadPool.threadCount", "1" }
};

ISchedulerFactory sf = new StdSchedulerFactory(props);
var scheduler = sf.GetScheduler();
scheduler.Start();

var job1 = JobBuilder.Create<DummyJob>().WithIdentity("job1", "general").Build();
var trigger1 =
    TriggerBuilder.Create()
        .WithIdentity("trigger1", "general")
        .StartNow()
        .WithSimpleSchedule(x => x.WithIntervalInSeconds(5).RepeatForever().WithMisfireHandlingInstructionFireNow())
        .Build();
var job2 = JobBuilder.Create<DummyJob>().WithIdentity("job2", "general").Build();
var trigger2 =
    TriggerBuilder.Create()
        .WithIdentity("trigger2", "general")
        .StartNow()
        .WithSimpleSchedule(x => x.WithIntervalInSeconds(5).RepeatForever().WithMisfireHandlingInstructionFireNow())
        .Build();

scheduler.ScheduleJob(job1, trigger1);
scheduler.ScheduleJob(job2, trigger2);

Thread.Sleep(60000);

scheduler.Shutdown(true);


Here is output:

DummyJob 'job1' executed: 09.06.2017 11:21:13
DummyJob 'job2' executed: 09.06.2017 11:21:23
DummyJob 'job1' executed: 09.06.2017 11:21:33
DummyJob 'job1' executed: 09.06.2017 11:21:43
DummyJob 'job1' executed: 09.06.2017 11:21:53
DummyJob 'job1' executed: 09.06.2017 11:22:03


As we can see, job2 was fired only once. And it has no chance to be executed again after that.
That's wierd. I would like Quartz let every job to be executed.

--
You received this message because you are subscribed to the Google Groups "Quartz.NET" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/quartznet.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

[quartznet:4129] Re: Waiting jobs

Philip Shaffer
I am not sure that your statement that Job2 has no chance to run again is true in theory, but in practice you are probably right.
Remove your [DisallowConcurrentExecution] attribute, and you will probably see more occurrences of Job2.
Alter your inheritance so that Job1 and Job2 are different job classes and you might see more occurrences of both.
But ultimately, your 1 thread job pool is probably an artificial constraint one wouldn't normally see in production except in special situations.
Also, your job scheduling is identical on both jobs (same start time, same interval, same duration, same priority).  So each time the scheduler brings the jobs up for submission to your single-thread thread pool, it has no criteria that differ between the two jobs other than the order in which they were scheduled.  And in that scenario, it always goes with the first one scheduled.  I hit this same situation myself when I started playing with the Quartz engine last week.
Good luck.

On Friday, June 9, 2017 at 8:54:57 AM UTC-4, Олександр Калиняк wrote:
Hi!

Under heavy load some jobs can not be executed.
Let me explain on simple example.

I have job which imitate long running computation:

[DisallowConcurrentExecution]
class DummyJob : IJob
{
public void Execute(IJobExecutionContext context)
{
System.Diagnostics.Trace.WriteLine("DummyJob '" + <a onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fcontext.JobDetail.Key.Name\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFnZzf5kHmMKQvmaNH2QGuTxGAOCQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fcontext.JobDetail.Key.Name\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFnZzf5kHmMKQvmaNH2QGuTxGAOCQ&#39;;return true;" href="http://context.JobDetail.Key.Name" target="_blank" rel="nofollow">context.JobDetail.Key.Name + "' executed: " + DateTime.Now.ToString("G"));
Thread.Sleep(10000);
}
}

Max threads in ThreadPool equal 1.
I create two instances of job with 5 seconds interval.

var props = new NameValueCollection
{
{ "quartz.threadPool.threadCount", "1" }
};

ISchedulerFactory sf = new StdSchedulerFactory(props);
var scheduler = sf.GetScheduler();
scheduler.Start();

var job1 = JobBuilder.Create<DummyJob>().WithIdentity("job1", "general").Build();
var trigger1 =
    TriggerBuilder.Create()
        .WithIdentity("trigger1", "general")
        .StartNow()
        .WithSimpleSchedule(x => x.WithIntervalInSeconds(5).RepeatForever().WithMisfireHandlingInstructionFireNow())
        .Build();
var job2 = JobBuilder.Create<DummyJob>().WithIdentity("job2", "general").Build();
var trigger2 =
    TriggerBuilder.Create()
        .WithIdentity("trigger2", "general")
        .StartNow()
        .WithSimpleSchedule(x => x.WithIntervalInSeconds(5).RepeatForever().WithMisfireHandlingInstructionFireNow())
        .Build();

scheduler.ScheduleJob(job1, trigger1);
scheduler.ScheduleJob(job2, trigger2);

Thread.Sleep(60000);

scheduler.Shutdown(true);


Here is output:

DummyJob 'job1' executed: 09.06.2017 11:21:13
DummyJob 'job2' executed: 09.06.2017 11:21:23
DummyJob 'job1' executed: 09.06.2017 11:21:33
DummyJob 'job1' executed: 09.06.2017 11:21:43
DummyJob 'job1' executed: 09.06.2017 11:21:53
DummyJob 'job1' executed: 09.06.2017 11:22:03


As we can see, job2 was fired only once. And it has no chance to be executed again after that.
That's wierd. I would like Quartz let every job to be executed.

--
You received this message because you are subscribed to the Google Groups "Quartz.NET" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/quartznet.
For more options, visit https://groups.google.com/d/optout.