Use a nonblocking socket for FE/BE communication and block using latches.
authorAndres Freund <andres@anarazel.de>
Tue, 3 Feb 2015 21:03:48 +0000 (22:03 +0100)
committerAndres Freund <andres@anarazel.de>
Tue, 3 Feb 2015 21:03:48 +0000 (22:03 +0100)
commit387da18874afa17156ee3af63766f17efb53c4b9
tree642eaff88114b0ac3be59397c3e96a66f93a7ebd
parent778d498c7d9099c784f14199a319ec2a84d91191
Use a nonblocking socket for FE/BE communication and block using latches.

This allows to introduce more elaborate handling of interrupts while
reading from a socket.  Currently some interrupt handlers have to do
significant work from inside signal handlers, and it's very hard to
correctly write code to do so.  Generic signal handler limitations,
combined with the fact that we can't safely jump out of a signal
handler while reading from the client have prohibited implementation
of features like timeouts for idle-in-transaction.

Additionally we use the latch code to wait in a couple places where we
previously only had waiting code on windows as other platforms just
busy looped.

This can increase the number of systemcalls happening during FE/BE
communication. Benchmarks so far indicate that the impact isn't very
high, and there's room for optimization in the latch code. The chance
of cleaning up the usage of latches gives us, seem to outweigh the
risk of small performance regressions.

This commit theoretically can't used without the next patch in the
series, as WaitLatchOrSocket is not defined to be fully signal
safe. As we already do that in some cases though, it seems better to
keep the commits separate, so they're easier to understand.

Author: Andres Freund
Reviewed-By: Heikki Linnakangas
src/backend/libpq/be-secure-openssl.c
src/backend/libpq/be-secure.c
src/backend/libpq/pqcomm.c