mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-27 02:44:18 +00:00
69760b4d05
Summary: Have a global StatsDumpScheduler for all DB instance stats dumping, including `DumpStats()` and `PersistStats()`. Before this, there're 2 dedicate threads for every DB instance, one for DumpStats() one for PersistStats(), which could create lots of threads if there're hundreds DB instances. Pull Request resolved: https://github.com/facebook/rocksdb/pull/7223 Reviewed By: riversand963 Differential Revision: D23056737 Pulled By: jay-zhuang fbshipit-source-id: 0faa2311142a73433ebb3317361db7cbf43faeba
65 lines
2 KiB
C++
65 lines
2 KiB
C++
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
|
|
#pragma once
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
#include "db/db_impl/db_impl.h"
|
|
#include "util/timer.h"
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
|
|
// StatsDumpScheduler is a singleton object, which is scheduling/running
|
|
// DumpStats() and PersistStats() for all DB instances. All DB instances uses
|
|
// the same object from `Default()`.
|
|
// Internally, it uses a single threaded timer object to run the stats dump
|
|
// functions. Timer thread won't be started if there's no function needs to run,
|
|
// for example, option.stats_dump_period_sec and option.stats_persist_period_sec
|
|
// are set to 0.
|
|
class StatsDumpScheduler {
|
|
public:
|
|
static StatsDumpScheduler* Default();
|
|
|
|
StatsDumpScheduler() = delete;
|
|
StatsDumpScheduler(const StatsDumpScheduler&) = delete;
|
|
StatsDumpScheduler(StatsDumpScheduler&&) = delete;
|
|
StatsDumpScheduler& operator=(const StatsDumpScheduler&) = delete;
|
|
StatsDumpScheduler& operator=(StatsDumpScheduler&&) = delete;
|
|
|
|
void Register(DBImpl* dbi, unsigned int stats_dump_period_sec,
|
|
unsigned int stats_persist_period_sec);
|
|
|
|
void Unregister(DBImpl* dbi);
|
|
|
|
protected:
|
|
std::unique_ptr<Timer> timer;
|
|
|
|
explicit StatsDumpScheduler(Env* env);
|
|
|
|
private:
|
|
std::string GetTaskName(DBImpl* dbi, const std::string& func_name);
|
|
};
|
|
|
|
#ifndef NDEBUG
|
|
// StatsDumpTestScheduler is for unittest, which can specify the Env like
|
|
// SafeMockTimeEnv. It also contains functions for unittest.
|
|
class StatsDumpTestScheduler : public StatsDumpScheduler {
|
|
public:
|
|
static StatsDumpTestScheduler* Default(Env* env);
|
|
|
|
void TEST_WaitForRun(std::function<void()> callback) const;
|
|
|
|
size_t TEST_GetValidTaskNum() const;
|
|
|
|
private:
|
|
explicit StatsDumpTestScheduler(Env* env);
|
|
};
|
|
#endif // !NDEBUG
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
|
|
|
#endif // ROCKSDB_LITE
|