summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Stancliff <matt@genges.com>2014-03-22 19:23:01 -0400
committerMatt Stancliff <matt@genges.com>2014-03-24 10:17:33 -0400
commit4a25983f8fe70e105bfd7cc42fed825001afd1df (patch)
treee5a1c69f9b8ba2230865546ad62da71bfa82cdc7
parent491532a713ae28fdd5e489e8f2d88076da8adf44 (diff)
downloadredis-4a25983f8fe70e105bfd7cc42fed825001afd1df.tar.gz
Improve error handling around setting ulimits
The log messages about open file limits have always been slightly opaque and confusing. Here's an attempt to fix their wording, detail, and meaning. Users will have a better understanding of how to fix very common problems with these reworded messages. Also, we handle a new error case when maxclients becomes less than one, essentially rendering the server unusable. We now exit on startup instead of leaving the user with a server unable to handle any connections. This fixes antirez#356 as well.
-rw-r--r--src/redis.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/redis.c b/src/redis.c
index cefc1fdc9..43314bd5d 100644
--- a/src/redis.c
+++ b/src/redis.c
@@ -1522,12 +1522,30 @@ void adjustOpenFilesLimit(void) {
}
if (f < oldlimit) f = oldlimit;
if (f != maxfiles) {
+ int old_maxclients = server.maxclients;
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);
+ if (server.maxclients < 1) {
+ redisLog(REDIS_WARNING,"Your current 'ulimit -n' "
+ "of %llu is not enough for Redis to start. "
+ "Please increase your open file limit to at least "
+ "%llu. Exiting.", oldlimit, maxfiles);
+ exit(1);
+ }
+ redisLog(REDIS_WARNING,"You requested maxclients of %d "
+ "requiring at least %llu max file descriptors.",
+ old_maxclients, maxfiles);
+ redisLog(REDIS_WARNING,"Redis can't set maximum open files "
+ "to %llu because of OS error: %s.",
+ maxfiles, strerror(errno));
+ redisLog(REDIS_WARNING,"Current maximum open files is %llu. "
+ "maxclients has been reduced to %d to compensate for "
+ "low ulimit. "
+ "If you need higher maxclients increase 'ulimit -n'.",
+ oldlimit, server.maxclients);
} else {
- redisLog(REDIS_NOTICE,"Max number of open files set to %d",
- (int) maxfiles);
+ redisLog(REDIS_NOTICE,"Increased maximum number of open files "
+ "to %llu (it was originally set to %llu).",
+ maxfiles, oldlimit);
}
}
}