Score:0

CentOS: Redis max client connection limitation

um flag

I am using Redis caching server on CentOS, where Redis accepts clients connections on the configured listening TCP port. I am trying to figure out the limits applied by the operating system to the number of connection allowed to the single configured port for redis.

The user being used is root as shown:

[root@server-001]# ps -ef | grep -i redis 
root     19595     1  9 Jun26 ?        09:43:07 /usr/local/bin/redis-server 0.0.0.0:6379

Now I am tricked by multiple factors:

1st: the value of file-max is:

[root@server-001]# cat /proc/sys/fs/file-max
6518496

2nd: the value of limits.conf:

[root@server-001]# cat /etc/security/limits.d/20-nproc.conf 
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.

*          soft    nproc     4096
root       soft    nproc     unlimited

3rd: The soft and hard limit of file descriptors:

[root@server-001]# ulimit -Hn
4096
[root@server-001]# ulimit -Sn
1024

Now, knowing that the the real factor limits connection to a single port is file descriptors, which one I have to change to make sure that the redis server is accepting as much clients as it is possible?

Score:1
it flag

use maxclients 4096 on redis.conf

void adjustOpenFilesLimit(void) {
rlim_t maxfiles = server.maxclients+CONFIG_MIN_RESERVED_FDS;
struct rlimit limit;

if (getrlimit(RLIMIT_NOFILE,&limit) == -1) {
    serverLog(LL_WARNING,"Unable to obtain the current NOFILE limit (%s), assuming 1024 and setting the max clients configuration accordingly.",
        strerror(errno));
    server.maxclients = 1024-CONFIG_MIN_RESERVED_FDS;
} else {
    rlim_t oldlimit = limit.rlim_cur;

    /* Set the max number of files if the current limit is not enough
     * for our needs. */
    if (oldlimit < maxfiles) {
        rlim_t bestlimit;
        int setrlimit_error = 0;

        /* Try to set the file limit to match 'maxfiles' or at least
         * to the higher value supported less than maxfiles. */
        bestlimit = maxfiles;
        while(bestlimit > oldlimit) {
            rlim_t decr_step = 16;

            limit.rlim_cur = bestlimit;
            limit.rlim_max = bestlimit;
            if (setrlimit(RLIMIT_NOFILE,&limit) != -1) break;
            setrlimit_error = errno;

            /* We failed to set file limit to 'bestlimit'. Try with a
             * smaller limit decrementing by a few FDs per iteration. */
            if (bestlimit < decr_step) break;
            bestlimit -= decr_step;
        }

        /* Assume that the limit we get initially is still valid if
         * our last try was even lower. */
        if (bestlimit < oldlimit) bestlimit = oldlimit;

        if (bestlimit < maxfiles) {
            unsigned int old_maxclients = server.maxclients;
            server.maxclients = bestlimit-CONFIG_MIN_RESERVED_FDS;
            /* maxclients is unsigned so may overflow: in order
             * to check if maxclients is now logically less than 1
             * we test indirectly via bestlimit. */
            if (bestlimit <= CONFIG_MIN_RESERVED_FDS) {
                serverLog(LL_WARNING,"Your current 'ulimit -n' "
                    "of %llu is not enough for the server to start. "
                    "Please increase your open file limit to at least "
                    "%llu. Exiting.",
                    (unsigned long long) oldlimit,
                    (unsigned long long) maxfiles);
                exit(1);
            }
            serverLog(LL_WARNING,"You requested maxclients of %d "
                "requiring at least %llu max file descriptors.",
                old_maxclients,
                (unsigned long long) maxfiles);
            serverLog(LL_WARNING,"Server can't set maximum open files "
                "to %llu because of OS error: %s.",
                (unsigned long long) maxfiles, strerror(setrlimit_error));
            serverLog(LL_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'.",
                (unsigned long long) bestlimit, server.maxclients);
        } else {
            serverLog(LL_NOTICE,"Increased maximum number of open files "
                "to %llu (it was originally set to %llu).",
                (unsigned long long) maxfiles,
                (unsigned long long) oldlimit);
        }
    }
}

}

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.