forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitbc971f4
committed
Optimize walsender wake up logic using condition variables
WalSndWakeup() currently loops through all the walsenders slots, with aspinlock acquisition and release for every iteration, to wake up waitingwalsenders.This commonly was not a problem beforee101dfa. But, to allow logicaldecoding on standbys, we need to wake up logical walsenders after every WALrecord is applied on the standby, rather just when flushing WAL or switchingtimelines. This causes a performance regression for workloads replaying a lotof WAL records.To solve this, we use condition variable (CV) to efficiently wake upwalsenders in WalSndWakeup().Every walsender prepares to sleep on a shared memory CV. Note that it justprepares to sleep on the CV (i.e., adds itself to the CV's waitlist), but doesnot actually wait on the CV (IOW, it never calls ConditionVariableSleep()). Itstill uses WaitEventSetWait() for waiting, because CV infrastructure doesn'thandle FeBe socket events currently. The processes (startup process,walreceiver etc.) wanting to wake up walsenders useConditionVariableBroadcast(), which in turn calls SetLatch(), helpingwalsenders come out of WaitEventSetWait().We use separate shared memory CVs for physical and logical walsenders forselective wake ups, see WalSndWakeup() for more details.This approach is simple and reasonably efficient. But not very elegant. Butfor 16 it seems to be a better path than a larger redesign of the CVmechanism. A desirable future improvement would be to add support for CVsinto WaitEventSetWait().This still leaves us with a small regression in very extreme workloads (due tothe spinlock acquisition in ConditionVariableBroadcast() when there are nowaiters) - but that seems acceptable.Reported-by: Andres Freund <andres@anarazel.de>Suggested-by: Andres Freund <andres@anarazel.de>Author: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>Reviewed-by: "Drouvot, Bertrand" <bertranddrouvot.pg@gmail.com>Reviewed-by: Zhijie Hou <houzj.fnst@fujitsu.com>Discussion:https://www.postgresql.org/message-id/20230509190247.3rrplhdgem6su6cg%40awork3.anarazel.de1 parent30579d2 commitbc971f4
File tree
2 files changed
+53
-24
lines changed- src
- backend/replication
- include/replication
2 files changed
+53
-24
lines changedLines changed: 48 additions & 24 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3309 | 3309 |
| |
3310 | 3310 |
| |
3311 | 3311 |
| |
| 3312 | + | |
| 3313 | + | |
| 3314 | + | |
3312 | 3315 |
| |
3313 | 3316 |
| |
3314 | 3317 |
| |
| |||
3330 | 3333 |
| |
3331 | 3334 |
| |
3332 | 3335 |
| |
3333 |
| - | |
3334 |
| - | |
3335 |
| - | |
3336 |
| - | |
3337 |
| - | |
3338 |
| - | |
3339 |
| - | |
3340 |
| - | |
3341 |
| - | |
3342 |
| - | |
3343 |
| - | |
3344 |
| - | |
3345 |
| - | |
3346 |
| - | |
3347 |
| - | |
3348 |
| - | |
3349 |
| - | |
3350 |
| - | |
3351 |
| - | |
3352 |
| - | |
| 3336 | + | |
| 3337 | + | |
| 3338 | + | |
| 3339 | + | |
| 3340 | + | |
| 3341 | + | |
| 3342 | + | |
| 3343 | + | |
3353 | 3344 |
| |
3354 |
| - | |
3355 |
| - | |
3356 |
| - | |
3357 |
| - | |
| 3345 | + | |
| 3346 | + | |
3358 | 3347 |
| |
3359 | 3348 |
| |
3360 | 3349 |
| |
| |||
3368 | 3357 |
| |
3369 | 3358 |
| |
3370 | 3359 |
| |
| 3360 | + | |
| 3361 | + | |
| 3362 | + | |
| 3363 | + | |
| 3364 | + | |
| 3365 | + | |
| 3366 | + | |
| 3367 | + | |
| 3368 | + | |
| 3369 | + | |
| 3370 | + | |
| 3371 | + | |
| 3372 | + | |
| 3373 | + | |
| 3374 | + | |
| 3375 | + | |
| 3376 | + | |
| 3377 | + | |
| 3378 | + | |
| 3379 | + | |
| 3380 | + | |
| 3381 | + | |
| 3382 | + | |
| 3383 | + | |
| 3384 | + | |
| 3385 | + | |
| 3386 | + | |
| 3387 | + | |
| 3388 | + | |
| 3389 | + | |
3371 | 3390 |
| |
3372 | 3391 |
| |
| 3392 | + | |
| 3393 | + | |
3373 | 3394 |
| |
| 3395 | + | |
| 3396 | + | |
| 3397 | + | |
3374 | 3398 |
| |
3375 | 3399 |
| |
3376 | 3400 |
| |
|
Lines changed: 5 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
17 | 17 |
| |
18 | 18 |
| |
19 | 19 |
| |
| 20 | + | |
20 | 21 |
| |
21 | 22 |
| |
22 | 23 |
| |
| |||
108 | 109 |
| |
109 | 110 |
| |
110 | 111 |
| |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
111 | 116 |
| |
112 | 117 |
| |
113 | 118 |
| |
|
0 commit comments
Comments
(0)