diff options
author | Tom Lane | 2001-07-11 19:03:07 +0000 |
---|---|---|
committer | Tom Lane | 2001-07-11 19:03:07 +0000 |
commit | d94174ef4bffb3b3501ae98669ae80d005da05d2 (patch) | |
tree | 909cd4a65e7394b99e8ca282b5d72518a6fe698b | |
parent | aa6d70b5277f5b80f2d39fd6f04a258e9659fc22 (diff) |
Instead of believing SOMAXCONN from the system header files (which is
a lie on many Unixen), invoke listen() with MIN(MaxBackends*2, 10000).
The clamp value 10000 is configurable in config.h.in, if that proves
to be necessary --- hopefully it won't.
-rw-r--r-- | src/backend/libpq/pqcomm.c | 26 | ||||
-rw-r--r-- | src/include/config.h.in | 10 |
2 files changed, 30 insertions, 6 deletions
diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c index 844c9d9cbd..3293ea47a7 100644 --- a/src/backend/libpq/pqcomm.c +++ b/src/backend/libpq/pqcomm.c @@ -80,11 +80,6 @@ #include "miscadmin.h" -#ifndef SOMAXCONN -#define SOMAXCONN 5 /* from Linux listen(2) man page */ -#endif - - static void pq_close(void); @@ -185,6 +180,7 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber, SockAddr saddr; int fd, err; + int maxconn; size_t len = 0; int one = 1; @@ -350,7 +346,25 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber, } #endif /* HAVE_UNIX_SOCKETS */ - listen(fd, SOMAXCONN); + /* + * Select appropriate accept-queue length limit. PG_SOMAXCONN is + * only intended to provide a clamp on the request on platforms where + * an overly large request provokes a kernel error (are there any?). + */ + maxconn = MaxBackends * 2; + if (maxconn > PG_SOMAXCONN) + maxconn = PG_SOMAXCONN; + + err = listen(fd, maxconn); + if (err < 0) + { + snprintf(PQerrormsg, PQERRORMSG_LENGTH, + "FATAL: StreamServerPort: listen() failed: %s\n", + strerror(errno)); + fputs(PQerrormsg, stderr); + pqdebug("%s", PQerrormsg); + return STATUS_ERROR; + } *fdP = fd; diff --git a/src/include/config.h.in b/src/include/config.h.in index ed0b5832e1..934abd537e 100644 --- a/src/include/config.h.in +++ b/src/include/config.h.in @@ -233,6 +233,16 @@ #define DEFAULT_MAX_EXPR_DEPTH 10000 /* + * PG_SOMAXCONN: maximum accept-queue length limit passed to listen(2). + * You'd think we should use SOMAXCONN from <sys/socket.h>, but on many + * systems that symbol is much smaller than the kernel's actual limit. + * In any case, this symbol need be twiddled only if you have a kernel + * that refuses large limit values, rather than silently reducing the + * value to what it can handle (which is what most if not all Unixen do). + */ +#define PG_SOMAXCONN 10000 + +/* * You can try changing this if you have a machine with bytes of another * size, but no guarantee... */ |