At Thu, 17 Sep 2020 17:59:45 +0900 (JST), Kyotaro Horiguchi <horikyota....@gmail.com> wrote in > Sigh.. I fixed some more wordings.
The condition "all clients took the same time to establish a connection" is not needed for the transformation, and an intermediate expression was wrong. Fixed them. regards. -- Kyotaro Horiguchi NTT Open Source Software Center
>From 802c06d95aebdb8a4ed4e3adc4a6c74d9675c625 Mon Sep 17 00:00:00 2001 From: Kyotaro Horiguchi <horikyoga....@gmail.com> Date: Thu, 17 Sep 2020 17:20:10 +0900 Subject: [PATCH v4] Fix latency and tps calculation of pgbench Fix the calculation for "latency average" and the "tps excluding connections establishing" not to wrongly affected by connections establishing time. --- src/bin/pgbench/pgbench.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c index 663d7d292a..4164a546e1 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -5194,16 +5194,34 @@ printResults(StatsData *total, instr_time total_time, instr_time conn_total_time, int64 latency_late) { double time_include, + time_exclude, tps_include, tps_exclude; int64 ntx = total->cnt - total->skipped; time_include = INSTR_TIME_GET_DOUBLE(total_time); + /* + * conn_total_time is the sum of the time each client took to establish a + * connection. In the multi-threaded case, all clients run on a thread wait + * for all the clients to establish a connection. So the actual total + * connection time of a thread is thread->conn_time * thread->nstate. Thus + * the total time took for connection establishment is: + * + * sum(thread->conn_time * thread->nstate) / nclients + * + * Assuming clients are distributed equally to threads, the expression is + * approximated as: + * + * sum(thread->conn_time) * (nclients/nthreads) / nclients + * = conn_total_time / nthreads + */ + time_exclude = (time_include - + (INSTR_TIME_GET_DOUBLE(conn_total_time) / nthreads)); + /* tps is about actually executed transactions */ tps_include = ntx / time_include; - tps_exclude = ntx / - (time_include - (INSTR_TIME_GET_DOUBLE(conn_total_time) / nclients)); + tps_exclude = ntx / time_exclude; /* Report test parameters. */ printf("transaction type: %s\n", @@ -5249,7 +5267,7 @@ printResults(StatsData *total, instr_time total_time, { /* no measurement, show average latency computed from run time */ printf("latency average = %.3f ms\n", - 1000.0 * time_include * nclients / total->cnt); + 1000.0 * time_exclude * nclients / total->cnt); } if (throttle_delay) -- 2.18.4