-
-
Notifications
You must be signed in to change notification settings - Fork 500
Description
Hi all,
I'm a newbie to rust coming from a java background. I've been doing some comparisons between tokio-postgres and the postgres jdbc driver and was curious about some of the differences I saw. I'm splitting this off of #1212 since the questions aren't really related.
One difference I noticed was that when trying to do a "batch"-y operation (like pipelining requests), the tokio postgres driver would send a Sync message at the end of each query in the pipeline. On the other hand, jdbc would only send a Sync at the end of the batch. The result being that postgres would flush each response message separately back to the rust implementation.
Here's an example captured packet for the tokio pipelined query where the query Binds and Executes are bundled but the responses are split across packets:
Here's an example captured packet for the jdbc batch query and response, both being bundled:
I'm wondering, is it possible to somehow send only one Sync message for a sequence of pipelined queries? And if not, what exactly does the Sync do and are there any performance concerns I should keep in mind with the additional Syncs (besides the additional network overhead)?
Thanks!
Activity
sfackler commentedon Feb 10, 2025
The full details of Postgres's network protocol are described here: https://www.postgresql.org/docs/17/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY.
I'm not 100% sure what the perf difference would be, but the big behavior difference here is that these requests are pipelined, not batched - they all succeed or fail independently. In the batch workflow, the first error would cause the remainder of the commands to be skipped.
A sync message is 5 bytes on the wire so you are not going to realistically notice overhead on the raw networking side of things.