2016-02-09 23:12:00 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-15 23:03:42 +00:00
|
|
|
// 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).
|
2013-10-16 21:59:46 +00:00
|
|
|
//
|
2021-01-26 06:07:26 +00:00
|
|
|
#include "rocksdb/perf_context.h"
|
|
|
|
|
2013-09-10 16:35:19 +00:00
|
|
|
#include <algorithm>
|
2013-08-13 06:59:04 +00:00
|
|
|
#include <iostream>
|
2015-10-13 17:41:48 +00:00
|
|
|
#include <thread>
|
[RocksDB] Added nano second stopwatch and new perf counters to track block read cost
Summary: The pupose of this diff is to expose per user-call level precise timing of block read, so that we can answer questions like: a Get() costs me 100ms, is that somehow related to loading blocks from file system, or sth else? We will answer that with EXACTLY how many blocks have been read, how much time was spent on transfering the bytes from os, how much time was spent on checksum verification and how much time was spent on block decompression, just for that one Get. A nano second stopwatch was introduced to track time with higher precision. The cost/precision of the stopwatch is also measured in unit-test. On my dev box, retrieving one time instance costs about 30ns, on average. The deviation of timing results is good enough to track 100ns-1us level events. And the overhead could be safely ignored for 100us level events (10000 instances/s), for example, a viewstate thrift call.
Test Plan: perf_context_test, also testing with viewstate shadow traffic.
Reviewers: dhruba
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D12351
2013-06-04 06:09:15 +00:00
|
|
|
#include <vector>
|
2013-08-13 06:59:04 +00:00
|
|
|
|
2017-04-06 02:02:00 +00:00
|
|
|
#include "monitoring/histogram.h"
|
|
|
|
#include "monitoring/instrumented_mutex.h"
|
2018-10-17 18:18:00 +00:00
|
|
|
#include "monitoring/perf_context_imp.h"
|
2017-04-06 02:02:00 +00:00
|
|
|
#include "monitoring/thread_status_util.h"
|
|
|
|
#include "port/port.h"
|
2013-08-23 15:38:13 +00:00
|
|
|
#include "rocksdb/db.h"
|
2016-03-26 01:29:43 +00:00
|
|
|
#include "rocksdb/memtablerep.h"
|
2014-03-14 20:02:20 +00:00
|
|
|
#include "rocksdb/slice_transform.h"
|
2021-01-26 06:07:26 +00:00
|
|
|
#include "rocksdb/system_clock.h"
|
2019-05-31 00:39:43 +00:00
|
|
|
#include "test_util/testharness.h"
|
[RocksDB] Added nano second stopwatch and new perf counters to track block read cost
Summary: The pupose of this diff is to expose per user-call level precise timing of block read, so that we can answer questions like: a Get() costs me 100ms, is that somehow related to loading blocks from file system, or sth else? We will answer that with EXACTLY how many blocks have been read, how much time was spent on transfering the bytes from os, how much time was spent on checksum verification and how much time was spent on block decompression, just for that one Get. A nano second stopwatch was introduced to track time with higher precision. The cost/precision of the stopwatch is also measured in unit-test. On my dev box, retrieving one time instance costs about 30ns, on average. The deviation of timing results is good enough to track 100ns-1us level events. And the overhead could be safely ignored for 100us level events (10000 instances/s), for example, a viewstate thrift call.
Test Plan: perf_context_test, also testing with viewstate shadow traffic.
Reviewers: dhruba
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D12351
2013-06-04 06:09:15 +00:00
|
|
|
#include "util/stop_watch.h"
|
2016-03-26 01:29:43 +00:00
|
|
|
#include "util/string_util.h"
|
|
|
|
#include "utilities/merge_operators.h"
|
2013-10-02 17:28:25 +00:00
|
|
|
|
2013-09-10 16:35:19 +00:00
|
|
|
bool FLAGS_random_key = false;
|
2013-09-25 21:35:01 +00:00
|
|
|
bool FLAGS_use_set_based_memetable = false;
|
2013-09-10 16:35:19 +00:00
|
|
|
int FLAGS_total_keys = 100;
|
|
|
|
int FLAGS_write_buffer_size = 1000000000;
|
|
|
|
int FLAGS_max_write_buffer_number = 8;
|
|
|
|
int FLAGS_min_write_buffer_number_to_merge = 7;
|
2015-03-30 20:05:35 +00:00
|
|
|
bool FLAGS_verbose = false;
|
2013-08-13 06:59:04 +00:00
|
|
|
|
|
|
|
// Path to the database on file system
|
2020-02-20 20:07:53 +00:00
|
|
|
const std::string kDbName =
|
|
|
|
ROCKSDB_NAMESPACE::test::PerThreadDBPath("perf_context_test");
|
2013-08-13 06:59:04 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2013-09-10 16:35:19 +00:00
|
|
|
|
2014-10-03 00:02:30 +00:00
|
|
|
std::shared_ptr<DB> OpenDb(bool read_only = false) {
|
2013-08-13 06:59:04 +00:00
|
|
|
DB* db;
|
|
|
|
Options options;
|
|
|
|
options.create_if_missing = true;
|
2016-04-21 22:32:06 +00:00
|
|
|
options.max_open_files = -1;
|
2013-09-10 16:35:19 +00:00
|
|
|
options.write_buffer_size = FLAGS_write_buffer_size;
|
|
|
|
options.max_write_buffer_number = FLAGS_max_write_buffer_number;
|
|
|
|
options.min_write_buffer_number_to_merge =
|
|
|
|
FLAGS_min_write_buffer_number_to_merge;
|
2013-09-25 21:35:01 +00:00
|
|
|
|
|
|
|
if (FLAGS_use_set_based_memetable) {
|
2014-11-12 21:05:12 +00:00
|
|
|
#ifndef ROCKSDB_LITE
|
2020-02-20 20:07:53 +00:00
|
|
|
options.prefix_extractor.reset(
|
|
|
|
ROCKSDB_NAMESPACE::NewFixedPrefixTransform(0));
|
2014-10-03 00:02:30 +00:00
|
|
|
options.memtable_factory.reset(NewHashSkipListRepFactory());
|
2014-11-12 21:05:12 +00:00
|
|
|
#endif // ROCKSDB_LITE
|
2013-09-25 21:35:01 +00:00
|
|
|
}
|
|
|
|
|
2014-10-03 00:02:30 +00:00
|
|
|
Status s;
|
|
|
|
if (!read_only) {
|
|
|
|
s = DB::Open(options, kDbName, &db);
|
|
|
|
} else {
|
|
|
|
s = DB::OpenForReadOnly(options, kDbName, &db);
|
|
|
|
}
|
rocksdb: Replace ASSERT* with EXPECT* in functions that does not return void value
Summary:
gtest does not use exceptions to fail a unit test by design, and `ASSERT*`s are implemented using `return`. As a consequence we cannot use `ASSERT*` in a function that does not return `void` value ([[ https://code.google.com/p/googletest/wiki/AdvancedGuide#Assertion_Placement | 1]]), and have to fix our existing code. This diff does this in a generic way, with no manual changes.
In order to detect all existing `ASSERT*` that are used in functions that doesn't return void value, I change the code to generate compile errors for such cases.
In `util/testharness.h` I defined `EXPECT*` assertions, the same way as `ASSERT*`, and redefined `ASSERT*` to return `void`. Then executed:
```lang=bash
% USE_CLANG=1 make all -j55 -k 2> build.log
% perl -naF: -e 'print "-- -number=".$F[1]." ".$F[0]."\n" if /: error:/' \
build.log | xargs -L 1 perl -spi -e 's/ASSERT/EXPECT/g if $. == $number'
% make format
```
After that I reverted back change to `ASSERT*` in `util/testharness.h`. But preserved introduced `EXPECT*`, which is the same as `ASSERT*`. This will be deleted once switched to gtest.
This diff is independent and contains manual changes only in `util/testharness.h`.
Test Plan:
Make sure all tests are passing.
```lang=bash
% USE_CLANG=1 make check
```
Reviewers: igor, lgalanis, sdong, yufei.zhu, rven, meyering
Reviewed By: meyering
Subscribers: dhruba, leveldb
Differential Revision: https://reviews.facebook.net/D33333
2015-03-17 03:52:32 +00:00
|
|
|
EXPECT_OK(s);
|
2013-08-13 06:59:04 +00:00
|
|
|
return std::shared_ptr<DB>(db);
|
|
|
|
}
|
|
|
|
|
2015-03-17 21:08:00 +00:00
|
|
|
class PerfContextTest : public testing::Test {};
|
2013-08-13 06:59:04 +00:00
|
|
|
|
2015-03-17 21:08:00 +00:00
|
|
|
TEST_F(PerfContextTest, SeekIntoDeletion) {
|
2013-10-02 17:28:25 +00:00
|
|
|
DestroyDB(kDbName, Options());
|
|
|
|
auto db = OpenDb();
|
|
|
|
WriteOptions write_options;
|
|
|
|
ReadOptions read_options;
|
|
|
|
|
|
|
|
for (int i = 0; i < FLAGS_total_keys; ++i) {
|
2014-11-25 04:44:49 +00:00
|
|
|
std::string key = "k" + ToString(i);
|
|
|
|
std::string value = "v" + ToString(i);
|
2013-10-02 17:28:25 +00:00
|
|
|
|
2020-12-23 07:44:44 +00:00
|
|
|
ASSERT_OK(db->Put(write_options, key, value));
|
2013-10-02 17:28:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < FLAGS_total_keys -1 ; ++i) {
|
2014-11-25 04:44:49 +00:00
|
|
|
std::string key = "k" + ToString(i);
|
2020-12-23 07:44:44 +00:00
|
|
|
ASSERT_OK(db->Delete(write_options, key));
|
2013-10-02 17:28:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HistogramImpl hist_get;
|
|
|
|
HistogramImpl hist_get_time;
|
|
|
|
for (int i = 0; i < FLAGS_total_keys - 1; ++i) {
|
2014-11-25 04:44:49 +00:00
|
|
|
std::string key = "k" + ToString(i);
|
2013-10-02 17:28:25 +00:00
|
|
|
std::string value;
|
|
|
|
|
2017-06-03 00:12:39 +00:00
|
|
|
get_perf_context()->Reset();
|
2021-01-26 06:07:26 +00:00
|
|
|
StopWatchNano timer(SystemClock::Default());
|
2014-10-03 00:02:30 +00:00
|
|
|
timer.Start();
|
2013-10-02 17:28:25 +00:00
|
|
|
auto status = db->Get(read_options, key, &value);
|
|
|
|
auto elapsed_nanos = timer.ElapsedNanos();
|
|
|
|
ASSERT_TRUE(status.IsNotFound());
|
2017-06-03 00:12:39 +00:00
|
|
|
hist_get.Add(get_perf_context()->user_key_comparison_count);
|
2013-10-02 17:28:25 +00:00
|
|
|
hist_get_time.Add(elapsed_nanos);
|
|
|
|
}
|
|
|
|
|
2015-03-30 20:05:35 +00:00
|
|
|
if (FLAGS_verbose) {
|
|
|
|
std::cout << "Get user key comparison: \n" << hist_get.ToString()
|
|
|
|
<< "Get time: \n" << hist_get_time.ToString();
|
|
|
|
}
|
2013-10-02 17:28:25 +00:00
|
|
|
|
2014-11-07 23:04:30 +00:00
|
|
|
{
|
|
|
|
HistogramImpl hist_seek_to_first;
|
|
|
|
std::unique_ptr<Iterator> iter(db->NewIterator(read_options));
|
2013-10-02 17:28:25 +00:00
|
|
|
|
2017-06-03 00:12:39 +00:00
|
|
|
get_perf_context()->Reset();
|
2021-01-26 06:07:26 +00:00
|
|
|
StopWatchNano timer(SystemClock::Default(), true);
|
2014-11-07 23:04:30 +00:00
|
|
|
iter->SeekToFirst();
|
2017-06-03 00:12:39 +00:00
|
|
|
hist_seek_to_first.Add(get_perf_context()->user_key_comparison_count);
|
2014-11-07 23:04:30 +00:00
|
|
|
auto elapsed_nanos = timer.ElapsedNanos();
|
2013-10-02 17:28:25 +00:00
|
|
|
|
2015-03-30 20:05:35 +00:00
|
|
|
if (FLAGS_verbose) {
|
2020-12-23 07:44:44 +00:00
|
|
|
std::cout << "SeekToFirst user key comparison: \n"
|
|
|
|
<< hist_seek_to_first.ToString() << "ikey skipped: "
|
|
|
|
<< get_perf_context()->internal_key_skipped_count << "\n"
|
2015-03-30 20:05:35 +00:00
|
|
|
<< "idelete skipped: "
|
2017-06-03 00:12:39 +00:00
|
|
|
<< get_perf_context()->internal_delete_skipped_count << "\n"
|
2015-03-30 20:05:35 +00:00
|
|
|
<< "elapsed: " << elapsed_nanos << "\n";
|
|
|
|
}
|
2014-11-07 23:04:30 +00:00
|
|
|
}
|
2013-10-02 17:28:25 +00:00
|
|
|
|
|
|
|
HistogramImpl hist_seek;
|
|
|
|
for (int i = 0; i < FLAGS_total_keys; ++i) {
|
|
|
|
std::unique_ptr<Iterator> iter(db->NewIterator(read_options));
|
2014-11-25 04:44:49 +00:00
|
|
|
std::string key = "k" + ToString(i);
|
2013-10-02 17:28:25 +00:00
|
|
|
|
2017-06-03 00:12:39 +00:00
|
|
|
get_perf_context()->Reset();
|
2021-01-26 06:07:26 +00:00
|
|
|
StopWatchNano timer(SystemClock::Default(), true);
|
2013-10-02 17:28:25 +00:00
|
|
|
iter->Seek(key);
|
|
|
|
auto elapsed_nanos = timer.ElapsedNanos();
|
2017-06-03 00:12:39 +00:00
|
|
|
hist_seek.Add(get_perf_context()->user_key_comparison_count);
|
2015-03-30 20:05:35 +00:00
|
|
|
if (FLAGS_verbose) {
|
2017-06-03 00:12:39 +00:00
|
|
|
std::cout << "seek cmp: " << get_perf_context()->user_key_comparison_count
|
|
|
|
<< " ikey skipped " << get_perf_context()->internal_key_skipped_count
|
2015-03-30 20:05:35 +00:00
|
|
|
<< " idelete skipped "
|
2017-06-03 00:12:39 +00:00
|
|
|
<< get_perf_context()->internal_delete_skipped_count
|
2015-03-30 20:05:35 +00:00
|
|
|
<< " elapsed: " << elapsed_nanos << "ns\n";
|
|
|
|
}
|
2013-10-02 17:28:25 +00:00
|
|
|
|
2017-06-03 00:12:39 +00:00
|
|
|
get_perf_context()->Reset();
|
2013-10-02 17:28:25 +00:00
|
|
|
ASSERT_TRUE(iter->Valid());
|
2021-01-26 06:07:26 +00:00
|
|
|
StopWatchNano timer2(SystemClock::Default(), true);
|
2013-10-02 17:28:25 +00:00
|
|
|
iter->Next();
|
|
|
|
auto elapsed_nanos2 = timer2.ElapsedNanos();
|
2015-03-30 20:05:35 +00:00
|
|
|
if (FLAGS_verbose) {
|
2017-06-03 00:12:39 +00:00
|
|
|
std::cout << "next cmp: " << get_perf_context()->user_key_comparison_count
|
2015-03-30 20:05:35 +00:00
|
|
|
<< "elapsed: " << elapsed_nanos2 << "ns\n";
|
|
|
|
}
|
2013-10-02 17:28:25 +00:00
|
|
|
}
|
|
|
|
|
2015-03-30 20:05:35 +00:00
|
|
|
if (FLAGS_verbose) {
|
2020-12-23 07:44:44 +00:00
|
|
|
std::cout << "Seek user key comparison: \n" << hist_seek.ToString();
|
2015-03-30 20:05:35 +00:00
|
|
|
}
|
2013-10-02 17:28:25 +00:00
|
|
|
}
|
|
|
|
|
2015-03-17 21:08:00 +00:00
|
|
|
TEST_F(PerfContextTest, StopWatchNanoOverhead) {
|
[RocksDB] Added nano second stopwatch and new perf counters to track block read cost
Summary: The pupose of this diff is to expose per user-call level precise timing of block read, so that we can answer questions like: a Get() costs me 100ms, is that somehow related to loading blocks from file system, or sth else? We will answer that with EXACTLY how many blocks have been read, how much time was spent on transfering the bytes from os, how much time was spent on checksum verification and how much time was spent on block decompression, just for that one Get. A nano second stopwatch was introduced to track time with higher precision. The cost/precision of the stopwatch is also measured in unit-test. On my dev box, retrieving one time instance costs about 30ns, on average. The deviation of timing results is good enough to track 100ns-1us level events. And the overhead could be safely ignored for 100us level events (10000 instances/s), for example, a viewstate thrift call.
Test Plan: perf_context_test, also testing with viewstate shadow traffic.
Reviewers: dhruba
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D12351
2013-06-04 06:09:15 +00:00
|
|
|
// profile the timer cost by itself!
|
|
|
|
const int kTotalIterations = 1000000;
|
|
|
|
std::vector<uint64_t> timings(kTotalIterations);
|
|
|
|
|
2021-01-26 06:07:26 +00:00
|
|
|
StopWatchNano timer(SystemClock::Default(), true);
|
[RocksDB] Added nano second stopwatch and new perf counters to track block read cost
Summary: The pupose of this diff is to expose per user-call level precise timing of block read, so that we can answer questions like: a Get() costs me 100ms, is that somehow related to loading blocks from file system, or sth else? We will answer that with EXACTLY how many blocks have been read, how much time was spent on transfering the bytes from os, how much time was spent on checksum verification and how much time was spent on block decompression, just for that one Get. A nano second stopwatch was introduced to track time with higher precision. The cost/precision of the stopwatch is also measured in unit-test. On my dev box, retrieving one time instance costs about 30ns, on average. The deviation of timing results is good enough to track 100ns-1us level events. And the overhead could be safely ignored for 100us level events (10000 instances/s), for example, a viewstate thrift call.
Test Plan: perf_context_test, also testing with viewstate shadow traffic.
Reviewers: dhruba
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D12351
2013-06-04 06:09:15 +00:00
|
|
|
for (auto& timing : timings) {
|
|
|
|
timing = timer.ElapsedNanos(true /* reset */);
|
|
|
|
}
|
|
|
|
|
|
|
|
HistogramImpl histogram;
|
|
|
|
for (const auto timing : timings) {
|
|
|
|
histogram.Add(timing);
|
|
|
|
}
|
|
|
|
|
2015-03-30 20:05:35 +00:00
|
|
|
if (FLAGS_verbose) {
|
|
|
|
std::cout << histogram.ToString();
|
|
|
|
}
|
[RocksDB] Added nano second stopwatch and new perf counters to track block read cost
Summary: The pupose of this diff is to expose per user-call level precise timing of block read, so that we can answer questions like: a Get() costs me 100ms, is that somehow related to loading blocks from file system, or sth else? We will answer that with EXACTLY how many blocks have been read, how much time was spent on transfering the bytes from os, how much time was spent on checksum verification and how much time was spent on block decompression, just for that one Get. A nano second stopwatch was introduced to track time with higher precision. The cost/precision of the stopwatch is also measured in unit-test. On my dev box, retrieving one time instance costs about 30ns, on average. The deviation of timing results is good enough to track 100ns-1us level events. And the overhead could be safely ignored for 100us level events (10000 instances/s), for example, a viewstate thrift call.
Test Plan: perf_context_test, also testing with viewstate shadow traffic.
Reviewers: dhruba
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D12351
2013-06-04 06:09:15 +00:00
|
|
|
}
|
|
|
|
|
2015-03-17 21:08:00 +00:00
|
|
|
TEST_F(PerfContextTest, StopWatchOverhead) {
|
[RocksDB] Added nano second stopwatch and new perf counters to track block read cost
Summary: The pupose of this diff is to expose per user-call level precise timing of block read, so that we can answer questions like: a Get() costs me 100ms, is that somehow related to loading blocks from file system, or sth else? We will answer that with EXACTLY how many blocks have been read, how much time was spent on transfering the bytes from os, how much time was spent on checksum verification and how much time was spent on block decompression, just for that one Get. A nano second stopwatch was introduced to track time with higher precision. The cost/precision of the stopwatch is also measured in unit-test. On my dev box, retrieving one time instance costs about 30ns, on average. The deviation of timing results is good enough to track 100ns-1us level events. And the overhead could be safely ignored for 100us level events (10000 instances/s), for example, a viewstate thrift call.
Test Plan: perf_context_test, also testing with viewstate shadow traffic.
Reviewers: dhruba
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D12351
2013-06-04 06:09:15 +00:00
|
|
|
// profile the timer cost by itself!
|
|
|
|
const int kTotalIterations = 1000000;
|
2014-10-03 00:02:30 +00:00
|
|
|
uint64_t elapsed = 0;
|
[RocksDB] Added nano second stopwatch and new perf counters to track block read cost
Summary: The pupose of this diff is to expose per user-call level precise timing of block read, so that we can answer questions like: a Get() costs me 100ms, is that somehow related to loading blocks from file system, or sth else? We will answer that with EXACTLY how many blocks have been read, how much time was spent on transfering the bytes from os, how much time was spent on checksum verification and how much time was spent on block decompression, just for that one Get. A nano second stopwatch was introduced to track time with higher precision. The cost/precision of the stopwatch is also measured in unit-test. On my dev box, retrieving one time instance costs about 30ns, on average. The deviation of timing results is good enough to track 100ns-1us level events. And the overhead could be safely ignored for 100us level events (10000 instances/s), for example, a viewstate thrift call.
Test Plan: perf_context_test, also testing with viewstate shadow traffic.
Reviewers: dhruba
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D12351
2013-06-04 06:09:15 +00:00
|
|
|
std::vector<uint64_t> timings(kTotalIterations);
|
|
|
|
|
2021-01-26 06:07:26 +00:00
|
|
|
StopWatch timer(SystemClock::Default(), nullptr, 0, &elapsed);
|
[RocksDB] Added nano second stopwatch and new perf counters to track block read cost
Summary: The pupose of this diff is to expose per user-call level precise timing of block read, so that we can answer questions like: a Get() costs me 100ms, is that somehow related to loading blocks from file system, or sth else? We will answer that with EXACTLY how many blocks have been read, how much time was spent on transfering the bytes from os, how much time was spent on checksum verification and how much time was spent on block decompression, just for that one Get. A nano second stopwatch was introduced to track time with higher precision. The cost/precision of the stopwatch is also measured in unit-test. On my dev box, retrieving one time instance costs about 30ns, on average. The deviation of timing results is good enough to track 100ns-1us level events. And the overhead could be safely ignored for 100us level events (10000 instances/s), for example, a viewstate thrift call.
Test Plan: perf_context_test, also testing with viewstate shadow traffic.
Reviewers: dhruba
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D12351
2013-06-04 06:09:15 +00:00
|
|
|
for (auto& timing : timings) {
|
2014-10-03 00:02:30 +00:00
|
|
|
timing = elapsed;
|
[RocksDB] Added nano second stopwatch and new perf counters to track block read cost
Summary: The pupose of this diff is to expose per user-call level precise timing of block read, so that we can answer questions like: a Get() costs me 100ms, is that somehow related to loading blocks from file system, or sth else? We will answer that with EXACTLY how many blocks have been read, how much time was spent on transfering the bytes from os, how much time was spent on checksum verification and how much time was spent on block decompression, just for that one Get. A nano second stopwatch was introduced to track time with higher precision. The cost/precision of the stopwatch is also measured in unit-test. On my dev box, retrieving one time instance costs about 30ns, on average. The deviation of timing results is good enough to track 100ns-1us level events. And the overhead could be safely ignored for 100us level events (10000 instances/s), for example, a viewstate thrift call.
Test Plan: perf_context_test, also testing with viewstate shadow traffic.
Reviewers: dhruba
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D12351
2013-06-04 06:09:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HistogramImpl histogram;
|
|
|
|
uint64_t prev_timing = 0;
|
|
|
|
for (const auto timing : timings) {
|
|
|
|
histogram.Add(timing - prev_timing);
|
|
|
|
prev_timing = timing;
|
|
|
|
}
|
|
|
|
|
2015-03-30 20:05:35 +00:00
|
|
|
if (FLAGS_verbose) {
|
|
|
|
std::cout << histogram.ToString();
|
|
|
|
}
|
[RocksDB] Added nano second stopwatch and new perf counters to track block read cost
Summary: The pupose of this diff is to expose per user-call level precise timing of block read, so that we can answer questions like: a Get() costs me 100ms, is that somehow related to loading blocks from file system, or sth else? We will answer that with EXACTLY how many blocks have been read, how much time was spent on transfering the bytes from os, how much time was spent on checksum verification and how much time was spent on block decompression, just for that one Get. A nano second stopwatch was introduced to track time with higher precision. The cost/precision of the stopwatch is also measured in unit-test. On my dev box, retrieving one time instance costs about 30ns, on average. The deviation of timing results is good enough to track 100ns-1us level events. And the overhead could be safely ignored for 100us level events (10000 instances/s), for example, a viewstate thrift call.
Test Plan: perf_context_test, also testing with viewstate shadow traffic.
Reviewers: dhruba
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D12351
2013-06-04 06:09:15 +00:00
|
|
|
}
|
2013-08-13 06:59:04 +00:00
|
|
|
|
2014-10-03 00:02:30 +00:00
|
|
|
void ProfileQueries(bool enabled_time = false) {
|
2013-08-13 06:59:04 +00:00
|
|
|
DestroyDB(kDbName, Options()); // Start this test with a fresh DB
|
|
|
|
|
2013-09-10 16:35:19 +00:00
|
|
|
auto db = OpenDb();
|
2013-08-13 06:59:04 +00:00
|
|
|
|
|
|
|
WriteOptions write_options;
|
|
|
|
ReadOptions read_options;
|
|
|
|
|
2013-09-25 21:35:01 +00:00
|
|
|
HistogramImpl hist_put;
|
2014-10-03 00:02:30 +00:00
|
|
|
|
2013-09-25 21:35:01 +00:00
|
|
|
HistogramImpl hist_get;
|
2013-11-18 19:32:54 +00:00
|
|
|
HistogramImpl hist_get_snapshot;
|
|
|
|
HistogramImpl hist_get_memtable;
|
2014-10-03 00:02:30 +00:00
|
|
|
HistogramImpl hist_get_files;
|
2013-11-18 19:32:54 +00:00
|
|
|
HistogramImpl hist_get_post_process;
|
|
|
|
HistogramImpl hist_num_memtable_checked;
|
2014-10-03 00:02:30 +00:00
|
|
|
|
|
|
|
HistogramImpl hist_mget;
|
|
|
|
HistogramImpl hist_mget_snapshot;
|
|
|
|
HistogramImpl hist_mget_memtable;
|
|
|
|
HistogramImpl hist_mget_files;
|
|
|
|
HistogramImpl hist_mget_post_process;
|
|
|
|
HistogramImpl hist_mget_num_memtable_checked;
|
|
|
|
|
2013-11-18 19:32:54 +00:00
|
|
|
HistogramImpl hist_write_pre_post;
|
|
|
|
HistogramImpl hist_write_wal_time;
|
|
|
|
HistogramImpl hist_write_memtable_time;
|
2018-04-24 00:53:27 +00:00
|
|
|
HistogramImpl hist_write_delay_time;
|
|
|
|
HistogramImpl hist_write_thread_wait_nanos;
|
|
|
|
HistogramImpl hist_write_scheduling_time;
|
2013-08-13 06:59:04 +00:00
|
|
|
|
2015-02-10 00:12:31 +00:00
|
|
|
uint64_t total_db_mutex_nanos = 0;
|
|
|
|
|
2015-03-30 20:05:35 +00:00
|
|
|
if (FLAGS_verbose) {
|
|
|
|
std::cout << "Inserting " << FLAGS_total_keys << " key/value pairs\n...\n";
|
|
|
|
}
|
2013-08-13 06:59:04 +00:00
|
|
|
|
2013-09-25 21:35:01 +00:00
|
|
|
std::vector<int> keys;
|
2014-10-03 00:02:30 +00:00
|
|
|
const int kFlushFlag = -1;
|
2013-09-10 16:35:19 +00:00
|
|
|
for (int i = 0; i < FLAGS_total_keys; ++i) {
|
2013-09-25 21:35:01 +00:00
|
|
|
keys.push_back(i);
|
2014-10-03 00:02:30 +00:00
|
|
|
if (i == FLAGS_total_keys / 2) {
|
|
|
|
// Issuing a flush in the middle.
|
|
|
|
keys.push_back(kFlushFlag);
|
|
|
|
}
|
2013-09-25 21:35:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (FLAGS_random_key) {
|
2020-04-20 20:21:34 +00:00
|
|
|
RandomShuffle(std::begin(keys), std::end(keys));
|
2013-09-25 21:35:01 +00:00
|
|
|
}
|
2015-02-10 00:12:31 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
ThreadStatusUtil::TEST_SetStateDelay(ThreadStatus::STATE_MUTEX_WAIT, 1U);
|
|
|
|
#endif
|
|
|
|
int num_mutex_waited = 0;
|
2013-09-25 21:35:01 +00:00
|
|
|
for (const int i : keys) {
|
2014-10-03 00:02:30 +00:00
|
|
|
if (i == kFlushFlag) {
|
|
|
|
FlushOptions fo;
|
|
|
|
db->Flush(fo);
|
|
|
|
continue;
|
|
|
|
}
|
2015-02-10 00:12:31 +00:00
|
|
|
|
2014-11-25 04:44:49 +00:00
|
|
|
std::string key = "k" + ToString(i);
|
|
|
|
std::string value = "v" + ToString(i);
|
2013-08-13 06:59:04 +00:00
|
|
|
|
2014-10-03 00:02:30 +00:00
|
|
|
std::vector<std::string> values;
|
|
|
|
|
2017-06-03 00:12:39 +00:00
|
|
|
get_perf_context()->Reset();
|
2020-12-23 07:44:44 +00:00
|
|
|
ASSERT_OK(db->Put(write_options, key, value));
|
2015-02-10 00:12:31 +00:00
|
|
|
if (++num_mutex_waited > 3) {
|
|
|
|
#ifndef NDEBUG
|
|
|
|
ThreadStatusUtil::TEST_SetStateDelay(ThreadStatus::STATE_MUTEX_WAIT, 0U);
|
|
|
|
#endif
|
|
|
|
}
|
2018-04-24 00:53:27 +00:00
|
|
|
hist_write_pre_post.Add(
|
|
|
|
get_perf_context()->write_pre_and_post_process_time);
|
2017-06-03 00:12:39 +00:00
|
|
|
hist_write_wal_time.Add(get_perf_context()->write_wal_time);
|
|
|
|
hist_write_memtable_time.Add(get_perf_context()->write_memtable_time);
|
2018-04-24 00:53:27 +00:00
|
|
|
hist_write_delay_time.Add(get_perf_context()->write_delay_time);
|
|
|
|
hist_write_thread_wait_nanos.Add(
|
|
|
|
get_perf_context()->write_thread_wait_nanos);
|
|
|
|
hist_write_scheduling_time.Add(
|
|
|
|
get_perf_context()->write_scheduling_flushes_compactions_time);
|
2017-06-03 00:12:39 +00:00
|
|
|
hist_put.Add(get_perf_context()->user_key_comparison_count);
|
|
|
|
total_db_mutex_nanos += get_perf_context()->db_mutex_lock_nanos;
|
2014-10-03 00:02:30 +00:00
|
|
|
}
|
2015-02-10 00:12:31 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
ThreadStatusUtil::TEST_SetStateDelay(ThreadStatus::STATE_MUTEX_WAIT, 0U);
|
|
|
|
#endif
|
2014-10-03 00:02:30 +00:00
|
|
|
|
|
|
|
for (const int i : keys) {
|
2016-04-21 22:32:06 +00:00
|
|
|
if (i == kFlushFlag) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-11-25 04:44:49 +00:00
|
|
|
std::string key = "k" + ToString(i);
|
2016-04-21 22:32:06 +00:00
|
|
|
std::string expected_value = "v" + ToString(i);
|
|
|
|
std::string value;
|
2014-10-03 00:02:30 +00:00
|
|
|
|
2014-11-07 23:04:30 +00:00
|
|
|
std::vector<Slice> multiget_keys = {Slice(key)};
|
2014-10-03 00:02:30 +00:00
|
|
|
std::vector<std::string> values;
|
2013-08-13 06:59:04 +00:00
|
|
|
|
2017-06-03 00:12:39 +00:00
|
|
|
get_perf_context()->Reset();
|
2016-04-21 22:32:06 +00:00
|
|
|
ASSERT_OK(db->Get(read_options, key, &value));
|
|
|
|
ASSERT_EQ(expected_value, value);
|
2017-06-03 00:12:39 +00:00
|
|
|
hist_get_snapshot.Add(get_perf_context()->get_snapshot_time);
|
|
|
|
hist_get_memtable.Add(get_perf_context()->get_from_memtable_time);
|
|
|
|
hist_get_files.Add(get_perf_context()->get_from_output_files_time);
|
|
|
|
hist_num_memtable_checked.Add(get_perf_context()->get_from_memtable_count);
|
|
|
|
hist_get_post_process.Add(get_perf_context()->get_post_process_time);
|
|
|
|
hist_get.Add(get_perf_context()->user_key_comparison_count);
|
|
|
|
|
|
|
|
get_perf_context()->Reset();
|
2020-12-23 07:44:44 +00:00
|
|
|
auto statuses = db->MultiGet(read_options, multiget_keys, &values);
|
|
|
|
for (const auto& s : statuses) {
|
|
|
|
ASSERT_OK(s);
|
|
|
|
}
|
2017-06-03 00:12:39 +00:00
|
|
|
hist_mget_snapshot.Add(get_perf_context()->get_snapshot_time);
|
|
|
|
hist_mget_memtable.Add(get_perf_context()->get_from_memtable_time);
|
|
|
|
hist_mget_files.Add(get_perf_context()->get_from_output_files_time);
|
|
|
|
hist_mget_num_memtable_checked.Add(get_perf_context()->get_from_memtable_count);
|
|
|
|
hist_mget_post_process.Add(get_perf_context()->get_post_process_time);
|
|
|
|
hist_mget.Add(get_perf_context()->user_key_comparison_count);
|
2013-08-13 06:59:04 +00:00
|
|
|
}
|
|
|
|
|
2015-03-30 20:05:35 +00:00
|
|
|
if (FLAGS_verbose) {
|
2020-12-23 07:44:44 +00:00
|
|
|
std::cout << "Put user key comparison: \n"
|
|
|
|
<< hist_put.ToString() << "Get user key comparison: \n"
|
|
|
|
<< hist_get.ToString() << "MultiGet user key comparison: \n"
|
|
|
|
<< hist_get.ToString();
|
2015-03-30 20:05:35 +00:00
|
|
|
std::cout << "Put(): Pre and Post Process Time: \n"
|
|
|
|
<< hist_write_pre_post.ToString() << " Writing WAL time: \n"
|
|
|
|
<< hist_write_wal_time.ToString() << "\n"
|
|
|
|
<< " Writing Mem Table time: \n"
|
|
|
|
<< hist_write_memtable_time.ToString() << "\n"
|
2018-04-24 00:53:27 +00:00
|
|
|
<< " Write Delay: \n" << hist_write_delay_time.ToString() << "\n"
|
|
|
|
<< " Waiting for Batch time: \n"
|
|
|
|
<< hist_write_thread_wait_nanos.ToString() << "\n"
|
|
|
|
<< " Scheduling Flushes and Compactions Time: \n"
|
|
|
|
<< hist_write_scheduling_time.ToString() << "\n"
|
2015-03-30 20:05:35 +00:00
|
|
|
<< " Total DB mutex nanos: \n" << total_db_mutex_nanos << "\n";
|
|
|
|
|
|
|
|
std::cout << "Get(): Time to get snapshot: \n"
|
|
|
|
<< hist_get_snapshot.ToString()
|
|
|
|
<< " Time to get value from memtables: \n"
|
|
|
|
<< hist_get_memtable.ToString() << "\n"
|
|
|
|
<< " Time to get value from output files: \n"
|
|
|
|
<< hist_get_files.ToString() << "\n"
|
|
|
|
<< " Number of memtables checked: \n"
|
|
|
|
<< hist_num_memtable_checked.ToString() << "\n"
|
|
|
|
<< " Time to post process: \n" << hist_get_post_process.ToString()
|
|
|
|
<< "\n";
|
|
|
|
|
|
|
|
std::cout << "MultiGet(): Time to get snapshot: \n"
|
|
|
|
<< hist_mget_snapshot.ToString()
|
|
|
|
<< " Time to get value from memtables: \n"
|
|
|
|
<< hist_mget_memtable.ToString() << "\n"
|
|
|
|
<< " Time to get value from output files: \n"
|
|
|
|
<< hist_mget_files.ToString() << "\n"
|
|
|
|
<< " Number of memtables checked: \n"
|
|
|
|
<< hist_mget_num_memtable_checked.ToString() << "\n"
|
|
|
|
<< " Time to post process: \n"
|
|
|
|
<< hist_mget_post_process.ToString() << "\n";
|
|
|
|
}
|
2014-10-03 00:02:30 +00:00
|
|
|
|
|
|
|
if (enabled_time) {
|
|
|
|
ASSERT_GT(hist_get.Average(), 0);
|
|
|
|
ASSERT_GT(hist_get_snapshot.Average(), 0);
|
|
|
|
ASSERT_GT(hist_get_memtable.Average(), 0);
|
|
|
|
ASSERT_GT(hist_get_files.Average(), 0);
|
|
|
|
ASSERT_GT(hist_get_post_process.Average(), 0);
|
|
|
|
ASSERT_GT(hist_num_memtable_checked.Average(), 0);
|
|
|
|
|
|
|
|
ASSERT_GT(hist_mget.Average(), 0);
|
|
|
|
ASSERT_GT(hist_mget_snapshot.Average(), 0);
|
|
|
|
ASSERT_GT(hist_mget_memtable.Average(), 0);
|
|
|
|
ASSERT_GT(hist_mget_files.Average(), 0);
|
|
|
|
ASSERT_GT(hist_mget_post_process.Average(), 0);
|
|
|
|
ASSERT_GT(hist_mget_num_memtable_checked.Average(), 0);
|
2018-04-24 00:53:27 +00:00
|
|
|
|
|
|
|
EXPECT_GT(hist_write_pre_post.Average(), 0);
|
|
|
|
EXPECT_GT(hist_write_wal_time.Average(), 0);
|
|
|
|
EXPECT_GT(hist_write_memtable_time.Average(), 0);
|
|
|
|
EXPECT_EQ(hist_write_delay_time.Average(), 0);
|
|
|
|
EXPECT_EQ(hist_write_thread_wait_nanos.Average(), 0);
|
|
|
|
EXPECT_GT(hist_write_scheduling_time.Average(), 0);
|
|
|
|
|
2015-02-10 00:12:31 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
ASSERT_GT(total_db_mutex_nanos, 2000U);
|
|
|
|
#endif
|
2014-10-03 00:02:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
db.reset();
|
|
|
|
db = OpenDb(true);
|
|
|
|
|
|
|
|
hist_get.Clear();
|
|
|
|
hist_get_snapshot.Clear();
|
|
|
|
hist_get_memtable.Clear();
|
|
|
|
hist_get_files.Clear();
|
|
|
|
hist_get_post_process.Clear();
|
|
|
|
hist_num_memtable_checked.Clear();
|
|
|
|
|
|
|
|
hist_mget.Clear();
|
|
|
|
hist_mget_snapshot.Clear();
|
|
|
|
hist_mget_memtable.Clear();
|
|
|
|
hist_mget_files.Clear();
|
|
|
|
hist_mget_post_process.Clear();
|
|
|
|
hist_mget_num_memtable_checked.Clear();
|
|
|
|
|
|
|
|
for (const int i : keys) {
|
2016-04-21 22:32:06 +00:00
|
|
|
if (i == kFlushFlag) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-11-25 04:44:49 +00:00
|
|
|
std::string key = "k" + ToString(i);
|
2016-04-21 22:32:06 +00:00
|
|
|
std::string expected_value = "v" + ToString(i);
|
|
|
|
std::string value;
|
2014-10-03 00:02:30 +00:00
|
|
|
|
2014-11-07 23:04:30 +00:00
|
|
|
std::vector<Slice> multiget_keys = {Slice(key)};
|
2014-10-03 00:02:30 +00:00
|
|
|
std::vector<std::string> values;
|
|
|
|
|
2017-06-03 00:12:39 +00:00
|
|
|
get_perf_context()->Reset();
|
2016-04-21 22:32:06 +00:00
|
|
|
ASSERT_OK(db->Get(read_options, key, &value));
|
|
|
|
ASSERT_EQ(expected_value, value);
|
2017-06-03 00:12:39 +00:00
|
|
|
hist_get_snapshot.Add(get_perf_context()->get_snapshot_time);
|
|
|
|
hist_get_memtable.Add(get_perf_context()->get_from_memtable_time);
|
|
|
|
hist_get_files.Add(get_perf_context()->get_from_output_files_time);
|
|
|
|
hist_num_memtable_checked.Add(get_perf_context()->get_from_memtable_count);
|
|
|
|
hist_get_post_process.Add(get_perf_context()->get_post_process_time);
|
|
|
|
hist_get.Add(get_perf_context()->user_key_comparison_count);
|
|
|
|
|
|
|
|
get_perf_context()->Reset();
|
2020-12-23 07:44:44 +00:00
|
|
|
auto statuses = db->MultiGet(read_options, multiget_keys, &values);
|
|
|
|
for (const auto& s : statuses) {
|
|
|
|
ASSERT_OK(s);
|
|
|
|
}
|
2017-06-03 00:12:39 +00:00
|
|
|
hist_mget_snapshot.Add(get_perf_context()->get_snapshot_time);
|
|
|
|
hist_mget_memtable.Add(get_perf_context()->get_from_memtable_time);
|
|
|
|
hist_mget_files.Add(get_perf_context()->get_from_output_files_time);
|
|
|
|
hist_mget_num_memtable_checked.Add(get_perf_context()->get_from_memtable_count);
|
|
|
|
hist_mget_post_process.Add(get_perf_context()->get_post_process_time);
|
|
|
|
hist_mget.Add(get_perf_context()->user_key_comparison_count);
|
2014-10-03 00:02:30 +00:00
|
|
|
}
|
|
|
|
|
2015-03-30 20:05:35 +00:00
|
|
|
if (FLAGS_verbose) {
|
2020-12-23 07:44:44 +00:00
|
|
|
std::cout << "ReadOnly Get user key comparison: \n"
|
|
|
|
<< hist_get.ToString()
|
|
|
|
<< "ReadOnly MultiGet user key comparison: \n"
|
2015-03-30 20:05:35 +00:00
|
|
|
<< hist_mget.ToString();
|
|
|
|
|
|
|
|
std::cout << "ReadOnly Get(): Time to get snapshot: \n"
|
|
|
|
<< hist_get_snapshot.ToString()
|
|
|
|
<< " Time to get value from memtables: \n"
|
|
|
|
<< hist_get_memtable.ToString() << "\n"
|
|
|
|
<< " Time to get value from output files: \n"
|
|
|
|
<< hist_get_files.ToString() << "\n"
|
|
|
|
<< " Number of memtables checked: \n"
|
|
|
|
<< hist_num_memtable_checked.ToString() << "\n"
|
|
|
|
<< " Time to post process: \n" << hist_get_post_process.ToString()
|
|
|
|
<< "\n";
|
|
|
|
|
|
|
|
std::cout << "ReadOnly MultiGet(): Time to get snapshot: \n"
|
|
|
|
<< hist_mget_snapshot.ToString()
|
|
|
|
<< " Time to get value from memtables: \n"
|
|
|
|
<< hist_mget_memtable.ToString() << "\n"
|
|
|
|
<< " Time to get value from output files: \n"
|
|
|
|
<< hist_mget_files.ToString() << "\n"
|
|
|
|
<< " Number of memtables checked: \n"
|
|
|
|
<< hist_mget_num_memtable_checked.ToString() << "\n"
|
|
|
|
<< " Time to post process: \n"
|
|
|
|
<< hist_mget_post_process.ToString() << "\n";
|
|
|
|
}
|
2014-10-03 00:02:30 +00:00
|
|
|
|
|
|
|
if (enabled_time) {
|
|
|
|
ASSERT_GT(hist_get.Average(), 0);
|
|
|
|
ASSERT_GT(hist_get_memtable.Average(), 0);
|
|
|
|
ASSERT_GT(hist_get_files.Average(), 0);
|
|
|
|
ASSERT_GT(hist_num_memtable_checked.Average(), 0);
|
|
|
|
// In read-only mode Get(), no super version operation is needed
|
|
|
|
ASSERT_EQ(hist_get_post_process.Average(), 0);
|
2018-08-23 05:40:34 +00:00
|
|
|
ASSERT_GT(hist_get_snapshot.Average(), 0);
|
2014-10-03 00:02:30 +00:00
|
|
|
|
|
|
|
ASSERT_GT(hist_mget.Average(), 0);
|
|
|
|
ASSERT_GT(hist_mget_snapshot.Average(), 0);
|
|
|
|
ASSERT_GT(hist_mget_memtable.Average(), 0);
|
|
|
|
ASSERT_GT(hist_mget_files.Average(), 0);
|
|
|
|
ASSERT_GT(hist_mget_post_process.Average(), 0);
|
|
|
|
ASSERT_GT(hist_mget_num_memtable_checked.Average(), 0);
|
|
|
|
}
|
2013-08-13 06:59:04 +00:00
|
|
|
}
|
|
|
|
|
2015-10-13 17:32:05 +00:00
|
|
|
#ifndef ROCKSDB_LITE
|
2015-03-17 21:08:00 +00:00
|
|
|
TEST_F(PerfContextTest, KeyComparisonCount) {
|
2013-09-10 16:35:19 +00:00
|
|
|
SetPerfLevel(kEnableCount);
|
2014-10-03 00:02:30 +00:00
|
|
|
ProfileQueries();
|
[RocksDB] Added nano second stopwatch and new perf counters to track block read cost
Summary: The pupose of this diff is to expose per user-call level precise timing of block read, so that we can answer questions like: a Get() costs me 100ms, is that somehow related to loading blocks from file system, or sth else? We will answer that with EXACTLY how many blocks have been read, how much time was spent on transfering the bytes from os, how much time was spent on checksum verification and how much time was spent on block decompression, just for that one Get. A nano second stopwatch was introduced to track time with higher precision. The cost/precision of the stopwatch is also measured in unit-test. On my dev box, retrieving one time instance costs about 30ns, on average. The deviation of timing results is good enough to track 100ns-1us level events. And the overhead could be safely ignored for 100us level events (10000 instances/s), for example, a viewstate thrift call.
Test Plan: perf_context_test, also testing with viewstate shadow traffic.
Reviewers: dhruba
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D12351
2013-06-04 06:09:15 +00:00
|
|
|
|
2013-09-10 16:35:19 +00:00
|
|
|
SetPerfLevel(kDisable);
|
2014-10-03 00:02:30 +00:00
|
|
|
ProfileQueries();
|
2013-08-13 06:59:04 +00:00
|
|
|
|
[RocksDB] Added nano second stopwatch and new perf counters to track block read cost
Summary: The pupose of this diff is to expose per user-call level precise timing of block read, so that we can answer questions like: a Get() costs me 100ms, is that somehow related to loading blocks from file system, or sth else? We will answer that with EXACTLY how many blocks have been read, how much time was spent on transfering the bytes from os, how much time was spent on checksum verification and how much time was spent on block decompression, just for that one Get. A nano second stopwatch was introduced to track time with higher precision. The cost/precision of the stopwatch is also measured in unit-test. On my dev box, retrieving one time instance costs about 30ns, on average. The deviation of timing results is good enough to track 100ns-1us level events. And the overhead could be safely ignored for 100us level events (10000 instances/s), for example, a viewstate thrift call.
Test Plan: perf_context_test, also testing with viewstate shadow traffic.
Reviewers: dhruba
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D12351
2013-06-04 06:09:15 +00:00
|
|
|
SetPerfLevel(kEnableTime);
|
2014-10-03 00:02:30 +00:00
|
|
|
ProfileQueries(true);
|
2013-08-13 06:59:04 +00:00
|
|
|
}
|
2015-10-13 17:32:05 +00:00
|
|
|
#endif // ROCKSDB_LITE
|
2013-08-13 06:59:04 +00:00
|
|
|
|
2013-09-10 16:35:19 +00:00
|
|
|
// make perf_context_test
|
2013-10-05 05:32:05 +00:00
|
|
|
// export ROCKSDB_TESTS=PerfContextTest.SeekKeyComparison
|
2013-09-10 16:35:19 +00:00
|
|
|
// For one memtable:
|
|
|
|
// ./perf_context_test --write_buffer_size=500000 --total_keys=10000
|
|
|
|
// For two memtables:
|
|
|
|
// ./perf_context_test --write_buffer_size=250000 --total_keys=10000
|
|
|
|
// Specify --random_key=1 to shuffle the key before insertion
|
|
|
|
// Results show that, for sequential insertion, worst-case Seek Key comparison
|
|
|
|
// is close to the total number of keys (linear), when there is only one
|
|
|
|
// memtable. When there are two memtables, even the avg Seek Key comparison
|
|
|
|
// starts to become linear to the input size.
|
|
|
|
|
2015-03-17 21:08:00 +00:00
|
|
|
TEST_F(PerfContextTest, SeekKeyComparison) {
|
2013-09-10 16:35:19 +00:00
|
|
|
DestroyDB(kDbName, Options());
|
|
|
|
auto db = OpenDb();
|
|
|
|
WriteOptions write_options;
|
|
|
|
ReadOptions read_options;
|
|
|
|
|
2015-03-30 20:05:35 +00:00
|
|
|
if (FLAGS_verbose) {
|
|
|
|
std::cout << "Inserting " << FLAGS_total_keys << " key/value pairs\n...\n";
|
|
|
|
}
|
2013-09-10 16:35:19 +00:00
|
|
|
|
|
|
|
std::vector<int> keys;
|
|
|
|
for (int i = 0; i < FLAGS_total_keys; ++i) {
|
|
|
|
keys.push_back(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FLAGS_random_key) {
|
2020-04-20 20:21:34 +00:00
|
|
|
RandomShuffle(std::begin(keys), std::end(keys));
|
2013-09-10 16:35:19 +00:00
|
|
|
}
|
|
|
|
|
2013-10-23 06:26:51 +00:00
|
|
|
HistogramImpl hist_put_time;
|
|
|
|
HistogramImpl hist_wal_time;
|
|
|
|
HistogramImpl hist_time_diff;
|
|
|
|
|
|
|
|
SetPerfLevel(kEnableTime);
|
2021-01-26 06:07:26 +00:00
|
|
|
StopWatchNano timer(SystemClock::Default());
|
2013-09-10 16:35:19 +00:00
|
|
|
for (const int i : keys) {
|
2014-11-25 04:44:49 +00:00
|
|
|
std::string key = "k" + ToString(i);
|
|
|
|
std::string value = "v" + ToString(i);
|
2013-09-10 16:35:19 +00:00
|
|
|
|
2017-06-03 00:12:39 +00:00
|
|
|
get_perf_context()->Reset();
|
2013-10-23 06:26:51 +00:00
|
|
|
timer.Start();
|
2020-12-23 07:44:44 +00:00
|
|
|
ASSERT_OK(db->Put(write_options, key, value));
|
2013-10-23 06:26:51 +00:00
|
|
|
auto put_time = timer.ElapsedNanos();
|
|
|
|
hist_put_time.Add(put_time);
|
2017-06-03 00:12:39 +00:00
|
|
|
hist_wal_time.Add(get_perf_context()->write_wal_time);
|
|
|
|
hist_time_diff.Add(put_time - get_perf_context()->write_wal_time);
|
2013-09-10 16:35:19 +00:00
|
|
|
}
|
|
|
|
|
2015-03-30 20:05:35 +00:00
|
|
|
if (FLAGS_verbose) {
|
|
|
|
std::cout << "Put time:\n" << hist_put_time.ToString() << "WAL time:\n"
|
|
|
|
<< hist_wal_time.ToString() << "time diff:\n"
|
|
|
|
<< hist_time_diff.ToString();
|
|
|
|
}
|
2013-10-23 06:26:51 +00:00
|
|
|
|
2013-09-25 21:35:01 +00:00
|
|
|
HistogramImpl hist_seek;
|
|
|
|
HistogramImpl hist_next;
|
|
|
|
|
2013-09-10 16:35:19 +00:00
|
|
|
for (int i = 0; i < FLAGS_total_keys; ++i) {
|
2014-11-25 04:44:49 +00:00
|
|
|
std::string key = "k" + ToString(i);
|
|
|
|
std::string value = "v" + ToString(i);
|
2013-09-10 16:35:19 +00:00
|
|
|
|
|
|
|
std::unique_ptr<Iterator> iter(db->NewIterator(read_options));
|
2017-06-03 00:12:39 +00:00
|
|
|
get_perf_context()->Reset();
|
2013-09-10 16:35:19 +00:00
|
|
|
iter->Seek(key);
|
|
|
|
ASSERT_TRUE(iter->Valid());
|
|
|
|
ASSERT_EQ(iter->value().ToString(), value);
|
2017-06-03 00:12:39 +00:00
|
|
|
hist_seek.Add(get_perf_context()->user_key_comparison_count);
|
2013-09-10 16:35:19 +00:00
|
|
|
}
|
2013-09-25 21:35:01 +00:00
|
|
|
|
|
|
|
std::unique_ptr<Iterator> iter(db->NewIterator(read_options));
|
|
|
|
for (iter->SeekToFirst(); iter->Valid();) {
|
2017-06-03 00:12:39 +00:00
|
|
|
get_perf_context()->Reset();
|
2013-09-25 21:35:01 +00:00
|
|
|
iter->Next();
|
2017-06-03 00:12:39 +00:00
|
|
|
hist_next.Add(get_perf_context()->user_key_comparison_count);
|
2013-09-25 21:35:01 +00:00
|
|
|
}
|
2020-12-23 07:44:44 +00:00
|
|
|
ASSERT_OK(iter->status());
|
2015-03-30 20:05:35 +00:00
|
|
|
if (FLAGS_verbose) {
|
|
|
|
std::cout << "Seek:\n" << hist_seek.ToString() << "Next:\n"
|
|
|
|
<< hist_next.ToString();
|
|
|
|
}
|
2013-09-10 16:35:19 +00:00
|
|
|
}
|
|
|
|
|
2015-10-13 17:41:48 +00:00
|
|
|
TEST_F(PerfContextTest, DBMutexLockCounter) {
|
|
|
|
int stats_code[] = {0, static_cast<int>(DB_MUTEX_WAIT_MICROS)};
|
2018-10-17 18:18:00 +00:00
|
|
|
for (PerfLevel perf_level_test :
|
2016-01-21 21:55:56 +00:00
|
|
|
{PerfLevel::kEnableTimeExceptForMutex, PerfLevel::kEnableTime}) {
|
|
|
|
for (int c = 0; c < 2; ++c) {
|
2021-01-26 06:07:26 +00:00
|
|
|
InstrumentedMutex mutex(nullptr, SystemClock::Default(), stats_code[c]);
|
2015-10-13 17:41:48 +00:00
|
|
|
mutex.Lock();
|
2021-01-26 06:07:26 +00:00
|
|
|
ROCKSDB_NAMESPACE::port::Thread child_thread([&] {
|
|
|
|
SetPerfLevel(perf_level_test);
|
|
|
|
get_perf_context()->Reset();
|
2017-06-03 00:12:39 +00:00
|
|
|
ASSERT_EQ(get_perf_context()->db_mutex_lock_nanos, 0);
|
2021-01-26 06:07:26 +00:00
|
|
|
mutex.Lock();
|
|
|
|
mutex.Unlock();
|
|
|
|
if (perf_level_test == PerfLevel::kEnableTimeExceptForMutex ||
|
|
|
|
stats_code[c] != DB_MUTEX_WAIT_MICROS) {
|
|
|
|
ASSERT_EQ(get_perf_context()->db_mutex_lock_nanos, 0);
|
|
|
|
} else {
|
|
|
|
// increment the counter only when it's a DB Mutex
|
|
|
|
ASSERT_GT(get_perf_context()->db_mutex_lock_nanos, 0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
SystemClock::Default()->SleepForMicroseconds(100);
|
|
|
|
mutex.Unlock();
|
|
|
|
child_thread.join();
|
2015-10-13 17:41:48 +00:00
|
|
|
}
|
2016-01-21 21:55:56 +00:00
|
|
|
}
|
2015-10-13 17:41:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(PerfContextTest, FalseDBMutexWait) {
|
|
|
|
SetPerfLevel(kEnableTime);
|
|
|
|
int stats_code[] = {0, static_cast<int>(DB_MUTEX_WAIT_MICROS)};
|
|
|
|
for (int c = 0; c < 2; ++c) {
|
2021-01-26 06:07:26 +00:00
|
|
|
InstrumentedMutex mutex(nullptr, SystemClock::Default(), stats_code[c]);
|
2015-10-13 17:41:48 +00:00
|
|
|
InstrumentedCondVar lock(&mutex);
|
2017-06-03 00:12:39 +00:00
|
|
|
get_perf_context()->Reset();
|
2015-10-13 17:41:48 +00:00
|
|
|
mutex.Lock();
|
|
|
|
lock.TimedWait(100);
|
|
|
|
mutex.Unlock();
|
|
|
|
if (stats_code[c] == static_cast<int>(DB_MUTEX_WAIT_MICROS)) {
|
|
|
|
// increment the counter only when it's a DB Mutex
|
2017-06-03 00:12:39 +00:00
|
|
|
ASSERT_GT(get_perf_context()->db_condition_wait_nanos, 0);
|
2015-10-13 17:41:48 +00:00
|
|
|
} else {
|
2017-06-03 00:12:39 +00:00
|
|
|
ASSERT_EQ(get_perf_context()->db_condition_wait_nanos, 0);
|
2015-10-13 17:41:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-01 21:41:13 +00:00
|
|
|
|
|
|
|
TEST_F(PerfContextTest, ToString) {
|
2017-06-03 00:12:39 +00:00
|
|
|
get_perf_context()->Reset();
|
|
|
|
get_perf_context()->block_read_count = 12345;
|
2016-02-01 21:41:13 +00:00
|
|
|
|
2017-06-03 00:12:39 +00:00
|
|
|
std::string zero_included = get_perf_context()->ToString();
|
2016-02-01 21:41:13 +00:00
|
|
|
ASSERT_NE(std::string::npos, zero_included.find("= 0"));
|
|
|
|
ASSERT_NE(std::string::npos, zero_included.find("= 12345"));
|
|
|
|
|
2017-06-03 00:12:39 +00:00
|
|
|
std::string zero_excluded = get_perf_context()->ToString(true);
|
2016-02-01 21:41:13 +00:00
|
|
|
ASSERT_EQ(std::string::npos, zero_excluded.find("= 0"));
|
|
|
|
ASSERT_NE(std::string::npos, zero_excluded.find("= 12345"));
|
|
|
|
}
|
2016-03-26 01:29:43 +00:00
|
|
|
|
|
|
|
TEST_F(PerfContextTest, MergeOperatorTime) {
|
|
|
|
DestroyDB(kDbName, Options());
|
|
|
|
DB* db;
|
|
|
|
Options options;
|
|
|
|
options.create_if_missing = true;
|
|
|
|
options.merge_operator = MergeOperators::CreateStringAppendOperator();
|
|
|
|
Status s = DB::Open(options, kDbName, &db);
|
|
|
|
EXPECT_OK(s);
|
|
|
|
|
|
|
|
std::string val;
|
|
|
|
ASSERT_OK(db->Merge(WriteOptions(), "k1", "val1"));
|
|
|
|
ASSERT_OK(db->Merge(WriteOptions(), "k1", "val2"));
|
|
|
|
ASSERT_OK(db->Merge(WriteOptions(), "k1", "val3"));
|
|
|
|
ASSERT_OK(db->Merge(WriteOptions(), "k1", "val4"));
|
|
|
|
|
|
|
|
SetPerfLevel(kEnableTime);
|
2017-06-03 00:12:39 +00:00
|
|
|
get_perf_context()->Reset();
|
2016-03-26 01:29:43 +00:00
|
|
|
ASSERT_OK(db->Get(ReadOptions(), "k1", &val));
|
2017-04-22 03:41:37 +00:00
|
|
|
#ifdef OS_SOLARIS
|
|
|
|
for (int i = 0; i < 100; i++) {
|
|
|
|
ASSERT_OK(db->Get(ReadOptions(), "k1", &val));
|
|
|
|
}
|
|
|
|
#endif
|
2017-06-03 00:12:39 +00:00
|
|
|
EXPECT_GT(get_perf_context()->merge_operator_time_nanos, 0);
|
2016-03-26 01:29:43 +00:00
|
|
|
|
|
|
|
ASSERT_OK(db->Flush(FlushOptions()));
|
|
|
|
|
2017-06-03 00:12:39 +00:00
|
|
|
get_perf_context()->Reset();
|
2016-03-26 01:29:43 +00:00
|
|
|
ASSERT_OK(db->Get(ReadOptions(), "k1", &val));
|
2017-04-22 03:41:37 +00:00
|
|
|
#ifdef OS_SOLARIS
|
|
|
|
for (int i = 0; i < 100; i++) {
|
|
|
|
ASSERT_OK(db->Get(ReadOptions(), "k1", &val));
|
|
|
|
}
|
|
|
|
#endif
|
2017-06-03 00:12:39 +00:00
|
|
|
EXPECT_GT(get_perf_context()->merge_operator_time_nanos, 0);
|
2016-03-26 01:29:43 +00:00
|
|
|
|
|
|
|
ASSERT_OK(db->CompactRange(CompactRangeOptions(), nullptr, nullptr));
|
|
|
|
|
2017-06-03 00:12:39 +00:00
|
|
|
get_perf_context()->Reset();
|
2016-03-26 01:29:43 +00:00
|
|
|
ASSERT_OK(db->Get(ReadOptions(), "k1", &val));
|
2017-04-22 03:41:37 +00:00
|
|
|
#ifdef OS_SOLARIS
|
|
|
|
for (int i = 0; i < 100; i++) {
|
|
|
|
ASSERT_OK(db->Get(ReadOptions(), "k1", &val));
|
|
|
|
}
|
|
|
|
#endif
|
2017-06-03 00:12:39 +00:00
|
|
|
EXPECT_GT(get_perf_context()->merge_operator_time_nanos, 0);
|
2016-03-26 01:29:43 +00:00
|
|
|
|
|
|
|
delete db;
|
|
|
|
}
|
2018-10-17 18:18:00 +00:00
|
|
|
|
2019-02-05 22:12:08 +00:00
|
|
|
TEST_F(PerfContextTest, CopyAndMove) {
|
|
|
|
// Assignment operator
|
|
|
|
{
|
|
|
|
get_perf_context()->Reset();
|
|
|
|
get_perf_context()->EnablePerLevelPerfContext();
|
|
|
|
PERF_COUNTER_BY_LEVEL_ADD(bloom_filter_useful, 1, 5);
|
|
|
|
ASSERT_EQ(
|
|
|
|
1,
|
|
|
|
(*(get_perf_context()->level_to_perf_context))[5].bloom_filter_useful);
|
|
|
|
PerfContext perf_context_assign;
|
|
|
|
perf_context_assign = *get_perf_context();
|
|
|
|
ASSERT_EQ(
|
|
|
|
1,
|
|
|
|
(*(perf_context_assign.level_to_perf_context))[5].bloom_filter_useful);
|
|
|
|
get_perf_context()->ClearPerLevelPerfContext();
|
|
|
|
get_perf_context()->Reset();
|
|
|
|
ASSERT_EQ(
|
|
|
|
1,
|
|
|
|
(*(perf_context_assign.level_to_perf_context))[5].bloom_filter_useful);
|
|
|
|
perf_context_assign.ClearPerLevelPerfContext();
|
|
|
|
perf_context_assign.Reset();
|
|
|
|
}
|
|
|
|
// Copy constructor
|
|
|
|
{
|
|
|
|
get_perf_context()->Reset();
|
|
|
|
get_perf_context()->EnablePerLevelPerfContext();
|
|
|
|
PERF_COUNTER_BY_LEVEL_ADD(bloom_filter_useful, 1, 5);
|
|
|
|
ASSERT_EQ(
|
|
|
|
1,
|
|
|
|
(*(get_perf_context()->level_to_perf_context))[5].bloom_filter_useful);
|
|
|
|
PerfContext perf_context_copy(*get_perf_context());
|
|
|
|
ASSERT_EQ(
|
|
|
|
1, (*(perf_context_copy.level_to_perf_context))[5].bloom_filter_useful);
|
|
|
|
get_perf_context()->ClearPerLevelPerfContext();
|
|
|
|
get_perf_context()->Reset();
|
|
|
|
ASSERT_EQ(
|
|
|
|
1, (*(perf_context_copy.level_to_perf_context))[5].bloom_filter_useful);
|
|
|
|
perf_context_copy.ClearPerLevelPerfContext();
|
|
|
|
perf_context_copy.Reset();
|
|
|
|
}
|
|
|
|
// Move constructor
|
|
|
|
{
|
|
|
|
get_perf_context()->Reset();
|
|
|
|
get_perf_context()->EnablePerLevelPerfContext();
|
|
|
|
PERF_COUNTER_BY_LEVEL_ADD(bloom_filter_useful, 1, 5);
|
|
|
|
ASSERT_EQ(
|
|
|
|
1,
|
|
|
|
(*(get_perf_context()->level_to_perf_context))[5].bloom_filter_useful);
|
|
|
|
PerfContext perf_context_move = std::move(*get_perf_context());
|
|
|
|
ASSERT_EQ(
|
|
|
|
1, (*(perf_context_move.level_to_perf_context))[5].bloom_filter_useful);
|
|
|
|
get_perf_context()->ClearPerLevelPerfContext();
|
|
|
|
get_perf_context()->Reset();
|
|
|
|
ASSERT_EQ(
|
|
|
|
1, (*(perf_context_move.level_to_perf_context))[5].bloom_filter_useful);
|
|
|
|
perf_context_move.ClearPerLevelPerfContext();
|
|
|
|
perf_context_move.Reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(PerfContextTest, PerfContextDisableEnable) {
|
|
|
|
get_perf_context()->Reset();
|
|
|
|
get_perf_context()->EnablePerLevelPerfContext();
|
|
|
|
PERF_COUNTER_BY_LEVEL_ADD(bloom_filter_full_positive, 1, 0);
|
|
|
|
get_perf_context()->DisablePerLevelPerfContext();
|
|
|
|
PERF_COUNTER_BY_LEVEL_ADD(bloom_filter_useful, 1, 5);
|
|
|
|
get_perf_context()->EnablePerLevelPerfContext();
|
|
|
|
PERF_COUNTER_BY_LEVEL_ADD(block_cache_hit_count, 1, 0);
|
|
|
|
get_perf_context()->DisablePerLevelPerfContext();
|
|
|
|
PerfContext perf_context_copy(*get_perf_context());
|
|
|
|
ASSERT_EQ(1, (*(perf_context_copy.level_to_perf_context))[0]
|
|
|
|
.bloom_filter_full_positive);
|
|
|
|
// this was set when per level perf context is disabled, should not be copied
|
|
|
|
ASSERT_NE(
|
|
|
|
1, (*(perf_context_copy.level_to_perf_context))[5].bloom_filter_useful);
|
|
|
|
ASSERT_EQ(
|
|
|
|
1, (*(perf_context_copy.level_to_perf_context))[0].block_cache_hit_count);
|
|
|
|
perf_context_copy.ClearPerLevelPerfContext();
|
|
|
|
perf_context_copy.Reset();
|
|
|
|
get_perf_context()->ClearPerLevelPerfContext();
|
|
|
|
get_perf_context()->Reset();
|
|
|
|
}
|
|
|
|
|
2018-10-17 18:18:00 +00:00
|
|
|
TEST_F(PerfContextTest, PerfContextByLevelGetSet) {
|
|
|
|
get_perf_context()->Reset();
|
|
|
|
get_perf_context()->EnablePerLevelPerfContext();
|
|
|
|
PERF_COUNTER_BY_LEVEL_ADD(bloom_filter_full_positive, 1, 0);
|
|
|
|
PERF_COUNTER_BY_LEVEL_ADD(bloom_filter_useful, 1, 5);
|
|
|
|
PERF_COUNTER_BY_LEVEL_ADD(bloom_filter_useful, 1, 7);
|
|
|
|
PERF_COUNTER_BY_LEVEL_ADD(bloom_filter_useful, 1, 7);
|
|
|
|
PERF_COUNTER_BY_LEVEL_ADD(bloom_filter_full_true_positive, 1, 2);
|
2018-12-21 21:15:47 +00:00
|
|
|
PERF_COUNTER_BY_LEVEL_ADD(block_cache_hit_count, 1, 0);
|
|
|
|
PERF_COUNTER_BY_LEVEL_ADD(block_cache_hit_count, 5, 2);
|
|
|
|
PERF_COUNTER_BY_LEVEL_ADD(block_cache_miss_count, 2, 3);
|
|
|
|
PERF_COUNTER_BY_LEVEL_ADD(block_cache_miss_count, 4, 1);
|
2018-10-17 18:18:00 +00:00
|
|
|
ASSERT_EQ(
|
|
|
|
0, (*(get_perf_context()->level_to_perf_context))[0].bloom_filter_useful);
|
|
|
|
ASSERT_EQ(
|
|
|
|
1, (*(get_perf_context()->level_to_perf_context))[5].bloom_filter_useful);
|
|
|
|
ASSERT_EQ(
|
|
|
|
2, (*(get_perf_context()->level_to_perf_context))[7].bloom_filter_useful);
|
|
|
|
ASSERT_EQ(1, (*(get_perf_context()->level_to_perf_context))[0]
|
|
|
|
.bloom_filter_full_positive);
|
|
|
|
ASSERT_EQ(1, (*(get_perf_context()->level_to_perf_context))[2]
|
|
|
|
.bloom_filter_full_true_positive);
|
2018-12-21 21:15:47 +00:00
|
|
|
ASSERT_EQ(1, (*(get_perf_context()->level_to_perf_context))[0]
|
|
|
|
.block_cache_hit_count);
|
|
|
|
ASSERT_EQ(5, (*(get_perf_context()->level_to_perf_context))[2]
|
|
|
|
.block_cache_hit_count);
|
|
|
|
ASSERT_EQ(2, (*(get_perf_context()->level_to_perf_context))[3]
|
|
|
|
.block_cache_miss_count);
|
|
|
|
ASSERT_EQ(4, (*(get_perf_context()->level_to_perf_context))[1]
|
|
|
|
.block_cache_miss_count);
|
2018-10-17 18:18:00 +00:00
|
|
|
std::string zero_excluded = get_perf_context()->ToString(true);
|
|
|
|
ASSERT_NE(std::string::npos,
|
|
|
|
zero_excluded.find("bloom_filter_useful = 1@level5, 2@level7"));
|
|
|
|
ASSERT_NE(std::string::npos,
|
|
|
|
zero_excluded.find("bloom_filter_full_positive = 1@level0"));
|
|
|
|
ASSERT_NE(std::string::npos,
|
|
|
|
zero_excluded.find("bloom_filter_full_true_positive = 1@level2"));
|
2018-12-21 21:15:47 +00:00
|
|
|
ASSERT_NE(std::string::npos,
|
|
|
|
zero_excluded.find("block_cache_hit_count = 1@level0, 5@level2"));
|
|
|
|
ASSERT_NE(std::string::npos,
|
|
|
|
zero_excluded.find("block_cache_miss_count = 4@level1, 2@level3"));
|
[RocksDB] Added nano second stopwatch and new perf counters to track block read cost
Summary: The pupose of this diff is to expose per user-call level precise timing of block read, so that we can answer questions like: a Get() costs me 100ms, is that somehow related to loading blocks from file system, or sth else? We will answer that with EXACTLY how many blocks have been read, how much time was spent on transfering the bytes from os, how much time was spent on checksum verification and how much time was spent on block decompression, just for that one Get. A nano second stopwatch was introduced to track time with higher precision. The cost/precision of the stopwatch is also measured in unit-test. On my dev box, retrieving one time instance costs about 30ns, on average. The deviation of timing results is good enough to track 100ns-1us level events. And the overhead could be safely ignored for 100us level events (10000 instances/s), for example, a viewstate thrift call.
Test Plan: perf_context_test, also testing with viewstate shadow traffic.
Reviewers: dhruba
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D12351
2013-06-04 06:09:15 +00:00
|
|
|
}
|
2019-03-26 23:20:52 +00:00
|
|
|
|
|
|
|
TEST_F(PerfContextTest, CPUTimer) {
|
2021-01-26 06:07:26 +00:00
|
|
|
if (SystemClock::Default()->CPUNanos() == 0) {
|
|
|
|
ROCKSDB_GTEST_SKIP("Target without CPUNanos support");
|
Fix MSVC-related build issues (#7439)
Summary:
This PR addresses some build and functional issues on MSVC targets, as a step towards an eventual goal of having RocksDB build successfully for Windows on ARM64.
Addressed issues include:
- BitsSetToOne and CountTrailingZeroBits do not compile on non-x64 MSVC targets. A fallback implementation of BitsSetToOne when Intel intrinsics are not available is added, based on the C++20 `<bit>` popcount implementation in Microsoft's STL.
- The implementation of FloorLog2 for MSVC targets (including x64) gives incorrect results. The unit test easily detects this, but CircleCI is currently configured to only run a specific set of tests for Windows CMake builds, so this seems to have been unnoticed.
- AsmVolatilePause does not use YieldProcessor on Windows ARM64 targets, even though it is available.
- When CondVar::TimedWait calls Microsoft STL's condition_variable::wait_for, it can potentially trigger a bug (just recently fixed in the upcoming VS 16.8's STL) that deadlocks various tests that wait for a timer to execute, since `Timer::Run` doesn't get a chance to execute before being blocked by the test function acquiring the mutex.
- In c_test, `GetTempDir` assumes a POSIX-style temp path.
- `NormalizePath` did not eliminate consecutive POSIX-style path separators on Windows, resulting in test failures in e.g., wal_manager_test.
- Various other test failures.
In a followup PR I hope to modify CircleCI's config.yml to invoke all RocksDB unit tests in Windows CMake builds with CTest, instead of the current use of `run_ci_db_test.ps1` which requires individual tests to be specified and is missing many of the existing tests.
Notes from peterd: FloorLog2 is not yet used in production code (it's for something in progress). I also added a few more inexpensive platform-dependent tests to Windows CircleCI runs. And included facebook/folly#1461 as requested
Pull Request resolved: https://github.com/facebook/rocksdb/pull/7439
Reviewed By: jay-zhuang
Differential Revision: D24021563
Pulled By: pdillinger
fbshipit-source-id: 0ec2027c0d6a494d8a0fe38d9667fc2f7e29f7e7
2020-10-01 16:21:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-26 23:20:52 +00:00
|
|
|
DestroyDB(kDbName, Options());
|
|
|
|
auto db = OpenDb();
|
|
|
|
WriteOptions write_options;
|
|
|
|
ReadOptions read_options;
|
|
|
|
SetPerfLevel(PerfLevel::kEnableTimeAndCPUTimeExceptForMutex);
|
|
|
|
|
|
|
|
std::string max_str = "0";
|
|
|
|
for (int i = 0; i < FLAGS_total_keys; ++i) {
|
|
|
|
std::string i_str = ToString(i);
|
|
|
|
std::string key = "k" + i_str;
|
|
|
|
std::string value = "v" + i_str;
|
|
|
|
max_str = max_str > i_str ? max_str : i_str;
|
|
|
|
|
2020-12-23 07:44:44 +00:00
|
|
|
ASSERT_OK(db->Put(write_options, key, value));
|
2019-03-26 23:20:52 +00:00
|
|
|
}
|
|
|
|
std::string last_key = "k" + max_str;
|
|
|
|
std::string last_value = "v" + max_str;
|
|
|
|
|
|
|
|
{
|
|
|
|
// Get
|
|
|
|
get_perf_context()->Reset();
|
|
|
|
std::string value;
|
|
|
|
ASSERT_OK(db->Get(read_options, "k0", &value));
|
|
|
|
ASSERT_EQ(value, "v0");
|
|
|
|
|
|
|
|
if (FLAGS_verbose) {
|
2019-03-27 19:20:43 +00:00
|
|
|
std::cout << "Get CPU time nanos: " << get_perf_context()->get_cpu_nanos
|
|
|
|
<< "ns\n";
|
2019-03-26 23:20:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Iter
|
|
|
|
std::unique_ptr<Iterator> iter(db->NewIterator(read_options));
|
|
|
|
|
|
|
|
// Seek
|
|
|
|
get_perf_context()->Reset();
|
|
|
|
iter->Seek(last_key);
|
|
|
|
ASSERT_TRUE(iter->Valid());
|
|
|
|
ASSERT_EQ(last_value, iter->value().ToString());
|
|
|
|
|
|
|
|
if (FLAGS_verbose) {
|
|
|
|
std::cout << "Iter Seek CPU time nanos: "
|
|
|
|
<< get_perf_context()->iter_seek_cpu_nanos << "ns\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// SeekForPrev
|
|
|
|
get_perf_context()->Reset();
|
|
|
|
iter->SeekForPrev(last_key);
|
|
|
|
ASSERT_TRUE(iter->Valid());
|
|
|
|
|
|
|
|
if (FLAGS_verbose) {
|
|
|
|
std::cout << "Iter SeekForPrev CPU time nanos: "
|
|
|
|
<< get_perf_context()->iter_seek_cpu_nanos << "ns\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// SeekToLast
|
|
|
|
get_perf_context()->Reset();
|
|
|
|
iter->SeekToLast();
|
|
|
|
ASSERT_TRUE(iter->Valid());
|
|
|
|
ASSERT_EQ(last_value, iter->value().ToString());
|
|
|
|
|
|
|
|
if (FLAGS_verbose) {
|
|
|
|
std::cout << "Iter SeekToLast CPU time nanos: "
|
|
|
|
<< get_perf_context()->iter_seek_cpu_nanos << "ns\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// SeekToFirst
|
|
|
|
get_perf_context()->Reset();
|
|
|
|
iter->SeekToFirst();
|
|
|
|
ASSERT_TRUE(iter->Valid());
|
|
|
|
ASSERT_EQ("v0", iter->value().ToString());
|
|
|
|
|
|
|
|
if (FLAGS_verbose) {
|
|
|
|
std::cout << "Iter SeekToFirst CPU time nanos: "
|
|
|
|
<< get_perf_context()->iter_seek_cpu_nanos << "ns\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Next
|
|
|
|
get_perf_context()->Reset();
|
|
|
|
iter->Next();
|
|
|
|
ASSERT_TRUE(iter->Valid());
|
|
|
|
ASSERT_EQ("v1", iter->value().ToString());
|
|
|
|
|
|
|
|
if (FLAGS_verbose) {
|
|
|
|
std::cout << "Iter Next CPU time nanos: "
|
|
|
|
<< get_perf_context()->iter_next_cpu_nanos << "ns\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prev
|
|
|
|
get_perf_context()->Reset();
|
|
|
|
iter->Prev();
|
|
|
|
ASSERT_TRUE(iter->Valid());
|
|
|
|
ASSERT_EQ("v0", iter->value().ToString());
|
|
|
|
|
|
|
|
if (FLAGS_verbose) {
|
|
|
|
std::cout << "Iter Prev CPU time nanos: "
|
|
|
|
<< get_perf_context()->iter_prev_cpu_nanos << "ns\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// monotonically increasing
|
|
|
|
get_perf_context()->Reset();
|
|
|
|
auto count = get_perf_context()->iter_seek_cpu_nanos;
|
|
|
|
for (int i = 0; i < FLAGS_total_keys; ++i) {
|
|
|
|
iter->Seek("k" + ToString(i));
|
|
|
|
ASSERT_TRUE(iter->Valid());
|
|
|
|
ASSERT_EQ("v" + ToString(i), iter->value().ToString());
|
|
|
|
auto next_count = get_perf_context()->iter_seek_cpu_nanos;
|
|
|
|
ASSERT_GT(next_count, count);
|
|
|
|
count = next_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
// iterator creation/destruction; multiple iterators
|
|
|
|
{
|
|
|
|
std::unique_ptr<Iterator> iter2(db->NewIterator(read_options));
|
|
|
|
ASSERT_EQ(count, get_perf_context()->iter_seek_cpu_nanos);
|
|
|
|
iter2->Seek(last_key);
|
|
|
|
ASSERT_TRUE(iter2->Valid());
|
|
|
|
ASSERT_EQ(last_value, iter2->value().ToString());
|
|
|
|
ASSERT_GT(get_perf_context()->iter_seek_cpu_nanos, count);
|
|
|
|
count = get_perf_context()->iter_seek_cpu_nanos;
|
|
|
|
}
|
|
|
|
ASSERT_EQ(count, get_perf_context()->iter_seek_cpu_nanos);
|
|
|
|
}
|
|
|
|
}
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
2013-08-13 06:59:04 +00:00
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
2015-03-17 21:08:00 +00:00
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
2013-08-13 06:59:04 +00:00
|
|
|
|
2013-09-10 16:35:19 +00:00
|
|
|
for (int i = 1; i < argc; i++) {
|
|
|
|
int n;
|
|
|
|
char junk;
|
|
|
|
|
|
|
|
if (sscanf(argv[i], "--write_buffer_size=%d%c", &n, &junk) == 1) {
|
|
|
|
FLAGS_write_buffer_size = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sscanf(argv[i], "--total_keys=%d%c", &n, &junk) == 1) {
|
|
|
|
FLAGS_total_keys = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sscanf(argv[i], "--random_key=%d%c", &n, &junk) == 1 &&
|
|
|
|
(n == 0 || n == 1)) {
|
|
|
|
FLAGS_random_key = n;
|
|
|
|
}
|
|
|
|
|
2013-09-25 21:35:01 +00:00
|
|
|
if (sscanf(argv[i], "--use_set_based_memetable=%d%c", &n, &junk) == 1 &&
|
|
|
|
(n == 0 || n == 1)) {
|
|
|
|
FLAGS_use_set_based_memetable = n;
|
|
|
|
}
|
|
|
|
|
2015-03-30 20:05:35 +00:00
|
|
|
if (sscanf(argv[i], "--verbose=%d%c", &n, &junk) == 1 &&
|
|
|
|
(n == 0 || n == 1)) {
|
|
|
|
FLAGS_verbose = n;
|
|
|
|
}
|
2013-08-13 06:59:04 +00:00
|
|
|
}
|
|
|
|
|
2015-03-30 20:05:35 +00:00
|
|
|
if (FLAGS_verbose) {
|
|
|
|
std::cout << kDbName << "\n";
|
|
|
|
}
|
2013-09-10 16:35:19 +00:00
|
|
|
|
2015-03-17 21:08:00 +00:00
|
|
|
return RUN_ALL_TESTS();
|
2013-08-13 06:59:04 +00:00
|
|
|
}
|