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

Commit fb05656

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 11bba6e commit fb05656

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
@@ -5011,6 +5011,16 @@ initPopulateTable(PGconn *con, const char *table, int64 base,
50115011
j, total,
50125012
(int) ((j * 100) / total),
50135013
table, elapsed_sec, remaining_sec);
5014+
5015+
/*
5016+
* If the previous progress message is longer than the current
5017+
* one, add spaces to the current line to fully overwrite any
5018+
* remaining characters from the previous message.
5019+
*/
5020+
if (prev_chars > chars)
5021+
fprintf(stderr, "%*c", prev_chars - chars, ' ');
5022+
fputc(eol, stderr);
5023+
prev_chars = chars;
50145024
}
50155025
/* let's not call the timing for each row, but only each 100 rows */
50165026
else if (use_quiet && (j % 100 == 0))
@@ -5026,20 +5036,20 @@ initPopulateTable(PGconn *con, const char *table, int64 base,
50265036
(int) ((j * 100) / total),
50275037
table, elapsed_sec, remaining_sec);
50285038

5039+
/*
5040+
* If the previous progress message is longer than the current
5041+
* one, add spaces to the current line to fully overwrite any
5042+
* remaining characters from the previous message.
5043+
*/
5044+
if (prev_chars > chars)
5045+
fprintf(stderr, "%*c", prev_chars - chars, ' ');
5046+
fputc(eol, stderr);
5047+
prev_chars = chars;
5048+
50295049
/* skip to the next interval */
50305050
log_interval = (int) ceil(elapsed_sec / LOG_STEP_SECONDS);
50315051
}
50325052
}
5033-
5034-
/*
5035-
* If the previous progress message is longer than the current one,
5036-
* add spaces to the current line to fully overwrite any remaining
5037-
* characters from the previous message.
5038-
*/
5039-
if (prev_chars > chars)
5040-
fprintf(stderr, "%*c", prev_chars - chars, ' ');
5041-
fputc(eol, stderr);
5042-
prev_chars = chars;
50435053
}
50445054

50455055
if (chars != 0 && eol != '\n')

0 commit comments

Comments
 (0)