Add PQsendSyncMessage() to libpq - Mailing list pgsql-hackers

From Anton Kirilov
Subject Add PQsendSyncMessage() to libpq
Date
Msg-id CACV6eE5arHFZEA717=iKEa_OewpVFfWJOmsOdGrqqsr8CJVfWQ@mail.gmail.com
Whole thread Raw
Responses Re: Add PQsendSyncMessage() to libpq  (Denis Laxalde <denis.laxalde@dalibo.com>)
Re: Add PQsendSyncMessage() to libpq  (Robert Haas <robertmhaas@gmail.com>)
List 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

pgsql-hackers by date:

Previous
From: Cary Huang
Date:
Subject: Re: pgbench - adding pl/pgsql versions of tests
Next
From: Jeff Davis
Date:
Subject: Re: ICU locale validation / canonicalization