Use timer to measure sleep rather than assume it is 1000 usecs

Summary:
This makes the stall timers in MakeRoomForWrite more accurate by timing
the sleeps. From looking at the logs the real sleep times are usually
about 2000 usecs each when SleepForMicros(1000) is called. The modified LOG messages are:
2012/10/29-12:06:33.271984 2b3cc872f700 delaying write 13 usecs for level0_slowdown_writes_trigger
2012/10/29-12:06:34.688939 2b3cc872f700 delaying write 1728 usecs for rate limits with max score 3.83

Task ID: #

Blame Rev:

Test Plan:
run db_bench, look at DB/LOG

Revert Plan:

Database Impact:

Memcache Impact:

Other Notes:

EImportant:

- begin *PUBLIC* platform impact section -
Bugzilla: #
- end platform impact -

Reviewers: dhruba

Reviewed By: dhruba

Differential Revision: https://reviews.facebook.net/D6297
main
Mark Callaghan 12 years ago
parent fb8d437325
commit 3e7e269292
  1. 15
      db/db_impl.cc

@ -1517,10 +1517,14 @@ Status DBImpl::MakeRoomForWrite(bool force) {
// this delay hands over some CPU to the compaction thread in
// case it is sharing the same core as the writer.
mutex_.Unlock();
uint64_t t1 = env_->NowMicros();
env_->SleepForMicroseconds(1000);
stall_level0_slowdown_ += 1000;
uint64_t delayed = env_->NowMicros() - t1;
stall_level0_slowdown_ += delayed;
allow_delay = false; // Do not delay a single write more than once
Log(options_.info_log, "delaying write...\n");
Log(options_.info_log,
"delaying write %llu usecs for level0_slowdown_writes_trigger\n",
delayed);
mutex_.Lock();
} else if (!force &&
(mem_->ApproximateMemoryUsage() <= options_.write_buffer_size)) {
@ -1546,11 +1550,14 @@ Status DBImpl::MakeRoomForWrite(bool force) {
(score = versions_->MaxCompactionScore()) > options_.rate_limit) {
// Delay a write when the compaction score for any level is too large.
mutex_.Unlock();
uint64_t t1 = env_->NowMicros();
env_->SleepForMicroseconds(1000);
stall_leveln_slowdown_ += 1000;
uint64_t delayed = env_->NowMicros() - t1;
stall_leveln_slowdown_ += delayed;
allow_delay = false; // Do not delay a single write more than once
Log(options_.info_log,
"delaying write for rate limits with max score %.2f\n", score);
"delaying write %llu usecs for rate limits with max score %.2f\n",
delayed, score);
mutex_.Lock();
} else {
// Attempt to switch to a new memtable and trigger compaction of old

Loading…
Cancel
Save