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

Commit396ef15

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 parent2632bcc commit396ef15

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
@@ -4578,20 +4578,30 @@ threadRun(void *arg)
45784578
* or it's time to print a progress report. Update input_mask to show
45794579
* which client(s) received data.
45804580
*/
4581-
if (min_usec>0&&maxsock!=-1)
4581+
if (min_usec>0)
45824582
{
4583-
intnsocks;/* return from select(2) */
4583+
intnsocks=0;/* return from select(2) if called */
45844584

45854585
if (min_usec!=PG_INT64_MAX)
45864586
{
4587-
structtimevaltimeout;
4587+
if (maxsock!=-1)
4588+
{
4589+
structtimevaltimeout;
45884590

4589-
timeout.tv_sec=min_usec /1000000;
4590-
timeout.tv_usec=min_usec %1000000;
4591-
nsocks=select(maxsock+1,&input_mask,NULL,NULL,&timeout);
4591+
timeout.tv_sec=min_usec /1000000;
4592+
timeout.tv_usec=min_usec %1000000;
4593+
nsocks=select(maxsock+1,&input_mask,NULL,NULL,&timeout);
4594+
}
4595+
else/* nothing active, simple sleep */
4596+
{
4597+
pg_usleep(min_usec);
4598+
}
45924599
}
4593-
else
4600+
else/* no explicit delay, select without timeout */
4601+
{
45944602
nsocks=select(maxsock+1,&input_mask,NULL,NULL,NULL);
4603+
}
4604+
45954605
if (nsocks<0)
45964606
{
45974607
if (errno==EINTR)
@@ -4604,7 +4614,7 @@ threadRun(void *arg)
46044614
gotodone;
46054615
}
46064616
}
4607-
else
4617+
else/* min_usec == 0, i.e. something needs to be executed */
46084618
{
46094619
/* If we didn't call select(), don't try to read any data */
46104620
FD_ZERO(&input_mask);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp