0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 00:02:34 +01:00

ircd::db: Enable histogram interface; partial data tally.

This commit is contained in:
Jason Volk 2018-09-25 22:05:29 -07:00
parent e5a96aab93
commit 533d129322
4 changed files with 103 additions and 21 deletions

View file

@ -21,7 +21,7 @@ struct ircd::db::database::stats final
{
database *d;
std::array<uint64_t, rocksdb::TICKER_ENUM_MAX> ticker {{0}};
std::array<rocksdb::HistogramData, rocksdb::HISTOGRAM_ENUM_MAX> histogram {{0.0}};
std::array<struct db::histogram, rocksdb::HISTOGRAM_ENUM_MAX> histogram;
uint64_t getTickerCount(const uint32_t tickerType) const noexcept override;
void recordTick(const uint32_t tickerType, const uint64_t count) noexcept override;

View file

@ -14,9 +14,12 @@
namespace ircd::db
{
// Histogram (per database)
struct histogram;
extern const uint32_t histogram_max;
string_view histogram_id(const uint32_t &id);
uint32_t histogram_id(const string_view &key);
const struct histogram &histogram(const database &, const uint32_t &id);
const struct histogram &histogram(const database &, const string_view &key);
// Ticker (per database)
extern const uint32_t ticker_max;
@ -35,3 +38,17 @@ namespace ircd::db
const rocksdb::IOStatsContext &iostats_current();
std::string string(const rocksdb::IOStatsContext &, const bool &all = false);
}
/// Copy of rocksdb::HistogramData because it is not included here.
struct ircd::db::histogram
{
double median {0};
double pct95 {0};
double pct99 {0};
double avg {0};
double stddev {0};
double max {0};
uint64_t hits {0};
uint64_t time {0};
};

View file

@ -459,20 +459,6 @@ ircd::db::setopt(database &d,
};
}
uint64_t
ircd::db::ticker(const database &d,
const string_view &key)
{
return ticker(d, ticker_id(key));
}
uint64_t
ircd::db::ticker(const database &d,
const uint32_t &id)
{
return d.stats->getTickerCount(id);
}
size_t
ircd::db::bytes(const database &d)
{
@ -1821,6 +1807,24 @@ ircd::db::perf_level()
return rocksdb::GetPerfLevel();
}
//
// ticker
//
uint64_t
ircd::db::ticker(const database &d,
const string_view &key)
{
return ticker(d, ticker_id(key));
}
uint64_t
ircd::db::ticker(const database &d,
const uint32_t &id)
{
return d.stats->getTickerCount(id);
}
uint32_t
ircd::db::ticker_id(const string_view &key)
{
@ -1850,6 +1854,24 @@ ircd::db::ticker_max
rocksdb::TICKER_ENUM_MAX
};
//
// histogram
//
const struct ircd::db::histogram &
ircd::db::histogram(const database &d,
const string_view &key)
{
return histogram(d, histogram_id(key));
}
const struct ircd::db::histogram &
ircd::db::histogram(const database &d,
const uint32_t &id)
{
return d.stats->histogram.at(id);
}
uint32_t
ircd::db::histogram_id(const string_view &key)
{
@ -1919,6 +1941,13 @@ ircd::db::database::stats::measureTime(const uint32_t type,
const uint64_t time)
noexcept
{
auto &data(histogram.at(type));
data.time += time;
data.hits++;
data.max = std::max(data.max, double(time));
data.avg = data.time / static_cast<long double>(data.hits);
}
void
@ -1927,12 +1956,17 @@ ircd::db::database::stats::histogramData(const uint32_t type,
const noexcept
{
assert(data);
const auto &h
{
histogram.at(type)
};
const auto &median(data->median);
const auto &percentile95(data->percentile95);
const auto &percentile88(data->percentile99);
const auto &average(data->average);
const auto &standard_deviation(data->standard_deviation);
data->median = h.median;
data->percentile95 = h.pct95;
data->percentile99 = h.pct99;
data->average = h.avg;
data->standard_deviation = h.stddev;
data->max = h.max;
}
void

View file

@ -1319,7 +1319,38 @@ try
continue;
out << std::left << std::setw(48) << std::setfill('_') << name
<< " " << val
<< " " << val
<< std::endl;
}
for(uint32_t i(0); i < db::histogram_max; ++i)
{
const string_view &name
{
db::histogram_id(i)
};
if(!name)
continue;
const auto &val
{
db::histogram(database, i)
};
if(!(val.max > 0.0) && ticker != "-a")
continue;
out << std::left << std::setw(48) << std::setfill('_') << name
<< std::setfill(' ') << std::right
<< " " << std::setw(9) << val.hits << " hit "
<< " " << std::setw(13) << val.time << " tot "
<< " " << std::setw(12) << uint64_t(val.max) << " max "
<< " " << std::setw(10) << uint64_t(val.median) << " med "
<< " " << std::setw(9) << uint64_t(val.avg) << " avg "
<< " " << std::setw(10) << val.stddev << " dev "
<< " " << std::setw(10) << val.pct95 << " p95 "
<< " " << std::setw(10) << val.pct99 << " p99 "
<< std::endl;
}