Re: pgin.tcl pg_exec_prepared slow (was: Released...)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: L J Bayuk <ljb220(at)mindspring(dot)com>
Cc: "Nigel J(dot) Andrews" <nandrews(at)investsystems(dot)co(dot)uk>, pgsql-interfaces(at)postgresql(dot)org
Subject: Re: pgin.tcl pg_exec_prepared slow (was: Released...)
Date: 2004-07-06 02:43:47
Message-ID: 14766.1089081827@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

L J Bayuk <ljb220(at)mindspring(dot)com> writes:
> The delay we are seeing (about 40 ms) is from the time the client sends the
> Bind message to PostgreSQL until it gets a TCP ACK back. (It should get
> a BindComplete message back, but the backend does't flush after sending
> this - no pq_flush() at the end of exec_bind_message(). Hello, Tom, is this
> a bug?

No. If you wanted a flush just there, send a Flush message. But AFAICS
the only reason why you'd do that is if you needed to look at the
BindComplete before sending your next message --- which you do not.

> pgin.tcl sets its Tcl connection socket channel to "unbuffered",
> which means each PostgreSQL message it sends will be go into the TCP
> buffers immediately, since each message is written in a single "puts".

This is certainly bogus. A good implementation would arrange to flush
the TCP outbound queue immediately after sending either a Flush or a
Sync message --- and *no place else*. Those are exactly the points
where you are starting to wait for a backend reply. More frequent
flushing simply results in more separate network packets, which is not
a win. Also, if you haven't sent one of these message types, you are
not entitled to expect any immediate reply (which is essentially what's
happening with pgin.tcl, evidently).

The V3 protocol is designed around the assumption that each side will
batch multiple logical messages into single network packets whenever
possible. If you don't do this, it's not surprising that performance
sucks :-(

The reason error recovery is defined as doing skip-to-Sync is exactly
so that you can shove off a batch of messages without having first
checked the results of the earlier messages.

regards, tom lane

In response to

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Brijesh Shrivastav 2004-07-06 23:50:49 Libpq and transactions
Previous Message L J Bayuk 2004-07-06 01:07:31 Re: pgin.tcl pg_exec_prepared slow (was: Released...)