Re: [HACKERS] SO_SNDBUF size is small on win32? - Mailing list pgsql-patches

From Bruce Momjian
Subject Re: [HACKERS] SO_SNDBUF size is small on win32?
Date
Msg-id 200608112044.k7BKiNr10009@momjian.us
Whole thread Raw
Responses Re: [HACKERS] SO_SNDBUF size is small on win32?  (Yoshiyuki Asaba <y-asaba@sraoss.co.jp>)
List pgsql-patches
Yoshiyuki Asaba wrote:
> Hi,
>
> I see a performance issue on win32. This problem is causes by the
> following URL.
>
> http://support.microsoft.com/kb/823764/EN-US/
>
> On win32, default SO_SNDBUF value is 8192 bytes. And libpq's buffer is
> 8192 too.
>
> pqcomm.c:117
>   #define PQ_BUFFER_SIZE 8192
>
> send() may take as long as 200ms. So, I think we should increase
> SO_SNDBUF to more than 8192. I attache the patch.

Based on this patch and comments, I have applied a patch that sets the
buffer to 32k, and adds the URL in a comment.  I think there was
concensus that there is no need for this to be used on the client side,
only the server.

Thanks.

--
  Bruce Momjian   bruce@momjian.us
  EnterpriseDB    http://www.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +
Index: src/backend/libpq/pqcomm.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v
retrieving revision 1.186
diff -c -c -r1.186 pqcomm.c
*** src/backend/libpq/pqcomm.c    14 Jul 2006 05:28:27 -0000    1.186
--- src/backend/libpq/pqcomm.c    11 Aug 2006 20:41:35 -0000
***************
*** 593,598 ****
--- 593,612 ----
              return STATUS_ERROR;
          }

+ #ifdef WIN32
+         /*
+          *    This is a Win32 socket optimization.  The ideal size is 32k.
+          *    http://support.microsoft.com/kb/823764/EN-US/
+          */
+         on = PQ_BUFFER_SIZE * 4;
+         if (setsockopt(port->sock, SOL_SOCKET, SO_SNDBUF, (char *) &on,
+             sizeof(on)) < 0)
+         {
+             elog(LOG, "setsockopt(SO_SNDBUF) failed: %m");
+             return STATUS_ERROR;
+         }
+ #endif
+
          /*
           * Also apply the current keepalive parameters.  If we fail to set a
           * parameter, don't error out, because these aren't universally

pgsql-patches by date:

Previous
From: Ron Mayer
Date:
Subject: Re: [HACKERS] Maintaining cluster order on insert
Next
From: Heikki Linnakangas
Date:
Subject: Re: [HACKERS] Maintaining cluster order on insert