Skip to content

Commit

Permalink
Added support for setting backlog queue on command line
Browse files Browse the repository at this point in the history
  • Loading branch information
lenn0x committed Mar 16, 2009
1 parent 0a7d846 commit 7d010a8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
13 changes: 9 additions & 4 deletions memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ static void settings_init(void) {
settings.prefix_delimiter = ':';
settings.detail_enabled = 0;
settings.reqs_per_event = 20;
settings.backlog = 1024;
}

/*
Expand Down Expand Up @@ -3220,7 +3221,7 @@ void accept_new_conns(const bool do_accept) {
for (next = listen_conn; next; next = next->next) {
if (do_accept) {
update_event(next, EV_READ | EV_PERSIST);
if (listen(next->sfd, 1024) != 0) {
if (listen(next->sfd, settings.backlog) != 0) {
perror("listen");
}
}
Expand Down Expand Up @@ -3729,7 +3730,7 @@ static int server_socket(const int port, enum protocol prot) {
continue;
} else {
success++;
if (!IS_UDP(prot) && listen(sfd, 1024) == -1) {
if (!IS_UDP(prot) && listen(sfd, settings.backlog) == -1) {
perror("listen()");
close(sfd);
freeaddrinfo(ai);
Expand Down Expand Up @@ -3825,7 +3826,7 @@ static int server_socket_unix(const char *path, int access_mask) {
return 1;
}
umask(old_umask);
if (listen(sfd, 1024) == -1) {
if (listen(sfd, settings.backlog) == -1) {
perror("listen()");
close(sfd);
return 1;
Expand Down Expand Up @@ -3919,6 +3920,7 @@ static void usage(void) {
" limits the number of requests process for a given con nection\n"
" to prevent starvation. default 20\n");
printf("-C Disable use of CAS\n");
printf("-b Set the backlog queue limit (default 1024)\n");
return;
}

Expand Down Expand Up @@ -4093,7 +4095,7 @@ int main (int argc, char **argv) {
setbuf(stderr, NULL);

/* process arguments */
while ((c = getopt(argc, argv, "a:p:s:U:m:Mc:khirvdl:u:P:f:s:n:t:D:LR:C")) != -1) {
while ((c = getopt(argc, argv, "a:p:s:U:m:Mc:khirvdl:u:P:f:s:n:t:D:LR:C:b")) != -1) {
switch (c) {
case 'a':
/* access for unix domain socket, as octal mask (like chmod)*/
Expand Down Expand Up @@ -4191,6 +4193,9 @@ int main (int argc, char **argv) {
case 'C' :
settings.use_cas = false;
break;
case 'b' :
settings.backlog = atoi(optarg);
break;
default:
fprintf(stderr, "Illegal argument \"%c\"\n", c);
return 1;
Expand Down
1 change: 1 addition & 0 deletions memcached.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ struct settings {
int reqs_per_event; /* Maximum number of io to process on each
io-event. */
bool use_cas;
int backlog;
};

extern struct stats stats;
Expand Down

0 comments on commit 7d010a8

Please sign in to comment.