Permalink
Browse files

Limit listen(2)'s backlog parameter to num_init_children*2 at largest.

This is almost same algorithm as PostgreSQL.
I hope pgpool-II does not consume so much system resource any more...
  • Loading branch information...
1 parent 5bac118 commit b9e0eadbefa1042fcc19d04b756a589d348e86e5 t-ishii committed Nov 14, 2009
Showing with 7 additions and 2 deletions.
  1. +7 −2 main.c
View
9 main.c
@@ -1,6 +1,6 @@
/* -*-pgsql-c-*- */
/*
- * $Header: /cvsroot/pgpool/pgpool-II/main.c,v 1.54 2009/11/10 02:24:41 t-ishii Exp $
+ * $Header: /cvsroot/pgpool/pgpool-II/main.c,v 1.55 2009/11/14 11:36:35 t-ishii Exp $
*
* pgpool: a language independent connection pool server for PostgreSQL
* written by Tatsuo Ishii
@@ -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));

0 comments on commit b9e0ead

Please sign in to comment.