Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stats RPC to print out rocksdb memory stats #2852

Merged
merged 3 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions nano/node/json_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3698,6 +3698,10 @@ void nano::json_handler::stats ()
node.stats.log_samples (*sink);
use_sink = true;
}
else if (type == "rocksdb")
{
node.store.serialize_memory_stats (response_l);
}
else
{
ec = nano::error_rpc::invalid_missing_type;
Expand Down
49 changes: 49 additions & 0 deletions nano/node/rocksdb/rocksdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <boost/endian/conversion.hpp>
#include <boost/format.hpp>
#include <boost/polymorphic_cast.hpp>
#include <boost/property_tree/ptree.hpp>

#include <rocksdb/merge_operator.h>
#include <rocksdb/slice.h>
Expand Down Expand Up @@ -619,5 +620,53 @@ bool nano::rocksdb_store::init_error () const
{
return error;
}

void nano::rocksdb_store::serialize_memory_stats (boost::property_tree::ptree & json)
{
uint64_t val;

// Approximate size of active and unflushed immutable memtables (bytes).
db->GetAggregatedIntProperty (rocksdb::DB::Properties::kCurSizeAllMemTables, &val);
json.put ("cur-size-all-mem-tables", val);

// Approximate size of active, unflushed immutable, and pinned immutable memtables (bytes).
db->GetAggregatedIntProperty (rocksdb::DB::Properties::kSizeAllMemTables, &val);
json.put ("size-all-mem-tables", val);

// Estimated memory used for reading SST tables, excluding memory used in block cache (e.g. filter and index blocks).
db->GetAggregatedIntProperty (rocksdb::DB::Properties::kEstimateTableReadersMem, &val);
json.put ("estimate-table-readers-mem", val);

// An estimate of the amount of live data in bytes.
db->GetAggregatedIntProperty (rocksdb::DB::Properties::kEstimateLiveDataSize, &val);
json.put ("estimate-live-data-size", val);

// Returns 1 if at least one compaction is pending; otherwise, returns 0.
db->GetAggregatedIntProperty (rocksdb::DB::Properties::kCompactionPending, &val);
json.put ("compaction-pending", val);

// Estimated number of total keys in the active and unflushed immutable memtables and storage.
db->GetAggregatedIntProperty (rocksdb::DB::Properties::kEstimateNumKeys, &val);
json.put ("estimate-num-keys", val);

// Estimated total number of bytes compaction needs to rewrite to get all levels down
// to under target size. Not valid for other compactions than level-based.
db->GetAggregatedIntProperty (rocksdb::DB::Properties::kEstimatePendingCompactionBytes, &val);
json.put ("estimate-pending-compaction-bytes", val);

// Total size (bytes) of all SST files.
// WARNING: may slow down online queries if there are too many files.
db->GetAggregatedIntProperty (rocksdb::DB::Properties::kTotalSstFilesSize, &val);
json.put ("total-sst-files-size", val);

// Block cache capacity.
db->GetAggregatedIntProperty (rocksdb::DB::Properties::kBlockCacheCapacity, &val);
json.put ("block-cache-capacity", val);

// Memory size for the entries residing in block cache.
db->GetAggregatedIntProperty (rocksdb::DB::Properties::kBlockCacheUsage, &val);
json.put ("block-cache-usage", val);
}

// Explicitly instantiate
template class nano::block_store_partial<rocksdb::Slice, nano::rocksdb_store>;
5 changes: 1 addition & 4 deletions nano/node/rocksdb/rocksdb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ class rocksdb_store : public block_store_partial<rocksdb::Slice, rocksdb_store>
int put (nano::write_transaction const & transaction_a, tables table_a, nano::rocksdb_val const & key_a, nano::rocksdb_val const & value_a);
int del (nano::write_transaction const & transaction_a, tables table_a, nano::rocksdb_val const & key_a);

void serialize_mdb_tracker (boost::property_tree::ptree &, std::chrono::milliseconds, std::chrono::milliseconds) override
{
// Do nothing
}
void serialize_memory_stats (boost::property_tree::ptree &) override;

std::shared_ptr<nano::block> block_get_v14 (nano::transaction const &, nano::block_hash const &, nano::block_sideband_v14 * = nullptr, bool * = nullptr) const override
{
Expand Down
27 changes: 23 additions & 4 deletions nano/rpc_test/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6679,11 +6679,30 @@ TEST (rpc, memory_stats)
boost::property_tree::ptree request;
request.put ("action", "stats");
request.put ("type", "objects");
test_response response (request, rpc.config.port, system.io_ctx);
ASSERT_TIMELY (5s, response.status != 0);
ASSERT_EQ (200, response.status);
{
test_response response (request, rpc.config.port, system.io_ctx);
ASSERT_TIMELY (5s, response.status != 0);
ASSERT_EQ (200, response.status);

ASSERT_EQ (response.json.get_child ("node").get_child ("vote_uniquer").get_child ("votes").get<std::string> ("count"), "1");
ASSERT_EQ (response.json.get_child ("node").get_child ("vote_uniquer").get_child ("votes").get<std::string> ("count"), "1");
}

request.put ("type", "rocksdb");
{
test_response response (request, rpc.config.port, system.io_ctx);
ASSERT_TIMELY (5s, response.status != 0);
ASSERT_EQ (200, response.status);

auto use_rocksdb_str = std::getenv ("TEST_USE_ROCKSDB");
if (use_rocksdb_str && boost::lexical_cast<int> (use_rocksdb_str) == 1)
{
ASSERT_TRUE (!response.json.empty ());
}
else
{
ASSERT_EQ ("Empty response", response.json.get<std::string> ("error"));
}
}
}

TEST (rpc, block_confirmed)
Expand Down
3 changes: 2 additions & 1 deletion nano/secure/blockstore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,8 @@ class block_store
virtual void rebuild_db (nano::write_transaction const & transaction_a) = 0;

/** Not applicable to all sub-classes */
virtual void serialize_mdb_tracker (boost::property_tree::ptree &, std::chrono::milliseconds, std::chrono::milliseconds) = 0;
virtual void serialize_mdb_tracker (boost::property_tree::ptree &, std::chrono::milliseconds, std::chrono::milliseconds){};
virtual void serialize_memory_stats (boost::property_tree::ptree &){};

virtual bool init_error () const = 0;

Expand Down