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

Commit e35d396

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 480acbb commit e35d396

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

src/bin/pgbench/pgbench.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5010,6 +5010,16 @@ initPopulateTable(PGconn *con, const char *table, int64 base,
50105010
j, total,
50115011
(int) ((j * 100) / total),
50125012
table, elapsed_sec, remaining_sec);
5013+
5014+
/*
5015+
* If the previous progress message is longer than the current
5016+
* one, add spaces to the current line to fully overwrite any
5017+
* remaining characters from the previous message.
5018+
*/
5019+
if (prev_chars > chars)
5020+
fprintf(stderr, "%*c", prev_chars - chars, ' ');
5021+
fputc(eol, stderr);
5022+
prev_chars = chars;
50135023
}
50145024
/* let's not call the timing for each row, but only each 100 rows */
50155025
else if (use_quiet && (j % 100 == 0))
@@ -5025,20 +5035,20 @@ initPopulateTable(PGconn *con, const char *table, int64 base,
50255035
(int) ((j * 100) / total),
50265036
table, elapsed_sec, remaining_sec);
50275037

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

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

0 commit comments

Comments
 (0)