Update:
I just ran a simple script that prints new Date()
with an interval of 1s.
setInterval(function(){
console.log(new Date());
},1000)
After about 5-6 mins, it had skipped 1 second.
So looks like this might be because of how setInterval
works internally.
Original Post:
Please note that I do not have a source code to simulate this, as my code original code contains huge amount of network and filesystem operations that I cannot put here.
I am setting multiple (500) setIntervals of 60 seconds. Each interval is set after approx 50 ms from each other
for(let i=1;i<500;i++){
delayStart(i)
}
function delayStart(index){
setTimeout(start,index*50)
}
function start(){
setInterval(myOperations,60*1000)
}
myOperations
consist of some TCP calls, synchronous file reads and asynchronous file writes.
All of these operations are completed within 35 seconds, and the script is idle after that. As the event loop is not filled, I don't see a reason why the interval execution will get delayed.
My logs suggest that there is increase in the time when this starts.
The first execution started on the 10th second.
After 7 mins: 11th second
After 22 mins: 12th second
After 57 mins: 15th second
After 71 mins: 19th second
There was an increase of 9 seconds in 71 mins.
I know that might not seem a lot, but the operations I'm doing need to be done every minute.
Yes, I have thought of using database, and cron job. But I don't understand why this is causing the issue.