Limit listen(2)'s backlog parameter to num_init_children*2 at largest.
authorTatsuo Ishii <ishii at sraoss.co.jp>
Sat, 14 Nov 2009 11:36:35 +0000 (11:36 +0000)
committerTatsuo Ishii <ishii at sraoss.co.jp>
Sat, 14 Nov 2009 11:36:35 +0000 (11:36 +0000)
This is almost same algorithm as PostgreSQL.
I hope pgpool-II does not consume so much system resource any more...

main.c

diff --git a/main.c b/main.c
index 7b2ac126f91cfdf4efc65ea56e3da4a83cc8147b..ab047ee35c6ed42668d0128ffe5f875de6b7f398 100644 (file)
--- a/main.c
+++ b/main.c
@@ -853,6 +853,7 @@ static int create_inet_domain_socket(const char *hostname, const int port)
        int status;
        int one = 1;
        int len;
+       int backlog;
 
        fd = socket(AF_INET, SOCK_STREAM, 0);
        if (fd == -1)
@@ -902,7 +903,11 @@ static int create_inet_domain_socket(const char *hostname, const int port)
                myexit(1);
        }
 
-       status = listen(fd, PGPOOLMAXLITSENQUEUELENGTH);
+       backlog = pool_config->num_init_children * 2;
+       if (backlog > PGPOOLMAXLITSENQUEUELENGTH)
+               backlog = PGPOOLMAXLITSENQUEUELENGTH;
+
+       status = listen(fd, backlog);
        if (status < 0)
        {
                pool_error("listen() failed. reason: %s", strerror(errno));