On Tue, 30 Jan 2024 at 19:48, Robert Haas <robertmh...@gmail.com> wrote:
>
> On Tue, Jan 30, 2024 at 12:58 PM Melih Mutlu <m.melihmu...@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 believe it will stay empty forever if 
> > we do not copy anything when the buffer is empty. We can maybe simply set 
> > the threshold to the buffer size/2 (4kB) and hope that will work better. Or 
> > copy the data only if it fits into the remaining space in 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 send it. Unfortunately, I don't have strong numbers to 
> > demonstrate any improvement in perf or timing yet. But I still like to 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.


Reply via email to