shm_mq: Update mq_bytes_written less often.
authorRobert Haas <rhaas@postgresql.org>
Thu, 14 Oct 2021 20:06:43 +0000 (16:06 -0400)
committerRobert Haas <rhaas@postgresql.org>
Thu, 14 Oct 2021 20:13:36 +0000 (16:13 -0400)
commit46846433a03dff4f2e08c8a161e54a842da360d6
tree668e9ff626ab6b3b8708dcb4e6b27748db6d7a66
parent7821a0bf2096df659671924fbeef0ebc66449292
shm_mq: Update mq_bytes_written less often.

Do not update shm_mq's mq_bytes_written until we have written
an amount of data greater than 1/4th of the ring size, unless
the caller of shm_mq_send(v) requests a flush at the end of
the message. This reduces the number of calls to SetLatch(),
and also the number of CPU cache misses, considerably, and thus
makes shm_mq significantly faster.

Dilip Kumar, reviewed by Zhihong Yu and Tomas Vondra. Some
minor cosmetic changes by me.

Discussion: http://postgr.es/m/CAFiTN-tVXqn_OG7tHNeSkBbN+iiCZTiQ83uakax43y1sQb2OBA@mail.gmail.com
src/backend/executor/tqueue.c
src/backend/libpq/pqmq.c
src/backend/storage/ipc/shm_mq.c
src/include/storage/shm_mq.h
src/test/modules/test_shm_mq/test.c
src/test/modules/test_shm_mq/worker.c