forked from nodejs/node-v0.x-archive
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Block SIGPROF when in the epoll_pwait() system call so the event loop doesn't keep waking up on signal delivery. The clock_gettime() system call that libuv does after EINTR is very expensive on virtualized systems. * Replace sched_yield() with nanosleep() in V8's tick event processor thread. The former only yields the CPU when there is another process scheduled on the same CPU. * Fix a bug in the epoll_pwait() system call wrapper in libuv, see libuv/libuv#4. Refs strongloop/strong-agent#3 and strongloop-internal/scrum-cs#37.
- Loading branch information
1 parent
3a08b7c
commit 24852b5
Showing
3 changed files
with
14 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24852b5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sched_yield to nanosleep change really alters the behaviour of the call.. On a system with load >= nCPU using node clustering, wouldn't this result in a possibly dramatic increase in context switches as the busy processes split their allocated time up across the schedule cycle? Though I suppose that would balance against waiting for the OS to re-schedule the thread...
On second thought, under any sort of load, this would help the node processes get more of their scheduled CPU time by being less polite to the other threads at the same priority.
Of course this is all without actually looking at when/where/why YieldCPU is actually called..
24852b5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's called in cpu-profiler.cc and execution.cc. The call in execution.cc is to implement preemption, a feature that node.js doesn't use and that has been removed in upstream V8.
As you can see, it's basically a busy loop when there are no other processes scheduled on the current CPU. The idea behind this patch is to force the tick processor thread to sleep for the shortest amount of time possible (1 ns, rounded up to whatever granularity the process scheduler has) in order to relax CPU usage.
24852b5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. Wasn't there some noise a while back when Linux changed the behaviour of sched_yield and how you shouldn't use it for busy loops? Been a long time since I paid attention to LKML and friends..
/me googles.. looks like it was a 2.5 change and was over a decade ago now. Wow.