Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1d0c3b3

Browse files
committed
pgbench: allow per-script statistics
Provide per-script statistical info (count of transactions executed under that script, average latency for the whole script) after a multi-script run, adding an intermediate level of detail to existing global stats and per-command stats. Author: Fabien Coelho Reviewer: Michaël Paquier, Álvaro Herrera
1 parent 64f5edc commit 1d0c3b3

File tree

2 files changed

+50
-13
lines changed

2 files changed

+50
-13
lines changed

doc/src/sgml/ref/pgbench.sgml

+3
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,9 @@ number of transactions actually processed: 10000/10000
11381138
tps = 618.764555 (including connections establishing)
11391139
tps = 622.977698 (excluding connections establishing)
11401140
SQL script 1: <builtin: TPC-B (sort of)>
1141+
- 10000 transactions (100.0% of total, tps = 618.764555)
1142+
- latency average = 15.844 ms
1143+
- latency stddev = 2.715 ms
11411144
- statement latencies in milliseconds:
11421145
0.004386 \set nbranches 1 * :scale
11431146
0.001343 \set ntellers 10 * :scale

src/bin/pgbench/pgbench.c

+47-13
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ bool use_log; /* log transaction latencies to a file */
164164
bool use_quiet; /* quiet logging onto stderr */
165165
int agg_interval; /* log aggregates instead of individual
166166
* transactions */
167+
bool per_script_stats = false; /* whether to collect stats per script */
167168
int progress = 0; /* thread progress report every this seconds */
168169
bool progress_timestamp = false; /* progress report with Unix time */
169170
int nclients = 1; /* number of clients */
@@ -206,8 +207,8 @@ typedef struct SimpleStats
206207
} SimpleStats;
207208

208209
/*
209-
* Data structure to hold various statistics: per-thread stats are maintained
210-
* and merged together.
210+
* Data structure to hold various statistics: per-thread and per-script stats
211+
* are maintained and merged together.
211212
*/
212213
typedef struct StatsData
213214
{
@@ -299,6 +300,7 @@ static struct
299300
{
300301
const char *name;
301302
Command **commands;
303+
StatsData stats;
302304
} sql_script[MAX_SCRIPTS]; /* SQL script files */
303305
static int num_scripts; /* number of scripts in sql_script[] */
304306
static int num_commands = 0; /* total number of Command structs */
@@ -1358,7 +1360,8 @@ doCustom(TState *thread, CState *st, FILE *logfile, StatsData *agg)
13581360
/* transaction finished: calculate latency and log the transaction */
13591361
if (commands[st->state + 1] == NULL)
13601362
{
1361-
if (progress || throttle_delay || latency_limit || logfile)
1363+
if (progress || throttle_delay || latency_limit ||
1364+
per_script_stats || logfile)
13621365
processXactStats(thread, st, &now, false, logfile, agg);
13631366
else
13641367
thread->stats.cnt++;
@@ -1451,7 +1454,7 @@ doCustom(TState *thread, CState *st, FILE *logfile, StatsData *agg)
14511454
}
14521455

14531456
/* Record transaction start time under logging, progress or throttling */
1454-
if ((logfile || progress || throttle_delay || latency_limit) && st->state == 0)
1457+
if ((logfile || progress || throttle_delay || latency_limit || per_script_stats) && st->state == 0)
14551458
{
14561459
INSTR_TIME_SET_CURRENT(st->txn_begin);
14571460

@@ -1904,6 +1907,10 @@ processXactStats(TState *thread, CState *st, instr_time *now,
19041907

19051908
if (use_log)
19061909
doLog(thread, st, logfile, now, agg, skipped, latency, lag);
1910+
1911+
/* XXX could use a mutex here, but we choose not to */
1912+
if (per_script_stats)
1913+
accumStats(&sql_script[st->use_file].stats, skipped, latency, lag);
19071914
}
19081915

19091916

@@ -2693,6 +2700,7 @@ addScript(const char *name, Command **commands)
26932700

26942701
sql_script[num_scripts].name = name;
26952702
sql_script[num_scripts].commands = commands;
2703+
initStats(&sql_script[num_scripts].stats, 0.0);
26962704
num_scripts++;
26972705
}
26982706

@@ -2776,22 +2784,43 @@ printResults(TState *threads, StatsData *total, instr_time total_time,
27762784
printf("tps = %f (including connections establishing)\n", tps_include);
27772785
printf("tps = %f (excluding connections establishing)\n", tps_exclude);
27782786

2779-
/* Report per-command latencies */
2780-
if (is_latencies)
2787+
/* Report per-command statistics */
2788+
if (per_script_stats)
27812789
{
27822790
int i;
27832791

27842792
for (i = 0; i < num_scripts; i++)
27852793
{
2786-
Command **commands;
2794+
printf("SQL script %d: %s\n"
2795+
" - " INT64_FORMAT " transactions (%.1f%% of total, tps = %f)\n",
2796+
i + 1, sql_script[i].name,
2797+
sql_script[i].stats.cnt,
2798+
100.0 * sql_script[i].stats.cnt / total->cnt,
2799+
sql_script[i].stats.cnt / time_include);
2800+
2801+
if (latency_limit)
2802+
printf(" - number of transactions skipped: " INT64_FORMAT " (%.3f%%)\n",
2803+
sql_script[i].stats.skipped,
2804+
100.0 * sql_script[i].stats.skipped /
2805+
(sql_script[i].stats.skipped + sql_script[i].stats.cnt));
2806+
2807+
printSimpleStats(" - latency", &sql_script[i].stats.latency);
27872808

2788-
printf("SQL script %d: %s\n", i + 1, sql_script[i].name);
2789-
printf(" - statement latencies in milliseconds:\n");
2809+
/* Report per-command latencies */
2810+
if (is_latencies)
2811+
{
2812+
Command **commands;
2813+
2814+
printf(" - statement latencies in milliseconds:\n");
27902815

2791-
for (commands = sql_script[i].commands; *commands != NULL; commands++)
2792-
printf(" %11.3f %s\n",
2793-
1000.0 * (*commands)->stats.sum / (*commands)->stats.count,
2794-
(*commands)->line);
2816+
for (commands = sql_script[i].commands;
2817+
*commands != NULL;
2818+
commands++)
2819+
printf(" %11.3f %s\n",
2820+
1000.0 * (*commands)->stats.sum /
2821+
(*commands)->stats.count,
2822+
(*commands)->line);
2823+
}
27952824
}
27962825
}
27972826
}
@@ -2977,6 +3006,7 @@ main(int argc, char **argv)
29773006
break;
29783007
case 'r':
29793008
benchmarking_option_set = true;
3009+
per_script_stats = true;
29803010
is_latencies = true;
29813011
break;
29823012
case 's':
@@ -3200,6 +3230,10 @@ main(int argc, char **argv)
32003230
internal_script_used = true;
32013231
}
32023232

3233+
/* show per script stats if several scripts are used */
3234+
if (num_scripts > 1)
3235+
per_script_stats = true;
3236+
32033237
/*
32043238
* Don't need more threads than there are clients. (This is not merely an
32053239
* optimization; throttle_delay is calculated incorrectly below if some

0 commit comments

Comments
 (0)