From e62e367ed324205f2c989adc13fbf048914ff3aa Mon Sep 17 00:00:00 2001 From: John Sully Date: Fri, 10 Sep 2021 00:38:08 +0000 Subject: [PATCH] In single thread mode don't batch Former-commit-id: 7daadae789cdca6f0eb0c3f553737d4f8efc0566 --- src/networking.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/networking.cpp b/src/networking.cpp index e2e033be3..d8b3e9a5d 100644 --- a/src/networking.cpp +++ b/src/networking.cpp @@ -2547,7 +2547,7 @@ void parseClientCommandBuffer(client *c) { } /* Prefetch outside the lock for better perf */ - if (g_pserver->prefetch_enabled && cqueriesStart < c->vecqueuedcmd.size() && + if (g_pserver->prefetch_enabled && cserver.cthreads > 1 && cqueriesStart < c->vecqueuedcmd.size() && (g_pserver->m_pstorageFactory || aeLockContested(cserver.cthreads/2) || cserver.cthreads == 1) && !GlobalLocksAcquired()) { auto &query = c->vecqueuedcmd.back(); if (query.argc > 0 && query.argc == query.argcMax) { @@ -2622,7 +2622,7 @@ void readQueryFromClient(connection *conn) { int nread, readlen; size_t qblen; - serverAssertDebug(FCorrectThread(c) sdfsdf); + serverAssertDebug(FCorrectThread(c)); serverAssertDebug(!GlobalLocksAcquired()); AeLocker aelock; @@ -2694,9 +2694,16 @@ void readQueryFromClient(connection *conn) { return; } - parseClientCommandBuffer(c); - - serverTL->vecclientsProcess.push_back(c); + if (cserver.cthreads > 1) { + parseClientCommandBuffer(c); + serverTL->vecclientsProcess.push_back(c); + } else { + // If we're single threaded its actually better to just process the command here while the query is hot in the cache + // multithreaded lock contention dominates and batching is better + aeAcquireLock(); + runAndPropogateToReplicas(processInputBuffer, c, true /*fParse*/, CMD_CALL_FULL); + aeReleaseLock(); + } } void processClients()