node-cron icon indicating copy to clipboard operation
node-cron copied to clipboard

Drowning...

Open bosgeluk opened this issue 12 years ago • 3 comments

Actually this is not a question I think but more a remark. I was curious what kind of behavior to except when I drown node-cron in to much work. I created a job with an interval of 1 second and in the job I incremented an int via redis (loop with 100k increments).

I measured that on my computer every three seconds the cron job actually starts (and finishes). So I think (this is a question ;-) ) node-cron drops job requests when it is to busy (which is off-course fine and totally OK).

Am I right?

bosgeluk avatar Jan 03 '14 20:01 bosgeluk

So- in theory, this could happen but I'd need to see the example code to rule out any issues there first. :)

The way I can see this happening is if the event loop (node's) backs up enough that setTimeout calls are delayed. Does that make sense?

ncb000gt avatar Jan 04 '14 00:01 ncb000gt

Hi Nick,

Thanks for taking interest, I've extracted the code, see below. The oops of a 100k results in keys at approx a 3 second interval [on my notebook].

keys '*'

  1. "test.17:23"
  2. "test.17:29"
  3. "test.17:26"

I don't think the setTimeout calls are actually delayed, they are 'skipped'. But it must be said that I'm still at an early stage of understanding Node - or better said the full impact of async programming.

var cronJob = require('cron').CronJob; var redis = require("redis"), client = redis.createClient();

(function main() { new cronJob('*/1 * * * * *', function () {

    console.log('.');

    var date = new Date();
    var key = 'test.' + date.getMinutes().toString() + ':' + date.getSeconds().toString();
    client.setnx(key, 1);

    var oops = 100000;
    for (var i = 0; i < oops; i++) {
        client.incr(key);
    }
}, null, true);

})();

bosgeluk avatar Jan 04 '14 12:01 bosgeluk

Yea, when I said delayed I meant skipping in that the start happens whenever the setTimeout call is fired. If the processing in the event loop is taking too long (for blocking or other reasons) then it would make sense that it would skip the next call to setTimeout, depending on when that call should be made.

ncb000gt avatar Jan 23 '14 14:01 ncb000gt