Add PQsendSyncMessage() to libpq

From: Anton Kirilov <antonvkirilov(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Add PQsendSyncMessage() to libpq
Date: 2023-03-24 22:38:48
Message-ID: CACV6eE5arHFZEA717=iKEa_OewpVFfWJOmsOdGrqqsr8CJVfWQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello,

Recently I have been trying to use libpq's pipeline mode in a project,
and in the process I have noticed that the PQpipelineSync() function
has a deficiency (which, to be fair, could be an advantage in other
situations): It combines the establishment of a synchronization point
in a pipeline with a send buffer flush, i.e. a system call. In my use
case I build up a pipeline of several completely independent queries,
so a synchronization point is required between each of them, but
performing a system call for each is just unnecessary overhead,
especially if the system is severely affected by any mitigations for
Spectre or other security vulnerabilities. That's why I propose to add
an interface to libpq to establish a synchronization point in a
pipeline without performing any further actions.

I have attached a patch that introduces PQsendSyncMessage(), a
function that is equivalent to PQpipelineSync(), except that it does
not flush anything to the server; the user must subsequently call
PQflush() instead. Alternatively, the new function is equivalent to
PQsendFlushRequest(), except that it sends a sync message instead of a
flush request. In addition to reducing the system call overhead of
libpq's pipeline mode, it also makes it easier for the operating
system to send as much of the pipeline as possible in a single TCP (or
lower level protocol) packet when the database is running remotely.

I would appeciate your thoughts on my proposal.

Best wishes,
Anton Kirilov

Attachment Content-Type Size
v1-0001-Add-PQsendSyncMessage-to-libpq.patch application/x-patch 13.5 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeff Davis 2023-03-24 23:28:24 Re: ICU locale validation / canonicalization
Previous Message Cary Huang 2023-03-24 22:17:33 Re: pgbench - adding pl/pgsql versions of tests