Re: Flushing large data immediately in pqcomm - Mailing list pgsql-hackers

From Jelte Fennema-Nio
Subject Re: Flushing large data immediately in pqcomm
Date
Msg-id CAGECzQTYUhnC1bO=zNiSpUgCs=hCYxVHvLD2doXNx3My6ZAC2w@mail.gmail.com
Whole thread Raw
In response to Re: Flushing large data immediately in pqcomm  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: Flushing large data immediately in pqcomm
List pgsql-hackers
On Tue, 30 Jan 2024 at 19:48, Robert Haas <robertmhaas@gmail.com> wrote:
>
> On Tue, Jan 30, 2024 at 12:58 PM Melih Mutlu <m.melihmutlu@gmail.com> wrote:
> > Sounds like it's difficult to come up with a heuristic that would work well enough for most cases.
> > One thing with sending data instead of copying it if the buffer is empty is that initially the buffer is empty. I
believeit will stay empty forever if we do not copy anything when the buffer is empty. We can maybe simply set the
thresholdto the buffer size/2 (4kB) and hope that will work better. Or copy the data only if it fits into the remaining
spacein the buffer. What do you think? 
> >
> > An additional note while I mentioned pq_putmessage_noblock(), I've been testing sending input data immediately in
pq_putmessage_noblock()without blocking and copy the data into PqSendBuffer only if the socket would block and cannot
sendit. Unfortunately, I don't have strong numbers to demonstrate any improvement in perf or timing yet. But I still
liketo know what would you think about it? 
>
> I think this is an area where it's very difficult to foresee on
> theoretical grounds what will be right in practice

I agree that it's hard to prove that such heuristics will always be
better in practice than the status quo. But I feel like we shouldn't
let perfect be the enemy of good here. I one approach that is a clear
improvement over the status quo is:
1. If the buffer is empty AND the data we are trying to send is larger
than the buffer size, then don't use the buffer.
2. If not, fill up the buffer first (just like we do now) then send
that. And if the left over data is then still larger than the buffer,
then now the buffer is empty so 1. applies.



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: 003_extrafiles.pl test fails on Windows with the newer Perl versions
Next
From: Andrew Dunstan
Date:
Subject: Re: 003_extrafiles.pl test fails on Windows with the newer Perl versions