Skip to content

Commit

Permalink
fix: allow 2 threads for CreateIoCompletionPort on single-core to pre…
Browse files Browse the repository at this point in the history
…vent busy looping (backport: 4-0-x) (#16012)

* allow 2 threads for CreateIoCompletionPort on single-core

* use base::SysInfo::NumberOfProcessors instead of env var

* CHECK that uv_loop_ has not been used before replacing its iocp
  • Loading branch information
trop[bot] authored and Cheng Zhao committed Dec 11, 2018
1 parent 913a433 commit e324fc4
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion atom/common/node_bindings_win.cc
Expand Up @@ -7,11 +7,25 @@
#include <windows.h>

#include "base/logging.h"
#include "base/sys_info.h"

namespace atom {

NodeBindingsWin::NodeBindingsWin(BrowserEnvironment browser_env)
: NodeBindings(browser_env) {}
: NodeBindings(browser_env) {
// on single-core the io comp port NumberOfConcurrentThreads needs to be 2
// to avoid cpu pegging likely caused by a busy loop in PollEvents
if (base::SysInfo::NumberOfProcessors() == 1) {
// the expectation is the uv_loop_ has just been initialized
// which makes iocp replacement safe
CHECK_EQ(0u, uv_loop_->active_handles);
CHECK_EQ(0u, uv_loop_->active_reqs.count);

if (uv_loop_->iocp && uv_loop_->iocp != INVALID_HANDLE_VALUE)
CloseHandle(uv_loop_->iocp);
uv_loop_->iocp = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 2);
}
}

NodeBindingsWin::~NodeBindingsWin() {}

Expand Down

0 comments on commit e324fc4

Please sign in to comment.