From 782e675072b65c355e17b36e5aa5ff91156dbf0f Mon Sep 17 00:00:00 2001 From: John Sully Date: Wed, 1 Jul 2020 21:59:00 -0400 Subject: [PATCH] Remove unnecessary work from critical path (Latency Fixes) Former-commit-id: 096a90deb7afe489875d3186f3f8f43e41fea329 --- src/server.cpp | 22 +++++++++++++++++++--- src/server.h | 3 +++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/server.cpp b/src/server.cpp index 92e775e2d..ea8aed59b 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2306,6 +2306,7 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) { g_pserver->rdb_bgsave_scheduled = 0; } +<<<<<<< HEAD if (cserver.storage_memory_model == STORAGE_WRITEBACK && g_pserver->m_pstorageFactory) { run_with_period(g_pserver->storage_flush_period) { flushStorageWeak(); @@ -2316,6 +2317,15 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) { g_pserver->db[0]->consolidate_snapshot(); }, true /*HiPri*/); +======= + if (g_pserver->db[0]->FSnapshot()) // BUG only db 0?! + { + g_pserver->asyncworkqueue->AddWorkFunction([]{ + g_pserver->db[0]->consolidate_snapshot(); + }, true /*HiPri*/); + } + +>>>>>>> dd700f1d6... Remove unnecessary work from critical path (Latency Fixes) /* Fire the cron loop modules event. */ RedisModuleCronLoopV1 ei = {REDISMODULE_CRON_LOOP_VERSION,g_pserver->hz}; moduleFireServerEvent(REDISMODULE_EVENT_CRON_LOOP, @@ -2441,7 +2451,7 @@ void beforeSleep(struct aeEventLoop *eventLoop) { static thread_local bool fFirstRun = true; // note: we also copy the DB pointer in case a DB swap is done while the lock is released std::vector vecdb; // note we cache the database pointer in case a dbswap is done while the lock is released - if (cserver.storage_memory_model == STORAGE_WRITETHROUGH) + if (cserver.storage_memory_model == STORAGE_WRITETHROUGH && g_pserver->m_pstorageFactory != nullptr) { if (!fFirstRun) { mstime_t storage_process_latency; @@ -2462,8 +2472,11 @@ void beforeSleep(struct aeEventLoop *eventLoop) { mstime_t commit_latency; latencyStartMonitor(commit_latency); - for (redisDb *db : vecdb) - db->commitChanges(); + if (g_pserver->m_pstorageFactory != nullptr) + { + for (redisDb *db : vecdb) + db->commitChanges(); + } latencyEndMonitor(commit_latency); latencyAddSampleIfNeeded("storage-commit", commit_latency); @@ -4150,6 +4163,7 @@ int processCommand(client *c, int callFlags, AeLocker &locker) { queueMultiCommand(c); addReply(c,shared.queued); } else { +<<<<<<< HEAD #if 0 if (cserver.cthreads >= 2 && !g_fTestMode && g_pserver->m_pstorageFactory == nullptr && listLength(g_pserver->monitors) == 0 && c->cmd->proc == getCommand) { @@ -4157,6 +4171,8 @@ int processCommand(client *c, int callFlags, AeLocker &locker) { return C_OK; } #endif +======= +>>>>>>> dd700f1d6... Remove unnecessary work from critical path (Latency Fixes) locker.arm(c); incrementMvccTstamp(); call(c,callFlags); diff --git a/src/server.h b/src/server.h index 1878bcb44..b96d1bd25 100644 --- a/src/server.h +++ b/src/server.h @@ -1350,6 +1350,8 @@ public: bool removeCachedValue(const char *key); void removeAllCachedValues(); + bool FSnapshot() const { return m_spdbSnapshotHOLDER != nullptr; } + dict_iter find_cached_threadsafe(const char *key) const; protected: @@ -1425,6 +1427,7 @@ public: using redisDbPersistentData::endSnapshotAsync; using redisDbPersistentData::end; using redisDbPersistentData::find_cached_threadsafe; + using redisDbPersistentData::FSnapshot; dict_iter random_cache_threadsafe(bool fPrimaryOnly = false) const;