Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

db_bench: optimize Done, replace slow divisions with addition/subtrac… #861

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion tools/db_bench_tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2887,6 +2887,7 @@ class Duration {
max_ops_ = max_ops;
ops_per_stage_ = (ops_per_stage > 0) ? ops_per_stage : max_ops;
ops_ = 0;
ops_modulo_ = 0;
start_at_ = FLAGS_env->NowMicros();
}

Expand All @@ -2895,12 +2896,14 @@ class Duration {
bool Done(int64_t increment) {
if (increment <= 0) increment = 1; // avoid Done(0) and infinite loops
ops_ += increment;
ops_modulo_ += increment;

if (max_seconds_) {
// Recheck every appx 1000 ops (exact iff increment is factor of 1000)
auto granularity = FLAGS_ops_between_duration_checks;
if ((ops_ / granularity) != ((ops_ - increment) / granularity)) {
if (ops_modulo_ >= granularity) {
uint64_t now = FLAGS_env->NowMicros();
ops_modulo_ -= granularity;
return ((now - start_at_) / 1000000) >= max_seconds_;
} else {
return false;
Expand All @@ -2915,6 +2918,7 @@ class Duration {
int64_t max_ops_;
int64_t ops_per_stage_;
int64_t ops_;
int64_t ops_modulo_;
uint64_t start_at_;
};

Expand Down
Loading