Merge pull request #8164 from sfc-gh-satherton/read-latency-logging-improvements

Add sampling class tests to FlowBench and remove redundant tests from Redwood
This commit is contained in:
Steve Atherton 2022-09-12 18:05:22 -07:00 committed by GitHub
commit a2e74af900
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 149 additions and 83 deletions

View File

@ -11117,92 +11117,26 @@ TEST_CASE(":/redwood/performance/randomRangeScans") {
return Void();
}
TEST_CASE(":/redwood/performance/histogramThroughput") {
std::default_random_engine generator;
std::uniform_int_distribution<uint32_t> distribution(0, UINT32_MAX);
state size_t inputSize = pow(10, 8);
state std::vector<uint32_t> uniform;
for (int i = 0; i < inputSize; i++) {
uniform.push_back(distribution(generator));
TEST_CASE(":/redwood/performance/histograms") {
// Time needed to log 33 histograms.
std::vector<Reference<Histogram>> histograms;
for (int i = 0; i < 33; i++) {
std::string levelString = "L" + std::to_string(i);
histograms.push_back(Histogram::getHistogram(
LiteralStringRef("histogramTest"), LiteralStringRef("levelString"), Histogram::Unit::bytes));
}
std::cout << "size of input: " << uniform.size() << std::endl;
{
// Time needed to log 33 histograms.
std::vector<Reference<Histogram>> histograms;
for (int i = 0; i < 33; i++) {
std::string levelString = "L" + std::to_string(i);
histograms.push_back(Histogram::getHistogram(
LiteralStringRef("histogramTest"), LiteralStringRef("levelString"), Histogram::Unit::bytes));
for (int i = 0; i < 33; i++) {
for (int j = 0; j < 32; j++) {
histograms[i]->sample(std::pow(2, j));
}
for (int i = 0; i < 33; i++) {
for (int j = 0; j < 32; j++) {
histograms[i]->sample(std::pow(2, j));
}
}
auto t_start = std::chrono::high_resolution_clock::now();
for (int i = 0; i < 33; i++) {
histograms[i]->writeToLog(30.0);
}
auto t_end = std::chrono::high_resolution_clock::now();
double elapsed_time_ms = std::chrono::duration<double, std::milli>(t_end - t_start).count();
std::cout << "Time needed to log 33 histograms (millisecond): " << elapsed_time_ms << std::endl;
}
{
std::cout << "Histogram Unit bytes" << std::endl;
auto t_start = std::chrono::high_resolution_clock::now();
Reference<Histogram> h = Histogram::getHistogram(
LiteralStringRef("histogramTest"), LiteralStringRef("counts"), Histogram::Unit::bytes);
ASSERT(uniform.size() == inputSize);
for (size_t i = 0; i < uniform.size(); i++) {
h->sample(uniform[i]);
}
auto t_end = std::chrono::high_resolution_clock::now();
std::cout << h->drawHistogram();
double elapsed_time_ms = std::chrono::duration<double, std::milli>(t_end - t_start).count();
std::cout << "Time in millisecond: " << elapsed_time_ms << std::endl;
auto t_start = std::chrono::high_resolution_clock::now();
for (int i = 0; i < 33; i++) {
histograms[i]->writeToLog(30.0);
}
auto t_end = std::chrono::high_resolution_clock::now();
double elapsed_time_ms = std::chrono::duration<double, std::milli>(t_end - t_start).count();
std::cout << "Time needed to log 33 histograms (millisecond): " << elapsed_time_ms << std::endl;
Reference<Histogram> hCopy = Histogram::getHistogram(
LiteralStringRef("histogramTest"), LiteralStringRef("counts"), Histogram::Unit::bytes);
std::cout << hCopy->drawHistogram();
GetHistogramRegistry().logReport();
}
{
std::cout << "Histogram Unit percentage: " << std::endl;
auto t_start = std::chrono::high_resolution_clock::now();
Reference<Histogram> h = Histogram::getHistogram(
LiteralStringRef("histogramTest"), LiteralStringRef("counts"), Histogram::Unit::percentageLinear);
ASSERT(uniform.size() == inputSize);
for (size_t i = 0; i < uniform.size(); i++) {
h->samplePercentage((double)uniform[i] / UINT32_MAX);
}
auto t_end = std::chrono::high_resolution_clock::now();
std::cout << h->drawHistogram();
GetHistogramRegistry().logReport();
double elapsed_time_ms = std::chrono::duration<double, std::milli>(t_end - t_start).count();
std::cout << "Time in millisecond: " << elapsed_time_ms << std::endl;
}
return Void();
}
TEST_CASE(":/redwood/performance/continuousSmapleThroughput") {
std::default_random_engine generator;
std::uniform_int_distribution<uint32_t> distribution(0, UINT32_MAX);
state size_t inputSize = pow(10, 8);
state std::vector<uint32_t> uniform;
for (int i = 0; i < inputSize; i++) {
uniform.push_back(distribution(generator));
}
{
ContinuousSample<uint32_t> s = ContinuousSample<uint32_t>(pow(10, 3));
auto t_start = std::chrono::high_resolution_clock::now();
ASSERT(uniform.size() == inputSize);
for (size_t i = 0; i < uniform.size(); i++) {
s.addSample(uniform[i]);
}
auto t_end = std::chrono::high_resolution_clock::now();
double elapsed_time_ms = std::chrono::duration<double, std::milli>(t_end - t_start).count();
std::cout << "size of input: " << uniform.size() << std::endl;
std::cout << "Time in millisecond: " << elapsed_time_ms << std::endl;
}
return Void();
}

104
flowbench/BenchSamples.cpp Normal file
View File

@ -0,0 +1,104 @@
/*
* BenchSamples.cpp
*
* This source file is part of the FoundationDB open source project
*
* Copyright 2013-2022 Apple Inc. and the FoundationDB project authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "benchmark/benchmark.h"
#include "flow/IRandom.h"
#include "flowbench/GlobalData.h"
#include "fdbrpc/Stats.h"
#include "flow/Histogram.h"
static void bench_continuousSampleInt(benchmark::State& state) {
ContinuousSample<int64_t> cs(state.range(0));
InputGenerator<int64_t> data(1e6, []() { return deterministicRandom()->randomInt64(0, 1e9); });
for (auto _ : state) {
cs.addSample(data.next());
}
state.SetItemsProcessed(state.iterations());
}
BENCHMARK(bench_continuousSampleInt)->Arg(1000)->Arg(10000)->ReportAggregatesOnly(true);
static void bench_continuousSampleLatency(benchmark::State& state) {
ContinuousSample<double> cs(state.range(0));
InputGenerator<double> data(1e6, []() { return deterministicRandom()->random01() * 2.0; });
for (auto _ : state) {
cs.addSample(data.next());
}
state.SetItemsProcessed(state.iterations());
}
BENCHMARK(bench_continuousSampleLatency)->Arg(1000)->Arg(10000)->ReportAggregatesOnly(true);
static void bench_latencyBands(benchmark::State& state) {
constexpr double max = 2.0;
InputGenerator<double> data(1e6, []() { return deterministicRandom()->random01() * max; });
LatencyBands lb("test", UID(), 5);
for (int i = 0; i < state.range(0); ++i) {
lb.addThreshold(max * (double)(i + 1) / (state.range(0) + 1));
}
for (auto _ : state) {
lb.addMeasurement(data.next(), false);
}
state.SetItemsProcessed(state.iterations());
}
BENCHMARK(bench_latencyBands)->Arg(1)->Arg(4)->Arg(7)->Arg(10)->ReportAggregatesOnly(true);
static void bench_histogramInt(benchmark::State& state) {
Reference<Histogram> h =
Histogram::getHistogram(LiteralStringRef("histogramTest"), LiteralStringRef("bytes"), Histogram::Unit::bytes);
InputGenerator<int32_t> data(1e6, []() { return deterministicRandom()->randomInt64(0, 1e9); });
for (auto _ : state) {
h->sample(data.next());
}
state.SetItemsProcessed(state.iterations());
}
BENCHMARK(bench_histogramInt)->ReportAggregatesOnly(true);
static void bench_histogramPct(benchmark::State& state) {
Reference<Histogram> h = Histogram::getHistogram(
LiteralStringRef("histogramTest"), LiteralStringRef("pct"), Histogram::Unit::percentageLinear);
InputGenerator<double> data(1e6, []() { return deterministicRandom()->random01() * 1.5; });
for (auto _ : state) {
h->samplePercentage(data.next());
}
state.SetItemsProcessed(state.iterations());
}
BENCHMARK(bench_histogramPct)->ReportAggregatesOnly(true);
static void bench_histogramTime(benchmark::State& state) {
Reference<Histogram> h = Histogram::getHistogram(
LiteralStringRef("histogramTest"), LiteralStringRef("latency"), Histogram::Unit::microseconds);
InputGenerator<double> data(1e6, []() { return deterministicRandom()->random01() * 5; });
for (auto _ : state) {
h->sampleSeconds(data.next());
}
state.SetItemsProcessed(state.iterations());
}
BENCHMARK(bench_histogramTime)->ReportAggregatesOnly(true);

View File

@ -28,4 +28,32 @@
KeyValueRef getKV(size_t keySize, size_t valueSize);
KeyRef getKey(size_t keySize);
// Pre-generate a vector of T using a lambda then return them
// via next() one by one with wrap-around
template <typename T>
struct InputGenerator {
InputGenerator() {}
template <typename Fn>
InputGenerator(int n, Fn genFunc) {
ASSERT(n > 0);
data.reserve(n);
for (int i = 0; i < n; ++i) {
data.push_back(genFunc());
}
lastIndex = -1;
}
const T& next() {
if (++lastIndex == data.size()) {
lastIndex = 0;
}
return data[lastIndex];
}
std::vector<T> data;
int lastIndex;
};
#endif