Re: Unportable implementation of background worker start
Andres Freund <andres@anarazel.de>
On 2017-04-21 23:50:41 -0400, Tom Lane wrote: > I wrote: > > Attached is a lightly-tested draft patch that converts the postmaster to > > use a WaitEventSet for waiting in ServerLoop. I've got mixed emotions > > about whether this is the direction to proceed, though. > > Attached are a couple of patches that represent a plausible Plan B. > The first one changes the postmaster to run its signal handlers without > specifying SA_RESTART. I've confirmed that that seems to fix the > select_parallel-test-takes-a-long-time problem on gaur/pademelon. > The second one uses pselect, if available, to replace the unblock-signals/ > select()/block-signals dance in ServerLoop. On platforms where pselect > exists and works properly, that should fix the race condition I described > previously. On platforms where it doesn't, we're no worse off than > before. > > As mentioned in the comments for the second patch, even if we don't > have working pselect(), the only problem is that ServerLoop's response > to an interrupt might be delayed by as much as the up-to-1-minute timeout. > The only existing case where that's really bad is launching multiple > bgworkers. I would therefore advocate also changing maybe_start_bgworker > to start up to N bgworkers per call, where N is large enough to pretty > much always satisfy simultaneously-arriving requests. I'd pick 100 or > so, but am willing to negotiate. > > I think that these patches represent something we could back-patch > without a lot of trepidation, unlike the WaitEventSet-based approach. > Therefore, my proposal is to apply and backpatch these changes, and > call it good for v10. For v11, we could work on changing the postmaster > to not do work in signal handlers, as discussed upthread. That would > supersede these two patches completely, though I'd still advocate for > keeping the change in maybe_start_bgworker. > > Note: for testing purposes, these patches are quite independent; just > ignore the hunk in the second patch that changes a comment added by > the first one. Unclear if related, but https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=gharial&dt=2017-04-24%2019%3A30%3A42 has a suspicious timing of failing in a weird way. - Andres
Commits
-
Cope with glibc too old to have epoll_create1().
- 53b157846024 9.6.3 landed
- 82ebbeb0abfe 10.0 landed
-
Make latch.c more paranoid about child-process cases.
- fa31b6f4e969 10.0 landed
- 866452cd8b52 9.6.3 landed
-
Allow multiple bgworkers to be launched per postmaster iteration.
- aa1351f1eec4 10.0 landed
- e880df25ec35 9.6.3 landed
-
Revert "Use pselect(2) not select(2), if available, to wait in postmaster's loop."
- e615605239f6 9.6.3 landed
- 64925603c972 10.0 landed
-
Use pselect(2) not select(2), if available, to wait in postmaster's loop.
- b9515b628797 9.6.3 landed
- 81069a9efc5a 10.0 landed
-
Run the postmaster's signal handlers without SA_RESTART.
- 8939020853e6 10.0 landed
- dfa4baf91cee 9.6.3 landed
-
Fix postmaster's handling of fork failure for a bgworker process.
- dba1f310a564 9.5.7 landed
- 63f64d2824b2 9.6.3 landed
- 4fe04244b584 10.0 landed
- 436b560b86ca 9.4.12 landed
-
Partially revert commit 536d47bd9d5fce8d91929bee3128fa1d08dbcc57.
- 5041cdf2b792 10.0 landed
-
Avoid depending on non-POSIX behavior of fcntl(2).
- 3e51725b3854 10.0 landed
- f07f6b62c9a7 9.6.3 landed
- ce521e50eb56 9.4.12 landed
- ad8fb69cccf4 9.2.21 landed
- 9f8be7542156 9.5.7 landed
- 899960b9fec2 9.3.17 landed
-
Remove long-obsolete catering for platforms without F_SETFD/FD_CLOEXEC.
- 536d47bd9d5f 10.0 landed