Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbabf185

Browse files
committed
Fix busy-wait in pgbench, with --rate.
If --rate was used to throttle pgbench, it failed to sleep when it hadnothing to do, leading to a busy-wait with 100% CPU usage. This bug wasintroduced in the refactoring in v10. Before that, sleep() was called witha timeout, even when there were no file descriptors to wait for.Reported by Jeff Janes, patch by Fabien COELHO. Backpatch to v10.Discussion:https://www.postgresql.org/message-id/CAMkU%3D1x5hoX0pLLKPRnXCy0T8uHoDvXdq%2B7kAM9eoC9_z72ucw%40mail.gmail.com
1 parent2aab702 commitbabf185

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

‎src/bin/pgbench/pgbench.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4539,20 +4539,30 @@ threadRun(void *arg)
45394539
* or it's time to print a progress report. Update input_mask to show
45404540
* which client(s) received data.
45414541
*/
4542-
if (min_usec>0&&maxsock!=-1)
4542+
if (min_usec>0)
45434543
{
4544-
intnsocks;/* return from select(2) */
4544+
intnsocks=0;/* return from select(2) if called */
45454545

45464546
if (min_usec!=PG_INT64_MAX)
45474547
{
4548-
structtimevaltimeout;
4548+
if (maxsock!=-1)
4549+
{
4550+
structtimevaltimeout;
45494551

4550-
timeout.tv_sec=min_usec /1000000;
4551-
timeout.tv_usec=min_usec %1000000;
4552-
nsocks=select(maxsock+1,&input_mask,NULL,NULL,&timeout);
4552+
timeout.tv_sec=min_usec /1000000;
4553+
timeout.tv_usec=min_usec %1000000;
4554+
nsocks=select(maxsock+1,&input_mask,NULL,NULL,&timeout);
4555+
}
4556+
else/* nothing active, simple sleep */
4557+
{
4558+
pg_usleep(min_usec);
4559+
}
45534560
}
4554-
else
4561+
else/* no explicit delay, select without timeout */
4562+
{
45554563
nsocks=select(maxsock+1,&input_mask,NULL,NULL,NULL);
4564+
}
4565+
45564566
if (nsocks<0)
45574567
{
45584568
if (errno==EINTR)
@@ -4565,7 +4575,7 @@ threadRun(void *arg)
45654575
gotodone;
45664576
}
45674577
}
4568-
else
4578+
else/* min_usec == 0, i.e. something needs to be executed */
45694579
{
45704580
/* If we didn't call select(), don't try to read any data */
45714581
FD_ZERO(&input_mask);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp