bench: some cleanups to netbench and allow multiple rounds of measurement
@@ -223,7 +223,7 @@ std::vector<double> PoissonWorker(rt::UdpConn *c, double req_rate,
return timings;
}
-void RunExperiment(double req_rate, double service_time) {
+std::vector<double> RunExperiment(double req_rate, double *reqs_per_sec) {
std::unique_ptr<rt::UdpConn> c(rt::UdpConn::Dial({0, 0}, raddr));
if (c == nullptr) panic("couldn't establish control connection");
@@ -298,9 +298,25 @@ void RunExperiment(double req_rate, double service_time) {
timings.insert(timings.end(), v.begin(), v.end());
}
- // Report statistics.
+ // Report results.
double elapsed = std::chrono::duration_cast<sec>(finish - start).count();
- double reqs_per_sec = static_cast<double>(total) / elapsed * 1000000;
+ *reqs_per_sec = static_cast<double>(total) / elapsed * 1000000;
+ return timings;
+}
+
+void DoExperiment(double req_rate) {
+ constexpr int kRounds = 1;
+ std::vector<double> timings;
+ double reqs_per_sec = 0;
+ for (int i = 0; i < kRounds; i++) {
+ double tmp;
+ auto t = RunExperiment(req_rate, &tmp);
+ timings.insert(timings.end(), t.begin(), t.end());
+ reqs_per_sec += tmp;
+ rt::Sleep(500 * rt::kMilliseconds);
+ }
+ reqs_per_sec /= kRounds;
+
std::sort(timings.begin(), timings.end());
double sum = std::accumulate(timings.begin(), timings.end(), 0.0);
double mean = sum / timings.size();
@@ -325,9 +341,8 @@ void RunExperiment(double req_rate, double service_time) {
}
void ClientHandler(void *arg) {
- for (double i = 10000; i <= 4000000; i += 10000) {
- RunExperiment(i, 10);
- }
+ for (double i = 10000; i <= 4000000; i += 10000)
+ DoExperiment(i);
}
int StringToAddr(const char *str, uint32_t *addr) {
