pgsql: Avoid needless large memcpys in libpq socket writing

Поиск
Список
Период
Сортировка
От David Rowley
Тема pgsql: Avoid needless large memcpys in libpq socket writing
Дата
Msg-id E1rtOho-000wy2-D8@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Avoid needless large memcpys in libpq socket writing

Until now, when calling pq_putmessage to write new data to a libpq
socket, all writes are copied into a buffer and that buffer gets flushed
when full to avoid having to perform small writes to the socket.

There are cases where we must write large amounts of data to the socket,
sometimes larger than the size of the buffer.  In this case, it's
wasteful to memcpy this data into the buffer and flush it out, instead,
we can send it directly from the memory location that the data is already
stored in.

Here we adjust internal_putbytes() so that after having just flushed the
buffer to the socket, if the remaining bytes to send is as big or bigger
than the buffer size, we just send directly rather than needlessly
copying into the PqSendBuffer buffer first.

Examples of operations that write large amounts of data in one message
are; outputting large tuples with SELECT or COPY TO STDOUT and
pg_basebackup.

Author: Melih Mutlu
Reviewed-by: Heikki Linnakangas
Reviewed-by: Jelte Fennema-Nio
Reviewed-by: David Rowley
Reviewed-by: Ranier Vilela
Reviewed-by: Andres Freund
Discussion: https://postgr.es/m/CAGPVpCR15nosj0f6xe-c2h477zFR88q12e6WjEoEZc8ZYkTh3Q@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/c4ab7da60617f020e8d75b1584d0754005d71830

Modified Files
--------------
src/backend/libpq/pqcomm.c | 74 +++++++++++++++++++++++++++++++++-------------
1 file changed, 53 insertions(+), 21 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Andres Freund
Дата:
Сообщение: [MASSMAIL]pgsql: Reduce branches in heapgetpage()'s per-tuple loop
Следующее
От: David Rowley
Дата:
Сообщение: pgsql: Enlarge bit-space for MemoryContextMethodID