pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgbench show progress report extremely frequently if "--progress" >= 2148 caused by integer overflow
3+ messages / 3 participants
[nested] [flat]

* pgbench show progress report extremely frequently if "--progress" >= 2148 caused by integer overflow
@ 2014-01-17 06:51  Kingter Wang <tew@vmware.com>
  0 siblings, 2 replies; 3+ messages in thread

From: Kingter Wang @ 2014-01-17 06:51 UTC (permalink / raw)
  To: pgsql-bugs; Heikki Linnakangas <hlinnakangas@vmware.com>; +Cc: Michael Paquier <mpaquier@vmware.com>; Jignesh Shah <jshah@vmware.com>



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-bugs

Attachments:

fix_pgbench_progress.patch (text/x-patch, 1.1K) download diff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.c index 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 */
^ permalink raw reply [nested|flat] 3+ messages in thread

* Re: pgbench show progress report extremely frequently if "--progress" >= 2148 caused by integer overflow
@ 2014-01-17 08:14  Heikki Linnakangas <hlinnakangas@vmware.com>
  parent: Kingter Wang <tew@vmware.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Heikki Linnakangas @ 2014-01-17 08:14 UTC (permalink / raw)
  To: Kingter Wang <tew@vmware.com>; +Cc: pgsql-bugs; Michael Paquier <mpaquier@vmware.com>; Jignesh Shah <jshah@vmware.com>

On 01/17/2014 08:51 AM, Kingter Wang wrote:
> Fix Integer overflow which happened when covert progress from seconds to micro-seconds by
> (progress * 1000000) if progress >= 2148.
> Attached the patch.

Thanks, committed.

- Heikki


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: pgbench show progress report extremely frequently if "--progress" >= 2148 caused by integer overflow
@ 2014-01-17 22:04  Fabien COELHO <coelho@cri.ensmp.fr>
  parent: Kingter Wang <tew@vmware.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Fabien COELHO @ 2014-01-17 22:04 UTC (permalink / raw)
  To: Kingter Wang <tew@vmware.com>; +Cc: pgsql-bugs


Hello,

> 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).

Indeed. Shame on me! I had not thought of overflows because of the false 
security of in64 target type. Thanks for the missing cast!

-- 
Fabien.


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2014-01-17 22:04 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-01-17 06:51 pgbench show progress report extremely frequently if "--progress" >= 2148 caused by integer overflow Kingter Wang <tew@vmware.com>
2014-01-17 08:14 ` Heikki Linnakangas <hlinnakangas@vmware.com>
2014-01-17 22:04 ` Fabien COELHO <coelho@cri.ensmp.fr>

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