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

Commit92daeca

Browse files
committed
Add wait event for pg_usleep() in perform_spin_delay()
The lwlock wait queue scalability issue fixed ina4adc31 was quite hard tofind because of the exponential backoff and because we adjust spins_per_delayover time within a backend.To make it easier to find similar issues in the future, add a wait event forthe pg_usleep() in perform_spin_delay(). Showing a wait event while spinningwithout sleeping would increase the overhead of spinlocks, which we do notwant.We may at some later point want to have more granular wait events, but that'dbe a substantial amount of work. This provides at least some insights intosomething currently hard to observe.Reviewed-by: Michael Paquier <michael@paquier.xyz>Reviewed-by: Robert Haas <robertmhaas@gmail.com>Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>https://postgr.es/m/20221120204310.xywrhyxyytsajuuq@awork3.anarazel.de
1 parentbd82928 commit92daeca

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

‎doc/src/sgml/monitoring.sgml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2289,6 +2289,10 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
22892289
<entry>Waiting while sending synchronization requests to the
22902290
checkpointer, because the request queue is full.</entry>
22912291
</row>
2292+
<row>
2293+
<entry><literal>SpinDelay</literal></entry>
2294+
<entry>Waiting while acquiring a contended spinlock.</entry>
2295+
</row>
22922296
<row>
22932297
<entry><literal>VacuumDelay</literal></entry>
22942298
<entry>Waiting in a cost-based vacuum delay point.</entry>

‎src/backend/storage/lmgr/s_lock.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include"common/pg_prng.h"
5454
#include"port/atomics.h"
5555
#include"storage/s_lock.h"
56+
#include"utils/wait_event.h"
5657

5758
#defineMIN_SPINS_PER_DELAY 10
5859
#defineMAX_SPINS_PER_DELAY 1000
@@ -136,7 +137,17 @@ perform_spin_delay(SpinDelayStatus *status)
136137
if (status->cur_delay==0)/* first time to delay? */
137138
status->cur_delay=MIN_DELAY_USEC;
138139

140+
/*
141+
* Once we start sleeping, the overhead of reporting a wait event is
142+
* justified. Actively spinning easily stands out in profilers, but
143+
* sleeping with an exponential backoff is harder to spot...
144+
*
145+
* We might want to report something more granular at some point, but
146+
* this is better than nothing.
147+
*/
148+
pgstat_report_wait_start(WAIT_EVENT_SPIN_DELAY);
139149
pg_usleep(status->cur_delay);
150+
pgstat_report_wait_end();
140151

141152
#if defined(S_LOCK_TEST)
142153
fprintf(stdout,"*");

‎src/backend/utils/activity/wait_event.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,9 @@ pgstat_get_wait_timeout(WaitEventTimeout w)
497497
caseWAIT_EVENT_REGISTER_SYNC_REQUEST:
498498
event_name="RegisterSyncRequest";
499499
break;
500+
caseWAIT_EVENT_SPIN_DELAY:
501+
event_name="SpinDelay";
502+
break;
500503
caseWAIT_EVENT_VACUUM_DELAY:
501504
event_name="VacuumDelay";
502505
break;

‎src/include/utils/wait_event.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ typedef enum
145145
WAIT_EVENT_RECOVERY_APPLY_DELAY,
146146
WAIT_EVENT_RECOVERY_RETRIEVE_RETRY_INTERVAL,
147147
WAIT_EVENT_REGISTER_SYNC_REQUEST,
148+
WAIT_EVENT_SPIN_DELAY,
148149
WAIT_EVENT_VACUUM_DELAY,
149150
WAIT_EVENT_VACUUM_TRUNCATE
150151
}WaitEventTimeout;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp