Set TCP_NODELAY and non blocking to frontend socket.
authorTatsuo Ishii <ishii@postgresql.org>
Mon, 29 Jan 2018 04:53:18 +0000 (13:53 +0900)
committerTatsuo Ishii <ishii@postgresql.org>
Mon, 29 Jan 2018 04:56:23 +0000 (13:56 +0900)
TCP_NODELAY is employed by PostgreSQL, so do we it.

Listen fd is set to non blocking. To make sure accept fd is set to non
blocking.

src/protocol/child.c

index 2e686186348b0c92bcf095e7df692f6a3402b4f8..17995924b22bda1c2282af4d98d8f383c26266f3 100644 (file)
@@ -5,7 +5,7 @@
  * pgpool: a language independent connection pool server for PostgreSQL
  * written by Tatsuo Ishii
  *
- * Copyright (c) 2003-2017     PgPool Global Development Group
+ * Copyright (c) 2003-2018     PgPool Global Development Group
  *
  * Permission to use, copy, modify, and distribute this software and
  * its documentation for any purpose and without fee is hereby
@@ -1895,6 +1895,7 @@ wait_for_new_connections(int *fds, struct timeval *timeout, SockAddr *saddr)
        int fd = 0;
        int afd;
        int *walk;
+       int on;
 
 #ifdef ACCEPT_PERFORMANCE
        struct timeval now1, now2;
@@ -2043,6 +2044,30 @@ wait_for_new_connections(int *fds, struct timeval *timeout, SockAddr *saddr)
                return RETRY;
 
        }
+
+       /*
+        * Set no delay if AF_INET socket. Not sure if this is really necessary
+        * but PostgreSQL does this.
+        */
+       if (!FD_ISSET(fds[0], &rmask))  /* fds[0] is UNIX domain socket */
+       {
+               on = 1;
+               if (setsockopt(afd, IPPROTO_TCP, TCP_NODELAY,
+                                          (char *) &on,
+                                          sizeof(on)) < 0)
+               {
+                       ereport(WARNING,
+                                       (errmsg("wait_for_new_connections: setsockopt failed with error \"%s\"",strerror(errno))));
+                       close(afd);
+                       return -1;
+               }
+       }
+
+       /*
+        * Make sure that the socket is non blocking.
+        */
+       pool_unset_nonblock(afd);
+
 #ifdef ACCEPT_PERFORMANCE
        gettimeofday(&now2,0);
        atime += (now2.tv_sec - now1.tv_sec)*1000000 + (now2.tv_usec - now1.tv_usec);