From 1b02987b0ca8002384413d3e216c4bf615ea7f2c 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: b1cb230690a584b8bfe7f433fc0ca0320877ebd3 --- src/networking.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/networking.cpp b/src/networking.cpp index 767fe9c2b..eaddab9e7 100644 --- a/src/networking.cpp +++ b/src/networking.cpp @@ -2551,7 +2551,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) { @@ -2624,7 +2624,7 @@ void readQueryFromClient(connection *conn) { int nread, readlen; size_t qblen; - serverAssertDebug(FCorrectThread(c) sdfsdf); + serverAssertDebug(FCorrectThread(c)); serverAssertDebug(!GlobalLocksAcquired()); AeLocker aelock; @@ -2696,9 +2696,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()