Re: Flushing large data immediately in pqcomm

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Jelte Fennema-Nio <postgres(at)jeltef(dot)nl>
Cc: Melih Mutlu <m(dot)melihmutlu(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
Subject: Re: Flushing large data immediately in pqcomm
Date: 2024-03-21 11:41:56
Message-ID: CAApHDvoD_K0vojCO7QKyR8+=ZJXCv2tFy=n2MQ4c5+cXjvVt0A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, 21 Mar 2024 at 22:44, Jelte Fennema-Nio <postgres(at)jeltef(dot)nl> wrote:
>
> On Thu, 21 Mar 2024 at 01:45, David Rowley <dgrowleyml(at)gmail(dot)com> wrote:
> > As I understand the code, there's no problem calling
> > internal_flush_buffer() when the buffer is empty and I suspect that if
> > we're sending a few buffers with "len > PqSendBufferSize" that it's
> > just so unlikely that the buffer is empty that we should just do the
> > function call and let internal_flush_buffer() handle doing nothing if
> > the buffer really is empty. I think the chances of
> > internal_flush_buffer() having to do exactly nothing here is less than
> > 1 in 8192, so I just don't think the check is worthwhile.
>
> I think you're missing the exact case that we're trying to improve
> here: Calls to internal_putbytes with a very large len, e.g. 1MB.
> With the new code the buffer will be empty ~50% of the time (not less
> than 1 in 8192) with such large buffers, because the flow that will
> happen:

It was the code I misread. I understand what the aim is. I failed to
notice the while loop in internal_putbytes(). So what I mentioned
about trying to fill the buffer before flushing already happens. I
now agree that the PqSendStart == PqSendPointer test. I'd say since
the reported regression was with 100 byte rows that testing "len >=
PqSendBufferSize" before PqSendStart == PqSendPointer makes sense.

David

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Ed Behn 2024-03-21 11:48:57 NLS for extension
Previous Message Fujii.Yuki@df.MitsubishiElectric.co.jp 2024-03-21 11:37:50 RE: Partial aggregates pushdown