From eab0c166289a2613450efec5adf0249fed92ede9 Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Thu, 5 Nov 2020 06:20:50 -0500 Subject: [PATCH] fix: revert use of setImmediate to process.nextTick A performance regression was identified in switching the connection pool to using setImmediate instead of process.nextTick for wait queue processing. This patch reverts that change. NODE-2861 --- lib/cmap/connection_pool.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/cmap/connection_pool.js b/lib/cmap/connection_pool.js index a36ee3b613..4500d9a280 100644 --- a/lib/cmap/connection_pool.js +++ b/lib/cmap/connection_pool.js @@ -233,7 +233,7 @@ class ConnectionPool extends EventEmitter { } this[kWaitQueue].push(waitQueueMember); - setImmediate(() => processWaitQueue(this)); + process.nextTick(() => processWaitQueue(this)); } /** @@ -258,7 +258,7 @@ class ConnectionPool extends EventEmitter { destroyConnection(this, connection, reason); } - setImmediate(() => processWaitQueue(this)); + process.nextTick(() => processWaitQueue(this)); } /** @@ -428,7 +428,7 @@ function createConnection(pool, callback) { // otherwise add it to the pool for later acquisition, and try to process the wait queue pool[kConnections].push(connection); - setImmediate(() => processWaitQueue(pool)); + process.nextTick(() => processWaitQueue(pool)); }); } @@ -439,7 +439,7 @@ function destroyConnection(pool, connection, reason) { pool[kPermits]++; // destroy the connection - setImmediate(() => connection.destroy()); + process.nextTick(() => connection.destroy()); } function processWaitQueue(pool) {