Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process.nextTick in _SynchronousQueue._scheduleRun blocks event loop #2299

Closed
zol opened this issue Jul 10, 2014 · 2 comments
Closed

process.nextTick in _SynchronousQueue._scheduleRun blocks event loop #2299

zol opened this issue Jul 10, 2014 · 2 comments

Comments

@zol
Copy link
Contributor

zol commented Jul 10, 2014

It appears to have been written to target the pre Node 0.10 behavior of nextTick (intending the processing of the next task to run in the next tick of the event loop). The implementation of process.nextTick changed in Node 0.10 and now schedules the callback for the end of the current tick (behavior is documented here).

This was causing operations coming down from oplog to starve the event queue and causing all of our webservers to stop accepting/servicing connections simultaneously while the event loop was blocking (sometimes up to 1.5 mins).

Changing process.nextTick over to setImmediate fixes the problem and implements the (I think) original intent of the code. We've been running it in production over the last week and observing much better CPU characteristics on our servers (and no event loop starvation).

PR to follow.

@n1mmy
Copy link
Contributor

n1mmy commented Jul 10, 2014

Merged in 591263f. Thanks zol!

@n1mmy n1mmy closed this as completed Jul 10, 2014
@tmeasday
Copy link
Contributor

Who would have thought nextTick was actually never intended to run in the next tick? (my reading of various node channels on this issue is that nextTick was never supposed to be used for the purpose outlined here, and people ending up doing so due to a misunderstanding the intention of nextTick, precipitated by a poor choice of name).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants