Skip to content

Commit

Permalink
Add some async read stats (#10947)
Browse files Browse the repository at this point in the history
Summary:
Add stats for time spent in the ReadAsync call, and async read errors.

Pull Request resolved: facebook/rocksdb#10947

Test Plan: Run db_bench and look at stats

Reviewed By: akankshamahajan15

Differential Revision: D41236637

Pulled By: anand1976

fbshipit-source-id: 70539b69a28491d57acead449436a761f7108acf
  • Loading branch information
anand76 authored and Yuval-Ariel committed Jan 23, 2023
1 parent 68378ff commit 4155158
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
8 changes: 8 additions & 0 deletions file/random_access_file_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ IOStatus RandomAccessFileReader::ReadAsync(
(uintptr_t(req.scratch) & (alignment - 1)) == 0;
read_async_info->is_aligned_ = is_aligned;

uint64_t elapsed = 0;
if (use_direct_io() && is_aligned == false) {
FSReadRequest aligned_req = Align(req, alignment);
aligned_req.status.PermitUncheckedError();
Expand All @@ -491,12 +492,17 @@ IOStatus RandomAccessFileReader::ReadAsync(

assert(read_async_info->buf_.CurrentSize() == 0);

StopWatch sw(clock_, nullptr /*stats*/, 0 /*hist_type*/, &elapsed,
true /*overwrite*/, true /*delay_enabled*/);
s = file_->ReadAsync(aligned_req, opts, read_async_callback,
read_async_info, io_handle, del_fn, nullptr /*dbg*/);
} else {
StopWatch sw(clock_, nullptr /*stats*/, 0 /*hist_type*/, &elapsed,
true /*overwrite*/, true /*delay_enabled*/);
s = file_->ReadAsync(req, opts, read_async_callback, read_async_info,
io_handle, del_fn, nullptr /*dbg*/);
}
RecordTick(stats_, READ_ASYNC_MICROS, elapsed);

// Suppress false positive clang analyzer warnings.
// Memory is not released if file_->ReadAsync returns !s.ok(), because
Expand Down Expand Up @@ -575,6 +581,8 @@ void RandomAccessFileReader::ReadAsyncCallback(const FSReadRequest& req,
}
if (req.status.ok()) {
RecordInHistogram(stats_, ASYNC_READ_BYTES, req.result.size());
} else if (!req.status.IsAborted()) {
RecordTick(stats_, ASYNC_READ_ERROR_COUNT, 1);
}
#ifndef ROCKSDB_LITE
if (ShouldNotifyListeners()) {
Expand Down
5 changes: 5 additions & 0 deletions include/rocksdb/statistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,11 @@ enum Tickers : uint32_t {
// # of bytes written into blob cache.
BLOB_DB_CACHE_BYTES_WRITE,

// Time spent in the ReadAsync file system call
READ_ASYNC_MICROS,
// Number of errors returned to the async read callback
ASYNC_READ_ERROR_COUNT,

TICKER_ENUM_MAX
};

Expand Down
8 changes: 8 additions & 0 deletions java/rocksjni/portal.h
Original file line number Diff line number Diff line change
Expand Up @@ -5104,6 +5104,10 @@ class TickerTypeJni {
return -0x33;
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_CACHE_BYTES_WRITE:
return -0x34;
case ROCKSDB_NAMESPACE::Tickers::READ_ASYNC_MICROS:
return -0x35;
case ROCKSDB_NAMESPACE::Tickers::ASYNC_READ_ERROR_COUNT:
return -0x36;
case ROCKSDB_NAMESPACE::Tickers::TICKER_ENUM_MAX:
// 0x5F was the max value in the initial copy of tickers to Java.
// Since these values are exposed directly to Java clients, we keep
Expand Down Expand Up @@ -5487,6 +5491,10 @@ class TickerTypeJni {
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_CACHE_BYTES_READ;
case -0x34:
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_CACHE_BYTES_WRITE;
case -0x35:
return ROCKSDB_NAMESPACE::Tickers::READ_ASYNC_MICROS;
case -0x36:
return ROCKSDB_NAMESPACE::Tickers::ASYNC_READ_ERROR_COUNT;
case 0x5F:
// 0x5F was the max value in the initial copy of tickers to Java.
// Since these values are exposed directly to Java clients, we keep
Expand Down
4 changes: 3 additions & 1 deletion monitoring/statistics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ const std::vector<std::pair<Tickers, std::string>> TickersNameMap = {
{BLOB_DB_CACHE_ADD, "rocksdb.blobdb.cache.add"},
{BLOB_DB_CACHE_ADD_FAILURES, "rocksdb.blobdb.cache.add.failures"},
{BLOB_DB_CACHE_BYTES_READ, "rocksdb.blobdb.cache.bytes.read"},
{BLOB_DB_CACHE_BYTES_WRITE, "rocksdb.blobdb.cache.bytes.write"}};
{BLOB_DB_CACHE_BYTES_WRITE, "rocksdb.blobdb.cache.bytes.write"},
{READ_ASYNC_MICROS, "rocksdb.read.async.micros"},
{ASYNC_READ_ERROR_COUNT, "rocksdb.async.read.error.count"}};

const std::vector<std::pair<Histograms, std::string>> HistogramsNameMap = {
{DB_GET, "rocksdb.db.get.micros"},
Expand Down

0 comments on commit 4155158

Please sign in to comment.