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

Commitc6c9474

Browse files
committed
Use condition variables to wait for checkpoints.
Previously we used a polling/sleeping loop to wait for checkpointsto begin and end, which leads to up to a couple hundred millisecondsof needless thumb-twiddling. Use condition variables instead.Author: Thomas MunroReviewed-by: Andres FreundDiscussion:https://postgr.es/m/CA%2BhUKGLY7sDe%2Bbg1K%3DbnEzOofGoo4bJHYh9%2BcDCXJepb6DQmLw%40mail.gmail.com
1 parent5655565 commitc6c9474

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

‎doc/src/sgml/monitoring.sgml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,7 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
12811281
<entry>Waiting in an extension.</entry>
12821282
</row>
12831283
<row>
1284-
<entry morerows="34"><literal>IPC</literal></entry>
1284+
<entry morerows="36"><literal>IPC</literal></entry>
12851285
<entry><literal>BgWorkerShutdown</literal></entry>
12861286
<entry>Waiting for background worker to shut down.</entry>
12871287
</row>
@@ -1293,6 +1293,14 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
12931293
<entry><literal>BtreePage</literal></entry>
12941294
<entry>Waiting for the page number needed to continue a parallel B-tree scan to become available.</entry>
12951295
</row>
1296+
<row>
1297+
<entry><literal>CheckpointDone</literal></entry>
1298+
<entry>Waiting for a checkpoint to complete.</entry>
1299+
</row>
1300+
<row>
1301+
<entry><literal>CheckpointStart</literal></entry>
1302+
<entry>Waiting for a checkpoint to start.</entry>
1303+
</row>
12961304
<row>
12971305
<entry><literal>ClogGroupUpdate</literal></entry>
12981306
<entry>Waiting for group leader to update transaction status at transaction end.</entry>

‎src/backend/postmaster/checkpointer.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ typedef struct
126126

127127
intckpt_flags;/* checkpoint flags, as defined in xlog.h */
128128

129+
ConditionVariablestart_cv;/* signaled when ckpt_started advances */
130+
ConditionVariabledone_cv;/* signaled when ckpt_done advances */
131+
129132
uint32num_backend_writes;/* counts user backend buffer writes */
130133
uint32num_backend_fsync;/* counts user backend fsync calls */
131134

@@ -428,6 +431,8 @@ CheckpointerMain(void)
428431
CheckpointerShmem->ckpt_started++;
429432
SpinLockRelease(&CheckpointerShmem->ckpt_lck);
430433

434+
ConditionVariableBroadcast(&CheckpointerShmem->start_cv);
435+
431436
/*
432437
* The end-of-recovery checkpoint is a real checkpoint that's
433438
* performed while we're still in recovery.
@@ -488,6 +493,8 @@ CheckpointerMain(void)
488493
CheckpointerShmem->ckpt_done=CheckpointerShmem->ckpt_started;
489494
SpinLockRelease(&CheckpointerShmem->ckpt_lck);
490495

496+
ConditionVariableBroadcast(&CheckpointerShmem->done_cv);
497+
491498
if (ckpt_performed)
492499
{
493500
/*
@@ -915,6 +922,8 @@ CheckpointerShmemInit(void)
915922
MemSet(CheckpointerShmem,0,size);
916923
SpinLockInit(&CheckpointerShmem->ckpt_lck);
917924
CheckpointerShmem->max_requests=NBuffers;
925+
ConditionVariableInit(&CheckpointerShmem->start_cv);
926+
ConditionVariableInit(&CheckpointerShmem->done_cv);
918927
}
919928
}
920929

@@ -1023,6 +1032,7 @@ RequestCheckpoint(int flags)
10231032
new_failed;
10241033

10251034
/* Wait for a new checkpoint to start. */
1035+
ConditionVariablePrepareToSleep(&CheckpointerShmem->start_cv);
10261036
for (;;)
10271037
{
10281038
SpinLockAcquire(&CheckpointerShmem->ckpt_lck);
@@ -1032,13 +1042,15 @@ RequestCheckpoint(int flags)
10321042
if (new_started!=old_started)
10331043
break;
10341044

1035-
CHECK_FOR_INTERRUPTS();
1036-
pg_usleep(100000L);
1045+
ConditionVariableSleep(&CheckpointerShmem->start_cv,
1046+
WAIT_EVENT_CHECKPOINT_START);
10371047
}
1048+
ConditionVariableCancelSleep();
10381049

10391050
/*
10401051
* We are waiting for ckpt_done >= new_started, in a modulo sense.
10411052
*/
1053+
ConditionVariablePrepareToSleep(&CheckpointerShmem->done_cv);
10421054
for (;;)
10431055
{
10441056
intnew_done;
@@ -1051,9 +1063,10 @@ RequestCheckpoint(int flags)
10511063
if (new_done-new_started >=0)
10521064
break;
10531065

1054-
CHECK_FOR_INTERRUPTS();
1055-
pg_usleep(100000L);
1066+
ConditionVariableSleep(&CheckpointerShmem->done_cv,
1067+
WAIT_EVENT_CHECKPOINT_DONE);
10561068
}
1069+
ConditionVariableCancelSleep();
10571070

10581071
if (new_failed!=old_failed)
10591072
ereport(ERROR,

‎src/backend/postmaster/pgstat.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3623,6 +3623,12 @@ pgstat_get_wait_ipc(WaitEventIPC w)
36233623
caseWAIT_EVENT_BTREE_PAGE:
36243624
event_name="BtreePage";
36253625
break;
3626+
caseWAIT_EVENT_CHECKPOINT_DONE:
3627+
event_name="CheckpointDone";
3628+
break;
3629+
caseWAIT_EVENT_CHECKPOINT_START:
3630+
event_name="CheckpointStart";
3631+
break;
36263632
caseWAIT_EVENT_CLOG_GROUP_UPDATE:
36273633
event_name="ClogGroupUpdate";
36283634
break;

‎src/include/pgstat.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,8 @@ typedef enum
817817
WAIT_EVENT_BGWORKER_STARTUP,
818818
WAIT_EVENT_BTREE_PAGE,
819819
WAIT_EVENT_CLOG_GROUP_UPDATE,
820+
WAIT_EVENT_CHECKPOINT_DONE,
821+
WAIT_EVENT_CHECKPOINT_START,
820822
WAIT_EVENT_EXECUTE_GATHER,
821823
WAIT_EVENT_HASH_BATCH_ALLOCATING,
822824
WAIT_EVENT_HASH_BATCH_ELECTING,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp