Skip to content

fix option '--max-clients' #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void initConfig(void) {
config.unixsocket = NULL;
config.unixsocketperm = DEFAULT_UNIXSOCKETPERM;
config.tcpkeepalive = DEFAULT_TCP_KEEPALIVE;
config.maxclients = DEFAULT_MAX_CLIENTS;
config.max_clients = DEFAULT_MAX_CLIENTS;
config.num_threads = DEFAULT_THREADS;
config.tcp_backlog = DEFAULT_TCP_BACKLOG;
config.daemonize = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ typedef struct {
int entry_points_count;
redisClusterEntryPoint entry_points[MAX_ENTRY_POINTS];
int tcpkeepalive;
int maxclients;
int max_clients;
int num_threads;
int tcp_backlog;
int daemonize;
Expand Down
2 changes: 1 addition & 1 deletion src/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const char *mainHelpString =
" -c <file> Configuration file\n"
" -p, --port <port> Port (default: %d). Use 0 in order to disable \n"
" TCP connections at all\n"
" --maxclients <n> Max clients (default: %d)\n"
" --max-clients <n> Max clients (default: %d)\n"
" --threads <n> Thread number (default: %d, max: %d)\n"
" --tcpkeepalive TCP Keep Alive (default: %d)\n"
" --tcp-backlog TCP Backlog (default: %d)\n"
Expand Down
38 changes: 19 additions & 19 deletions src/proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ static sds proxySubCommandConfig(clientRequest *r, sds option, sds value,
is_int = 1;
opt = &(config.num_threads);
read_only = 1;
} else if (strcmp("maxclients", option) == 0) {
} else if (strcmp("max-clients", option) == 0) {
is_int = 1;
opt = &(config.maxclients);
opt = &(config.max_clients);
read_only = 1;
} else if (strcmp("connections-pool-size", option) == 0) {
is_int = 1;
Expand Down Expand Up @@ -638,7 +638,7 @@ sds genInfoString(sds section, redisCluster *cluster) {
"connected_clients:%" PRId64 "\r\n"
"max_clients:%d\r\n",
proxy.numclients,
config.maxclients
config.max_clients
);
int i;
for (i = 0; i < config.num_threads; i++) {
Expand Down Expand Up @@ -1705,8 +1705,8 @@ int parseOptions(int argc, char **argv) {
config.pidfile = zstrdup(argv[++i]);
else if (!strcmp("--logfile", arg) && !lastarg)
config.logfile = zstrdup(argv[++i]);
else if (!strcmp("--maxclients", arg) && !lastarg)
config.maxclients = atoi(argv[++i]);
else if (!strcmp("--max-clients", arg) && !lastarg)
config.max_clients = atoi(argv[++i]);
else if (!strcmp("--tcpkeepalive", arg) && !lastarg)
config.tcpkeepalive = atoi(argv[++i]);
else if (!strcmp("--tcp-backlog", arg) && !lastarg)
Expand Down Expand Up @@ -1807,16 +1807,16 @@ int parseOptions(int argc, char **argv) {
*
* 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
* comfig.maxclients to the value that we can actually handle. */
* comfig.max_clients to the value that we can actually handle. */
void adjustOpenFilesLimit(void) {
rlim_t maxfiles = config.maxclients + proxy.min_reserved_fds;
rlim_t maxfiles = config.max_clients + proxy.min_reserved_fds;
struct rlimit limit;

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

Expand Down Expand Up @@ -1848,10 +1848,10 @@ void adjustOpenFilesLimit(void) {
if (bestlimit < oldlimit) bestlimit = oldlimit;

if (bestlimit < maxfiles) {
unsigned int old_maxclients = config.maxclients;
config.maxclients = bestlimit - proxy.min_reserved_fds;
/* maxclients is unsigned so may overflow: in order
* to check if maxclients is now logically less than 1
unsigned int old_max_clients = config.max_clients;
config.max_clients = bestlimit - proxy.min_reserved_fds;
/* max-clients is unsigned so may overflow: in order
* to check if max-clients is now logically less than 1
* we test indirectly via bestlimit. */
if (bestlimit <= (rlim_t) proxy.min_reserved_fds) {
proxyLogWarn("Your current 'ulimit -n' "
Expand All @@ -1862,18 +1862,18 @@ void adjustOpenFilesLimit(void) {
(unsigned long long) maxfiles);
exit(1);
}
proxyLogWarn("You requested maxclients of %d "
proxyLogWarn("You requested max-clients of %d "
"requiring at least %llu max file descriptors.",
old_maxclients,
old_max_clients,
(unsigned long long) maxfiles);
proxyLogWarn("Server can't set maximum open files "
"to %llu because of OS error: %s.",
(unsigned long long) maxfiles, strerror(setrlimit_error));
proxyLogWarn("Current maximum open files is %llu. "
"maxclients has been reduced to %d to compensate for "
"max-clients has been reduced to %d to compensate for "
"low ulimit. "
"If you need higher maxclients increase 'ulimit -n'.",
(unsigned long long) bestlimit, config.maxclients);
"If you need higher max-clients increase 'ulimit -n'.",
(unsigned long long) bestlimit, config.max_clients);
} else {
proxyLogInfo("Increased maximum number of open files "
"to %llu (it was originally set to %llu).",
Expand Down Expand Up @@ -2338,7 +2338,7 @@ static proxyThread *createProxyThread(int index) {
thread->pending_messages = listCreate();
if (thread->pending_messages == NULL) goto fail;
listSetFreeMethod(thread->pending_messages, zfree);
int loopsize = proxy.min_reserved_fds + config.maxclients;
int loopsize = proxy.min_reserved_fds + config.max_clients;
thread->loop = aeCreateEventLoop(loopsize);
if (thread->loop == NULL) {
proxyLogErr("Failed to allocate event loop for thread %d", index);
Expand Down Expand Up @@ -4422,7 +4422,7 @@ void readQuery(aeEventLoop *el, int fd, void *privdata, int mask){
}

static void acceptHandler(int fd, char *ip, int port) {
if (proxy.numclients >= (uint64_t) config.maxclients) {
if (proxy.numclients >= (uint64_t) config.max_clients) {
char *err = "-ERR max number of clients reached\r\n";
static int errlen = 0;
if (errlen == 0) errlen = strlen(err);
Expand Down