diff options
author | antirez <antirez@gmail.com> | 2014-12-04 10:54:31 +0100 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2014-12-04 11:02:53 +0100 |
commit | c3846becae5528e2987865ec1a5ef2cdeca3dadd (patch) | |
tree | 0d55107c8175203e9e0a7931183049209b7bd5e2 | |
parent | 1b732c09d010cfeee57a55e3d30e93ec6f535da8 (diff) | |
download | redis-c3846becae5528e2987865ec1a5ef2cdeca3dadd.tar.gz |
Check that tcp-backlog is matched by /proc/sys/net/core/somaxconn.
-rw-r--r-- | src/config.h | 1 | ||||
-rw-r--r-- | src/redis.c | 18 |
2 files changed, 19 insertions, 0 deletions
diff --git a/src/config.h b/src/config.h index 57d07599a..1f2919ed2 100644 --- a/src/config.h +++ b/src/config.h @@ -48,6 +48,7 @@ #define HAVE_PROC_STAT 1 #define HAVE_PROC_MAPS 1 #define HAVE_PROC_SMAPS 1 +#define HAVE_PROC_SOMAXCONN 1 #endif /* Test for task_info() */ diff --git a/src/redis.c b/src/redis.c index 25f9e568c..32b54e4fc 100644 --- a/src/redis.c +++ b/src/redis.c @@ -1621,6 +1621,23 @@ void adjustOpenFilesLimit(void) { } } +/* Check that server.tcp_backlog can be actually enforced in Linux according + * to the value of /proc/sys/net/core/somaxconn, or warn about it. */ +void checkTcpBacklogSettings(void) { +#ifdef HAVE_PROC_SOMAXCONN + FILE *fp = fopen("/proc/sys/net/core/somaxconn","r"); + char buf[1024]; + if (!fp) return; + if (fgets(buf,sizeof(buf),fp) != NULL) { + int somaxconn = atoi(buf); + if (somaxconn > 0 && somaxconn < server.tcp_backlog) { + redisLog(REDIS_WARNING,"WARNING: The TCP backlog setting of %d cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of %d.", server.tcp_backlog, somaxconn); + } + } + fclose(fp); +#endif +} + /* Initialize a set of file descriptors to listen to the specified 'port' * binding the addresses specified in the Redis server configuration. * @@ -3648,6 +3665,7 @@ int main(int argc, char **argv) { #ifdef __linux__ linuxMemoryWarnings(); #endif + checkTcpBacklogSettings(); loadDataFromDisk(); if (server.cluster_enabled) { if (verifyClusterConfigWithData() == REDIS_ERR) { |