From 3fe84f82537732ae2240e6e87d970d9193e01c93 Mon Sep 17 00:00:00 2001 From: Tatsuo Ishii Date: Mon, 29 Jan 2018 13:53:18 +0900 Subject: [PATCH] Set TCP_NODELAY and non blocking to frontend socket. 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 | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/protocol/child.c b/src/protocol/child.c index 9cf1544ab..066b03581 100644 --- a/src/protocol/child.c +++ b/src/protocol/child.c @@ -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 @@ -1866,6 +1866,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; @@ -2037,6 +2038,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); -- 2.39.5