schedule to run every minute, runs several times a minute when system is moderately busy, others are skipped entirely
See original GitHub issueI made a schedule to run every minute, the system is very busy every 15 minutes. 9:46 duplicating lines up with the increased usage, 9:56 and 9:57 is a quiet time, 10:00 is super busy (like 12 cores 100% busy). It appears to be almost random. I bolded the typical busy times.
2018-10-10 09:46:00:872 2018-10-10 09:46:00:919 2018-10-10 09:46:00:950 2018-10-10 09:47:00:436 2018-10-10 09:47:00:608 2018-10-10 09:48:00:295 2018-10-10 09:49:00:904 2018-10-10 09:50:00:922 2018-10-10 09:51:00:454 2018-10-10 09:52:00:329 2018-10-10 09:53:00:128 2018-10-10 09:54:00:909 2018-10-10 09:55:00:723 2018-10-10 09:56:00:380 2018-10-10 09:56:00:536 2018-10-10 09:56:00:724 2018-10-10 09:57:00:179 2018-10-10 09:57:00:273 2018-10-10 09:58:00:976 2018-10-10 09:59:00:805 2018-10-10 10:00:00:900 2018-10-10 10:01:00:790 2018-10-10 10:02:00:907 2018-10-10 10:03:00:987 2018-10-10 10:04:00:614 2018-10-10 10:05:00:647 2018-10-10 10:06:00:197 2018-10-10 10:06:00:853 2018-10-10 10:06:00:915 2018-10-10 10:07:00:403 2018-10-10 10:07:00:497 2018-10-10 10:07:00:950 2018-10-10 10:08:00:060 2018-10-10 10:08:00:591 2018-10-10 10:09:00:391 2018-10-10 10:09:00:704 2018-10-10 10:10:00:752 2018-10-10 10:11:00:285 2018-10-10 10:11:00:910 2018-10-10 10:12:00:035 2018-10-10 10:12:00:550 2018-10-10 10:13:00:146 2018-10-10 10:13:00:818
This is the same test running every 15 seconds across the same time period. Again i bolded the typical busy times. Both these ran together. (I have around 200 of these running together)
2018-10-10 09:44:45:667 2018-10-10 09:44:45:667 2018-10-10 09:45:01:026 2018-10-10 09:45:15:433 2018-10-10 09:45:30:513 2018-10-10 09:45:30:575 2018-10-10 09:45:30:607 2018-10-10 09:45:45:716 2018-10-10 09:45:45:810 2018-10-10 09:46:00:888 2018-10-10 09:46:00:935 2018-10-10 09:46:15:013 2018-10-10 09:46:15:044 2018-10-10 09:46:15:091 2018-10-10 09:46:30:123 2018-10-10 09:46:30:201 2018-10-10 09:46:30:233 2018-10-10 09:46:45:295 2018-10-10 09:46:45:342 2018-10-10 09:47:00:436 2018-10-10 09:47:00:592 2018-10-10 09:47:15:623 2018-10-10 09:47:15:686 2018-10-10 09:47:15:764 2018-10-10 09:47:30:811 2018-10-10 09:47:30:889 2018-10-10 09:47:45:061 2018-10-10 09:48:00:279 2018-10-10 09:48:15:326 2018-10-10 09:48:15:404 2018-10-10 09:48:30:514 2018-10-10 09:48:45:686 2018-10-10 09:49:00:904 2018-10-10 09:49:15:092 2018-10-10 09:49:30:328 2018-10-10 09:49:45:500 2018-10-10 09:50:00:875 2018-10-10 09:50:15:875 2018-10-10 09:50:15:953 2018-10-10 09:50:15:985 2018-10-10 09:50:30:079 2018-10-10 09:50:45:282 2018-10-10 09:51:00:470 2018-10-10 09:51:15:673 2018-10-10 09:51:30:876 2018-10-10 09:51:45:079 2018-10-10 09:52:00:376 2018-10-10 09:52:15:501 2018-10-10 09:52:15:595 2018-10-10 09:52:30:706 2018-10-10 09:52:45:894 2018-10-10 09:53:00:113 2018-10-10 09:53:15:331 2018-10-10 09:53:30:488 2018-10-10 09:53:45:659 2018-10-10 09:54:00:894 2018-10-10 09:54:15:050 2018-10-10 09:54:15:113 2018-10-10 09:54:30:270 2018-10-10 09:54:45:457 2018-10-10 09:55:00:895 2018-10-10 09:55:15:067 2018-10-10 09:55:15:160 2018-10-10 09:55:15:848 2018-10-10 09:55:30:005 2018-10-10 09:55:30:193 2018-10-10 09:55:30:349 2018-10-10 09:55:45:193 2018-10-10 09:55:45:349 2018-10-10 09:55:45:552 2018-10-10 09:56:00:380 2018-10-10 09:56:00:521 2018-10-10 09:56:00:708 2018-10-10 09:56:15:568 2018-10-10 09:56:15:646 2018-10-10 09:56:15:865 2018-10-10 09:56:30:757 2018-10-10 09:56:30:992 2018-10-10 09:56:45:117 2018-10-10 09:56:45:945 2018-10-10 09:57:00:179 2018-10-10 09:57:00:242 2018-10-10 09:57:15:351 2018-10-10 09:57:15:398 2018-10-10 09:57:30:554 2018-10-10 09:57:45:757 2018-10-10 09:58:00:976 2018-10-10 09:58:15:163 2018-10-10 09:58:30:368 2018-10-10 09:58:45:586 2018-10-10 09:59:00:774 2018-10-10 09:59:15:993 2018-10-10 09:59:30:165 2018-10-10 09:59:45:369 2018-10-10 10:00:00:790 2018-10-10 10:00:15:978 2018-10-10 10:00:31:009 2018-10-10 10:00:45:915 2018-10-10 10:01:00:775 2018-10-10 10:01:00:931 2018-10-10 10:01:15:572 2018-10-10 10:01:30:845 2018-10-10 10:01:45:657 2018-10-10 10:01:46:032 2018-10-10 10:02:00:470 2018-10-10 10:02:15:251 2018-10-10 10:02:16:017 2018-10-10 10:02:30:440 2018-10-10 10:02:45:737 2018-10-10 10:03:00:987 2018-10-10 10:03:15:049 2018-10-10 10:03:15:174 2018-10-10 10:03:30:207 2018-10-10 10:03:30:364 2018-10-10 10:03:45:426 2018-10-10 10:03:45:520 2018-10-10 10:04:00:567 2018-10-10 10:04:00:723 2018-10-10 10:04:15:723 2018-10-10 10:04:15:801 2018-10-10 10:04:15:864 2018-10-10 10:04:30:053 2018-10-10 10:04:30:850 2018-10-10 10:04:30:912 2018-10-10 10:04:45:022 2018-10-10 10:04:45:069 2018-10-10 10:04:45:225 2018-10-10 10:05:00:194 2018-10-10 10:05:00:506 2018-10-10 10:05:15:381 2018-10-10 10:05:15:491 2018-10-10 10:05:15:647 2018-10-10 10:05:30:509 2018-10-10 10:05:30:603 2018-10-10 10:05:30:837 2018-10-10 10:05:45:712 2018-10-10 10:05:45:759 2018-10-10 10:06:00:181 2018-10-10 10:06:00:837 2018-10-10 10:06:00:884 2018-10-10 10:06:15:040 2018-10-10 10:06:15:353 2018-10-10 10:06:15:978 2018-10-10 10:06:30:153 2018-10-10 10:06:30:215 2018-10-10 10:06:30:606 2018-10-10 10:06:45:278 2018-10-10 10:06:45:356 2018-10-10 10:06:45:762 2018-10-10 10:07:00:403 2018-10-10 10:07:00:497 2018-10-10 10:07:00:918 2018-10-10 10:07:15:075 2018-10-10 10:07:15:575 2018-10-10 10:07:15:622 2018-10-10 10:07:30:232 2018-10-10 10:07:30:763 2018-10-10 10:07:45:388 2018-10-10 10:07:45:904 2018-10-10 10:08:00:029 2018-10-10 10:08:00:591 2018-10-10 10:08:15:185 2018-10-10 10:08:15:763 2018-10-10 10:08:30:313 2018-10-10 10:08:30:985 2018-10-10 10:08:45:157 2018-10-10 10:08:45:469 2018-10-10 10:09:00:391 2018-10-10 10:09:00:688 2018-10-10 10:09:15:594 2018-10-10 10:09:15:782 2018-10-10 10:09:15:860 2018-10-10 10:09:30:752 2018-10-10 10:09:30:892 2018-10-10 10:09:30:986 2018-10-10 10:09:45:017 2018-10-10 10:09:45:111 2018-10-10 10:09:45:986 2018-10-10 10:10:00:736 2018-10-10 10:10:15:252 2018-10-10 10:10:15:705 2018-10-10 10:10:30:425 2018-10-10 10:10:30:910 2018-10-10 10:10:45:082 2018-10-10 10:10:45:582 2018-10-10 10:11:00:269 2018-10-10 10:11:00:769 2018-10-10 10:11:15:019 2018-10-10 10:11:15:504 2018-10-10 10:11:30:144 2018-10-10 10:11:30:675 2018-10-10 10:11:45:269 2018-10-10 10:11:45:832 2018-10-10 10:12:00:019 2018-10-10 10:12:00:410 2018-10-10 10:12:15:191 2018-10-10 10:12:15:566 2018-10-10 10:12:30:381 2018-10-10 10:12:30:709 2018-10-10 10:12:45:568 2018-10-10 10:12:45:865 2018-10-10 10:13:00:006 2018-10-10 10:13:00:802 2018-10-10 10:13:15:193 2018-10-10 10:13:15:990 2018-10-10 10:13:30:147 2018-10-10 10:13:30:366 2018-10-10 10:13:45:350 2018-10-10 10:13:45:522 2018-10-10 10:14:00:538 2018-10-10 10:14:00:663
To get around the bug for now, I added this to my callback function.
First a global function to calculate the time
function clock(start) {
if ( !start ) return process.hrtime();
var end = process.hrtime(start);
return Math.round((end[0]*1000) + (end[1]/1000000));
}
Then checking it like this
self.lastRunTime = clock();
self.schedule = cron.schedule(self.time, function () {
const currentTime = clock(self.lastRunTime);
if (currentTime > 1000) {
// ...do task
The plugin code would need to be changed to run the timeout or interval every 10ms, and check this clock function to see how many multiples of 1000ms have passed, and run the schedule at each interval. So if it shows 3000ms has passed since the last run (the system froze doing something), then it needs to call update on 3 dates, backdating as needed so no schedule is missed.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Hello @TDola thanks for getting in touch.
I think this is a complex problem and I don’t now if my english communication skill are enough to really understand your example.
If I understood, as node is single thread, there is no guaranty that the setTimeout will be executed in exactly specified delay.
So, if another part of the system froze, for exemple with blocking i/o, the function passed to setTimeout may be executed with a delay greater then the specified.
The solution for that is check every 10ms if the elapsed time since last run is a multiple of 1000ms and perform force the execution of the missed executions?
So, if the elapsed is 5500 I need execute 5 update:
I’ve understood right?
I finally released a new version, sorry for that.