Avoid posting unnecessary async tasks

Former-commit-id: 08f63fdfd6c78388bba093ec2edda7d77fc9173e
This commit is contained in:
John Sully 2021-04-07 17:41:20 +00:00
parent 635ddad7fc
commit 571718f774
3 changed files with 21 additions and 8 deletions

View File

@ -49,6 +49,12 @@ public:
m_setepochOutstanding.clear();
}
bool empty() const
{
std::unique_lock<fastlock> lock(m_lock);
return m_vecepochs.empty();
}
void endEpoch(uint64_t epoch, bool fNoFree = false)
{
std::unique_lock<fastlock> lock(m_lock);
@ -109,7 +115,7 @@ public:
}
private:
fastlock m_lock { "Garbage Collector"};
mutable fastlock m_lock { "Garbage Collector"};
std::vector<EpochHolder> m_vecepochs;
std::unordered_set<uint64_t> m_setepochOutstanding;

View File

@ -2441,13 +2441,15 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
ProcessPendingAsyncWrites();
run_with_period(10) {
// Server threads don't free the GC, but if we don't have a
// a bgsave or some other async task then we'll hold onto the
// data for too long
g_pserver->asyncworkqueue->AddWorkFunction([]{
auto epoch = g_pserver->garbageCollector.startEpoch();
g_pserver->garbageCollector.endEpoch(epoch);
});
if (!g_pserver->garbageCollector.empty()) {
// Server threads don't free the GC, but if we don't have a
// a bgsave or some other async task then we'll hold onto the
// data for too long
g_pserver->asyncworkqueue->AddWorkFunction([]{
auto epoch = g_pserver->garbageCollector.startEpoch();
g_pserver->garbageCollector.endEpoch(epoch);
});
}
}
g_pserver->cronloops++;

View File

@ -1852,6 +1852,11 @@ public:
garbageCollectorGeneric.endEpoch(epochGeneric, fNoFree);
}
bool empty()
{
return garbageCollectorGeneric.empty() && garbageCollectorSnapshot.empty();
}
void shutdown()
{
garbageCollectorSnapshot.shutdown();