Skip to content
Merged
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
40 changes: 34 additions & 6 deletions wish/cpp/benchmark/high_qps_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "absl/flags/parse.h"
#include "absl/log/initialize.h"
#include "absl/log/log.h"
#include "absl/log/vlog_is_on.h"
#include "benchmark/benchmark.h"

ABSL_FLAG(std::string, host, "127.0.0.1", "Server host to connect to");
Expand Down Expand Up @@ -348,18 +349,40 @@ static void BM_PlainText_HighQPS(benchmark::State& state) {

double prev_qps = 0.0;

for (int w = 0; w < kMaxWindows &&
near_target_count < kStableNeeded && plateau_count < kPlateauLimit;
for (int w = 0;
w < kMaxWindows &&
near_target_count < kStableNeeded &&
plateau_count < kPlateauLimit;
++w) {
ss.completed.store(0, std::memory_order_relaxed);
{
std::lock_guard<std::mutex> lk(ss.result_mu);
ss.results.clear();
}

VLOG(2) << "Measuring QPS in the warmup phase ...";

const double measured = MeasureQps(ss.completed, kWindowMs);
VLOG(2) << "[warmup] QPS: " << static_cast<int>(measured)
<< " / target: " << static_cast<int>(target_qps);

VLOG(2) << "Measured";
VLOG(2) << " Current interval: " << ss.dispenser.GetInterval() << " us";
VLOG(2) << " Measured QPS: " << static_cast<int>(measured);
VLOG(2) << " Target QPS: " << static_cast<int>(target_qps);

if (VLOG_IS_ON(2)) {
std::vector<double> rtt_snap;
{
std::lock_guard<std::mutex> lk(ss.result_mu);
rtt_snap.assign(ss.results.begin(), ss.results.end());
}
if (!rtt_snap.empty()) {
std::sort(rtt_snap.begin(), rtt_snap.end());
VLOG(2) << " RTT samples: " << rtt_snap.size()
<< " p50=" << PercentileFromSorted(rtt_snap, 0.50) << " us"
<< " p90=" << PercentileFromSorted(rtt_snap, 0.90) << " us"
<< " p99=" << PercentileFromSorted(rtt_snap, 0.99) << " us";
}
}

// Adjust only the interval knob. Workers are fixed in number; the interval
// is the sole rate-control lever.
Expand All @@ -369,6 +392,9 @@ static void BM_PlainText_HighQPS(benchmark::State& state) {
0, current_us + static_cast<int64_t>(
(1.0 / target_qps - 1.0 / measured) * 1e6));
ss.dispenser.SetInterval(new_us);

VLOG(2) << "Adjusting interval: " << current_us << " -> "
<< new_us << " us";
}

const bool near_target =
Expand All @@ -386,8 +412,10 @@ static void BM_PlainText_HighQPS(benchmark::State& state) {
else
plateau_count = 0;

VLOG(2) << "[warmup] near_target_count=" << near_target_count
<< " plateau_count=" << plateau_count;
VLOG(2) << "Warm up condition check";
VLOG(2) << " Near-target count: " << near_target_count;
VLOG(2) << " Plateau count: " << plateau_count;

prev_qps = measured;
}

Expand Down