Skip to content

Commit 2325dc3

Browse files
committed
Speed up I/O processing by processing batches of events
1 parent 9e244ac commit 2325dc3

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

qode/integration/node_integration.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ NodeIntegration::NodeIntegration()
1919
embed_closed_(false) {
2020
}
2121

22+
constexpr uint64_t EVENT_BATCH_TIMEOUT_MS = 8;
23+
constexpr int EVENT_BATCH_SIZE = 64;
24+
2225
NodeIntegration::~NodeIntegration() {
2326
// Quit the embed thread.
2427
embed_closed_ = true;
@@ -76,6 +79,17 @@ void NodeIntegration::ReleaseHandleRef() {
7679
void NodeIntegration::WakeupMainThread() {
7780
PostTask([this] {
7881
this->UvRunOnce();
82+
// ^ This also updates the uv_now() timestamp.
83+
uint64_t start_time_ms = uv_now(uv_loop_);
84+
85+
int loop_count = EVENT_BATCH_SIZE;
86+
uint64_t elapsed_ms = 0;
87+
while (loop_count != 0 && (elapsed_ms < EVENT_BATCH_TIMEOUT_MS)) {
88+
loop_count--;
89+
this->UvRunOnce();
90+
elapsed_ms = uv_now(uv_loop_) - start_time_ms;
91+
}
92+
7993
// Tell the worker thread to continue polling.
8094
uv_sem_post(&this->embed_sem_);
8195
});

0 commit comments

Comments
 (0)