From: Kingter Wang <tew@vmware.com>
To: pgsql-bugs@postgresql.org
To: Heikki Linnakangas <hlinnakangas@vmware.com>
Cc: Michael Paquier <mpaquier@vmware.com>
Cc: Jignesh Shah <jshah@vmware.com>
Subject: pgbench show progress report extremely frequently if "--progress" >= 2148 caused by integer overflow
Date: Thu, 16 Jan 2014 22:51:58 -0800 (PST)
Message-ID: <1144780387.13149347.1389941518395.JavaMail.root@vmware.com> (raw)
In-Reply-To: <893617240.12873238.1389934810928.JavaMail.root@vmware.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
Logged by: Kingter Wang
Email address: tew(at)vmware(dot)com
PostgreSQL version: 9.4
Operating system: Suse 11 sp3
Description:
A new option "--progress=NUM" is introduced into postgres 9.4,
it is designed to show pgbench progress report every NUM seconds.
The option can work properly if the NUM < 2148. For example,
pgbench can show progress report every 60 seconds as below:
$ ./pgbench --progress=60 -T 600
starting vacuum...end.
progress: 60.0 s, 527.0 tps, lat 120.424 ms stddev 58.133
progress: 120.1 s, 482.5 tps, lat 130.335 ms stddev 104.964
progress: 180.1 s, 378.3 tps, lat 168.859 ms stddev 403.032
progress: 240.0 s, 358.6 tps, lat 178.792 ms stddev 417.703
progress: 300.1 s, 363.0 tps, lat 176.089 ms stddev 447.271
progress: 420.0 s, 579.7 tps, lat 110.126 ms stddev 243.220
progress: 480.1 s, 138.7 tps, lat 461.893 ms stddev 980.454
progress: 540.6 s, 114.6 tps, lat 558.521 ms stddev 1048.582
progress: 600.0 s, 153.5 tps, lat 417.516 ms stddev 969.933
transaction type: TPC-B (sort of)
scaling factor: 10
query mode: simple
number of clients: 64
number of threads: 16
duration: 600 s
number of transactions actually processed: 211803
latency average: 181.513 ms
latency stddev: 465.317 ms
tps = 351.267829 (including connections establishing)
tps = 351.520664 (excluding connections establishing)
But pgbench will unexpectedly show progress report extremely frequently,
if NUM >= 2148.
For example, passed --progress=3600, however, the pgbench report progress
with a frequency less than 1 second.
$ ./pgbench --progress=3600 -T 259200
starting vacuum...end.
progress: 0.6 s, 77.6 tps, lat 140.995 ms stddev 39.355
progress: 0.6 s, 0.0 tps, lat -nan ms stddev -nan
progress: 0.6 s, 0.0 tps, lat -nan ms stddev -nan
progress: 0.6 s, 0.0 tps, lat -nan ms stddev -nan
progress: 0.6 s, 0.0 tps, lat -nan ms stddev -nan
progress: 0.6 s, 0.0 tps, lat -nan ms stddev -nan
progress: 0.6 s, 0.0 tps, lat -nan ms stddev -nan
progress: 0.6 s, 0.0 tps, lat -nan ms stddev -nan
progress: 0.6 s, 0.0 tps, lat -nan ms stddev -nan
progress: 0.6 s, 264.6 tps, lat 172.637 ms stddev 0.000
progress: 0.6 s, 0.0 tps, lat -nan ms stddev -nan
.
.
.
====Diagnosis====
Looking into the source code, the root cause is integer overflow of
"int progress", see source code from "pgbench.c.
The integer progress multiple by 1000,000 to convert from second to micro-second.
If progress >= 2148, then the value of progress * 1000,000 (2,148,000,000)
will larger than max value of 32 bits integer (2,147,483,647).
The integer overflow lead to negative value, hence,
the value of 'next_report' does not incremental but decremental.
Therefore, the 'now' (current time) will be always larger than 'next_report',
This result in the progress report is printed out for every loop
(very very frequently), rather than wait for next time up of progress.
====Fix Patch Description====
Fix Integer overflow which happened when covert progress from seconds to micro-seconds by
(progress * 1000000) if progress >= 2148.
Attached the patch.
====Test Done====
Test passed with the patch:
$pgbench --progress=3600 -j 16 -c 64 -T 259200 pgbench
starting vacuum...end.
progress: 3600.0 s, 410.6 tps, lat 155.848 ms stddev 773.983
progress: 7200.0 s, 410.5 tps, lat 155.906 ms stddev 740.046
progress: 10800.0 s, 459.6 tps, lat 139.261 ms stddev 771.408
progress: 14400.1 s, 496.4 tps, lat 128.880 ms stddev 649.061
Best Regards,
Kingter Wang
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugsAttachments:fix_pgbench_progress.patch (text/x-patch, 1.1K) downloaddiff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.cindex 8f125830965119a9b064a93be0de8478a374d039..16b7ab5ddc7f93d63c5636b3bedae16ee75850a7 100644--- a/contrib/pgbench/pgbench.c+++ b/contrib/pgbench/pgbench.c@@ -2974,7 +2974,7 @@ threadRun(void *arg)
/* for reporting progress: */
int64 thread_start = INSTR_TIME_GET_MICROSEC(thread->start_time);
int64 last_report = thread_start;
- int64 next_report = last_report + progress * 1000000;+ int64 next_report = last_report + (int64) progress * 1000000;
int64 last_count = 0, last_lats = 0, last_sqlats = 0, last_lags = 0;
AggVals aggs;
@@ -3210,7 +3210,7 @@ threadRun(void *arg)
last_sqlats = sqlats;
last_lags = lags;
last_report = now;
- next_report += progress * 1000000;+ next_report += (int64) progress * 1000000;
}
}
#else
@@ -3261,7 +3261,7 @@ threadRun(void *arg)
last_sqlats = sqlats;
last_lags = lags;
last_report = now;
- next_report += progress * 1000000;+ next_report += (int64) progress * 1000000;
}
}
#endif /* PTHREAD_FORK_EMULATION */
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tew@vmware.com, hlinnakangas@vmware.com, mpaquier@vmware.com, jshah@vmware.com
Subject: Re: pgbench show progress report extremely frequently if "--progress" >= 2148 caused by integer overflow
In-Reply-To: <1144780387.13149347.1389941518395.JavaMail.root@vmware.com>
References: <893617240.12873238.1389934810928.JavaMail.root@vmware.com> <1144780387.13149347.1389941518395.JavaMail.root@vmware.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox