Skip to content

Commit 499d1cf

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 fd467ce commit 499d1cf

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
@@ -5009,6 +5009,16 @@ initGenerateDataClientSide(PGconn *con)
50095009
j, (int64) naccounts * scale,
50105010
(int) (((int64) j * 100) / (naccounts * (int64) scale)),
50115011
elapsed_sec, remaining_sec);
5012+
5013+
/*
5014+
* If the previous progress message is longer than the current
5015+
* one, add spaces to the current line to fully overwrite any
5016+
* remaining characters from the previous message.
5017+
*/
5018+
if (prev_chars > chars)
5019+
fprintf(stderr, "%*c", prev_chars - chars, ' ');
5020+
fputc(eol, stderr);
5021+
prev_chars = chars;
50125022
}
50135023
/* let's not call the timing for each row, but only each 100 rows */
50145024
else if (use_quiet && (j % 100 == 0))
@@ -5023,20 +5033,20 @@ initGenerateDataClientSide(PGconn *con)
50235033
j, (int64) naccounts * scale,
50245034
(int) (((int64) j * 100) / (naccounts * (int64) scale)), elapsed_sec, remaining_sec);
50255035

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

50425052
if (eol != '\n')

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy