mirror of
https://github.com/fluencelabs/redis
synced 2025-03-17 16:10:50 +00:00
Replace magic 32 with REDIS_EVENTLOOP_FDSET_INCR
32 was the additional number of file descriptors Redis would reserve when managing a too-low ulimit. The number 32 was in too many places statically, so now we use a macro instead that looks more appropriate. When Redis sets up the server event loop, it uses: server.maxclients+REDIS_EVENTLOOP_FDSET_INCR So, when reserving file descriptors, it makes sense to reserve at least REDIS_EVENTLOOP_FDSET_INCR FDs instead of only 32. Currently, REDIS_EVENTLOOP_FDSET_INCR is set to 128 in redis.h. Also, I replaced the static 128 in the while f < old loop with REDIS_EVENTLOOP_FDSET_INCR as well, which results in no change since it was already 128. Impact: Users now need at least maxclients+128 as their open file limit instead of maxclients+32 to obtain actual "maxclients" number of clients. Redis will carve the extra REDIS_EVENTLOOP_FDSET_INCR file descriptors it needs out of the "maxclients" range instead of failing to start (unless the local ulimit -n is too low to accomidate the request).
This commit is contained in:
parent
c138631cd1
commit
491532a713
14
src/redis.c
14
src/redis.c
@ -1490,21 +1490,21 @@ void initServerConfig() {
|
||||
}
|
||||
|
||||
/* This function will try to raise the max number of open files accordingly to
|
||||
* the configured max number of clients. It will also account for 32 additional
|
||||
* file descriptors as we need a few more for persistence, listening
|
||||
* sockets, log files and so forth.
|
||||
* the configured max number of clients. It also reserves a number of file
|
||||
* descriptors (REDIS_EVENTLOOP_FDSET_INCR) 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+32;
|
||||
rlim_t maxfiles = server.maxclients+REDIS_EVENTLOOP_FDSET_INCR;
|
||||
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-32;
|
||||
server.maxclients = 1024-REDIS_EVENTLOOP_FDSET_INCR;
|
||||
} else {
|
||||
rlim_t oldlimit = limit.rlim_cur;
|
||||
|
||||
@ -1518,11 +1518,11 @@ void adjustOpenFilesLimit(void) {
|
||||
limit.rlim_cur = f;
|
||||
limit.rlim_max = f;
|
||||
if (setrlimit(RLIMIT_NOFILE,&limit) != -1) break;
|
||||
f -= 128;
|
||||
f -= REDIS_EVENTLOOP_FDSET_INCR;
|
||||
}
|
||||
if (f < oldlimit) f = oldlimit;
|
||||
if (f != maxfiles) {
|
||||
server.maxclients = f-32;
|
||||
server.maxclients = f-REDIS_EVENTLOOP_FDSET_INCR;
|
||||
redisLog(REDIS_WARNING,"Unable to set the max number of files limit to %d (%s), setting the max clients configuration to %d.",
|
||||
(int) maxfiles, strerror(errno), (int) server.maxclients);
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user