diff --git a/src/redis.c b/src/redis.c index 6955137554a7ad9b6dca77b70caf9c1b504ea668..853ef5c8eabec89861d01211921493ce15597da3 100644 --- a/src/redis.c +++ b/src/redis.c @@ -1491,20 +1491,20 @@ void initServerConfig() { /* This function will try to raise the max number of open files accordingly to * the configured max number of clients. It also reserves a number of file - * descriptors (REDIS_EVENTLOOP_FDSET_INCR) for extra operations of + * descriptors (REDIS_MIN_RESERVED_FDS) for extra operations of * persistence, listening sockets, log files and so forth. * * If it will not be possible to set the limit accordingly to the configured * max number of clients, the function will do the reverse setting * server.maxclients to the value that we can actually handle. */ void adjustOpenFilesLimit(void) { - rlim_t maxfiles = server.maxclients+REDIS_EVENTLOOP_FDSET_INCR; + rlim_t maxfiles = server.maxclients+REDIS_MIN_RESERVED_FDS; struct rlimit limit; if (getrlimit(RLIMIT_NOFILE,&limit) == -1) { redisLog(REDIS_WARNING,"Unable to obtain the current NOFILE limit (%s), assuming 1024 and setting the max clients configuration accordingly.", strerror(errno)); - server.maxclients = 1024-REDIS_EVENTLOOP_FDSET_INCR; + server.maxclients = 1024-REDIS_MIN_RESERVED_FDS; } else { rlim_t oldlimit = limit.rlim_cur; @@ -1518,7 +1518,7 @@ void adjustOpenFilesLimit(void) { limit.rlim_cur = f; limit.rlim_max = f; if (setrlimit(RLIMIT_NOFILE,&limit) != -1) break; - f -= REDIS_EVENTLOOP_FDSET_INCR; + f -= REDIS_MIN_RESERVED_FDS; if (f > limit.rlim_cur) { /* Instead of getting smaller, f just got bigger. * That means it wrapped around its unsigned floor @@ -1534,7 +1534,7 @@ void adjustOpenFilesLimit(void) { if (f < oldlimit) f = oldlimit; if (f != maxfiles) { int old_maxclients = server.maxclients; - server.maxclients = f-REDIS_EVENTLOOP_FDSET_INCR; + server.maxclients = f-REDIS_MIN_RESERVED_FDS; if (server.maxclients < 1) { redisLog(REDIS_WARNING,"Your current 'ulimit -n' " "of %llu is not enough for Redis to start. " diff --git a/src/redis.h b/src/redis.h index 5d57410e86c7a47107c5b0277a9bfba462f6269e..14a656b368febe4ecae621f941b53ec3c6cfc93c 100644 --- a/src/redis.h +++ b/src/redis.h @@ -123,6 +123,7 @@ #define REDIS_IP_STR_LEN INET6_ADDRSTRLEN #define REDIS_PEER_ID_LEN (REDIS_IP_STR_LEN+32) /* Must be enough for ip:port */ #define REDIS_BINDADDR_MAX 16 +#define REDIS_MIN_RESERVED_FDS 32 #define ACTIVE_EXPIRE_CYCLE_LOOKUPS_PER_LOOP 20 /* Loopkups per loop. */ #define ACTIVE_EXPIRE_CYCLE_FAST_DURATION 1000 /* Microseconds */ @@ -139,9 +140,9 @@ #define REDIS_LONGSTR_SIZE 21 /* Bytes needed for long -> str */ #define REDIS_AOF_AUTOSYNC_BYTES (1024*1024*32) /* fdatasync every 32MB */ /* When configuring the Redis eventloop, we setup it so that the total number - * of file descriptors we can handle are server.maxclients + FDSET_INCR + * of file descriptors we can handle are server.maxclients + RESERVED_FDS + FDSET_INCR * that is our safety margin. */ -#define REDIS_EVENTLOOP_FDSET_INCR 128 +#define REDIS_EVENTLOOP_FDSET_INCR (REDIS_MIN_RESERVED_FDS+96) /* Hash table parameters */ #define REDIS_HT_MINFILL 10 /* Minimal hash table fill 10% */