Monday 25 April 2016

setInterval is causing process.nextTick to take several seconds.

I found that whenever I was trying to query the database it was taking roughly 4 to 5 seconds to get the results. I tracked this down to a process.nextTick call. After spending way too much time trying to figure out why it was causing such a long delay I remembered about a talk I vaguely remember watching several months ago.It involved the Event Loop and how it will wait for events or something along those lines, but it mentioned timers specifically. Once I remembered that I know where my problem came from, a setInterval timer with a 5 second delay. I tested to see when I get the query results back, and I seem to get them back immediately after the timer is called.I know timers are called first, and that nextTick callbacks are processed at the end of the event queue. But why does the nextTick get blocked by the setInterval call when it still needs several seconds to expire?

Submitted April 25, 2016 at 08:09AM by NullField

No comments:

Post a Comment