From: Artemiy Ryabinkov <getlag@ya.ru>
To: pgsql-general@postgresql.org
Subject: Why does backend send buffer size hardcoded at 8KB?
Date: Sat, 27 Jul 2019 14:43:54 +0300
Message-ID: <0cdc5485-cb3c-5e16-4a46-e3b2f7a41322@ya.ru> (raw)
Why backend send buffer use exactly 8KB?
(https://github.com/postgres/postgres/blob/249d64999615802752940e017ee5166e726bc7cd/src/backend/libpq...)
I had this question when I try to measure the speed of reading data. The
bottleneck was a read syscall. With strace I found that in most cases
read returns 8192 bytes (https://pastebin.com/LU10BdBJ). With tcpdump we
can confirm, that network packets have size 8192
(https://pastebin.com/FD8abbiA)
So, with well-tuned networking stack, the limit is 8KB. The reason is
the hardcoded size of Postgres write buffer.
I found discussion, where Tom Lane says that the reason of this limit is
the size of pipe buffers in Unix machines:
https://www.postgresql.org/message-id/9426.1388761242%40sss.pgh.pa.us
> Traditionally, at least, that was the size of pipe buffers in Unix
machines, so in principle this is the most optimal chunk size for
sending data across a Unix socket. I have no idea though if that's
still true in kernels in common use today. For TCP communication it
might be marginally better to find out the MTU size and use that; but
it's unclear that it's worth the trouble, or indeed that we can
know the end-to-end MTU size with any reliability.
Does it make sense to make this parameter configurable?
--
Artemiy Ryabinkov
getlag(at)ya(dot)ru
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: getlag@ya.ru
Subject: Re: Why does backend send buffer size hardcoded at 8KB?
In-Reply-To: <0cdc5485-cb3c-5e16-4a46-e3b2f7a41322@ya.ru>
References: <0cdc5485-cb3c-5e16-4a46-e3b2f7a41322@ya.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox