postgresql/src
Tom Lane 09cf1d5226 Improve timeout.c's handling of repeated timeout set/cancel.
A very common usage pattern is that we set a timeout that we don't
expect to reach, cancel it after a little bit, and later repeat.
With the original implementation of timeout.c, this results in one
setitimer() call per timeout set or cancel.  We can do a lot better
by being lazy about changing the timeout interrupt request, namely:
(1) never cancel the outstanding interrupt, even when we have no
active timeout events;
(2) if we need to set an interrupt, but there already is one pending
at or before the required time, leave it alone.  When the interrupt
happens, the signal handler will reschedule it at whatever time is
then needed.

For example, with a one-second setting for statement_timeout, this
method results in having to interact with the kernel only a little
more than once a second, no matter how many statements we execute
in between.  The mainline code might never call setitimer() at all
after the first time, while each time the signal handler fires,
it sees that the then-pending request is most of a second away,
and that's when it sets the next interrupt request for.  Each
mainline timeout-set request after that will observe that the time
it wants is past the pending interrupt request time, and do nothing.

This also works pretty well for cases where a few different timeout
lengths are in use, as long as none of them are very short.  But
that describes our usage well.

Idea and original patch by Thomas Munro; I fixed a race condition
and improved the comments.

Discussion: https://postgr.es/m/CA+hUKG+o6pbuHBJSGnud=TadsuXySWA7CCcPgCt2QE9F6_4iHQ@mail.gmail.com
2021-01-06 18:28:52 -05:00
..
backend Improve timeout.c's handling of repeated timeout set/cancel. 2021-01-06 18:28:52 -05:00
bin Promote --data-checksums to the common set of options in initdb --help 2021-01-06 10:52:26 +09:00
common Update copyright for 2021 2021-01-02 13:06:25 -05:00
fe_utils Update copyright for 2021 2021-01-02 13:06:25 -05:00
include Report progress of COPY commands 2021-01-06 21:51:06 +01:00
interfaces Re-implement pl/pgsql's expression and assignment parsing. 2021-01-04 11:52:00 -05:00
makefiles Remove libpq.rc, use win32ver.rc for libpq 2020-01-15 15:06:12 +01:00
pl Rethink the "read/write parameter" mechanism in pl/pgsql. 2021-01-04 12:39:27 -05:00
port Update copyright for 2021 2021-01-02 13:06:25 -05:00
template On macOS, use -isysroot in link steps as well as compile steps. 2020-11-20 00:07:09 -05:00
test Report progress of COPY commands 2021-01-06 21:51:06 +01:00
timezone Update copyright for 2021 2021-01-02 13:06:25 -05:00
tools Replace remaining uses of "whitelist". 2021-01-05 14:00:16 +13:00
tutorial Update copyright for 2021 2021-01-02 13:06:25 -05:00
.gitignore Convert cvsignore to gitignore, and add .gitignore for build targets. 2010-09-22 12:57:04 +02:00
DEVELOPERS
Makefile Remove the option to build thread_test.c outside configure. 2020-10-21 12:08:48 -04:00
Makefile.global.in Split Makefile symbol CFLAGS_VECTOR into two symbols. 2020-09-06 21:28:16 -04:00
Makefile.shlib Add PostgreSQL home page to --help output 2020-02-28 13:12:21 +01:00
nls-global.mk NLS: Fix backend gettext triggers 2019-09-23 09:04:20 +02:00