Skip to content

Commit 5addea7

Browse files
committed
Fix pgbench performance issue induced by commit af35fe5.
Commit af35fe5 caused "pgbench -i" to emit a '\r' character for each data row loaded (when stderr is a terminal). That's effectively invisible on-screen, but it causes the connected terminal program to consume a lot of cycles. It's even worse if you're connected over ssh, as the data then has to pass through the ssh tunnel. Simplest fix is to move the added logic inside the if-tests that check whether to print a progress line. We could do it another way that avoids duplicating these few lines, but on the whole this seems the most transparent way to write it. Like the previous commit, back-patch to all supported versions. Reported-by: Andres Freund <andres@anarazel.de> Author: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: Nathan Bossart <nathandbossart@gmail.com> Discussion: https://postgr.es/m/4k4drkh7bcmdezq6zbkhp25mnrzpswqi2o75d5uv2eeg3aq6q7@b7kqdmzzwzgb Backpatch-through: 13
1 parent 9f6ad2f commit 5addea7

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

src/bin/pgbench/pgbench.c

+20-10
Original file line numberDiff line numberDiff line change
@@ -4312,6 +4312,16 @@ initGenerateDataClientSide(PGconn *con)
43124312
j, (int64) naccounts * scale,
43134313
(int) (((int64) j * 100) / (naccounts * (int64) scale)),
43144314
elapsed_sec, remaining_sec);
4315+
4316+
/*
4317+
* If the previous progress message is longer than the current
4318+
* one, add spaces to the current line to fully overwrite any
4319+
* remaining characters from the previous message.
4320+
*/
4321+
if (prev_chars > chars)
4322+
fprintf(stderr, "%*c", prev_chars - chars, ' ');
4323+
fputc(eol, stderr);
4324+
prev_chars = chars;
43154325
}
43164326
/* let's not call the timing for each row, but only each 100 rows */
43174327
else if (use_quiet && (j % 100 == 0))
@@ -4326,20 +4336,20 @@ initGenerateDataClientSide(PGconn *con)
43264336
j, (int64) naccounts * scale,
43274337
(int) (((int64) j * 100) / (naccounts * (int64) scale)), elapsed_sec, remaining_sec);
43284338

4339+
/*
4340+
* If the previous progress message is longer than the current
4341+
* one, add spaces to the current line to fully overwrite any
4342+
* remaining characters from the previous message.
4343+
*/
4344+
if (prev_chars > chars)
4345+
fprintf(stderr, "%*c", prev_chars - chars, ' ');
4346+
fputc(eol, stderr);
4347+
prev_chars = chars;
4348+
43294349
/* skip to the next interval */
43304350
log_interval = (int) ceil(elapsed_sec / LOG_STEP_SECONDS);
43314351
}
43324352
}
4333-
4334-
/*
4335-
* If the previous progress message is longer than the current one,
4336-
* add spaces to the current line to fully overwrite any remaining
4337-
* characters from the previous message.
4338-
*/
4339-
if (prev_chars > chars)
4340-
fprintf(stderr, "%*c", prev_chars - chars, ' ');
4341-
fputc(eol, stderr);
4342-
prev_chars = chars;
43434353
}
43444354

43454355
if (eol != '\n')

0 commit comments

Comments
 (0)