From c60ca35b2d1fc36b891f132fbdd2860c3119ccf6 Mon Sep 17 00:00:00 2001 From: Trond Norbye Date: Tue, 1 Mar 2011 11:30:29 +0100 Subject: Bind each UDP socket to an a single worker thread in multiport env --- memcached.c | 14 +++++++++++++- memcached.h | 1 + t/binary.t | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/memcached.c b/memcached.c index 5a8fc8e..0e96aa9 100644 --- a/memcached.c +++ b/memcached.c @@ -189,6 +189,7 @@ static void settings_init(void) { settings.factor = 1.25; settings.chunk_size = 48; /* space for a modest key and value */ settings.num_threads = 4; /* N workers */ + settings.num_threads_per_udp = 0; settings.prefix_delimiter = ':'; settings.detail_enabled = 0; settings.reqs_per_event = 20; @@ -2437,6 +2438,7 @@ static void process_stat_settings(ADD_STAT add_stats, void *c) { APPEND_STAT("growth_factor", "%.2f", settings.factor); APPEND_STAT("chunk_size", "%d", settings.chunk_size); APPEND_STAT("num_threads", "%d", settings.num_threads); + APPEND_STAT("num_threads_per_udp", "%d", settings.num_threads_per_udp); APPEND_STAT("stat_key_prefix", "%c", settings.prefix_delimiter); APPEND_STAT("detail_enabled", "%s", settings.detail_enabled ? "yes" : "no"); @@ -3912,7 +3914,7 @@ static int server_socket(const char *interface, if (IS_UDP(transport)) { int c; - for (c = 0; c < settings.num_threads; c++) { + for (c = 0; c < settings.num_threads_per_udp; c++) { /* this is guaranteed to hit all threads because we round-robin */ dispatch_conn_new(sfd, conn_read, EV_READ | EV_PERSIST, UDP_READ_BUFFER_SIZE, transport); @@ -4575,6 +4577,16 @@ int main (int argc, char **argv) { } } + /* + * Use one workerthread to serve each UDP port if the user specified + * multiple ports + */ + if (settings.inter != NULL && strchr(settings.inter, ',')) { + settings.num_threads_per_udp = 1; + } else { + settings.num_threads_per_udp = settings.num_threads; + } + if (settings.sasl) { if (!protocol_specified) { settings.binding_protocol = binary_prot; diff --git a/memcached.h b/memcached.h index 74a6592..5f1ac9d 100644 --- a/memcached.h +++ b/memcached.h @@ -270,6 +270,7 @@ struct settings { double factor; /* chunk size growth factor */ int chunk_size; int num_threads; /* number of worker (without dispatcher) libevent threads to run */ + int num_threads_per_udp; /* number of worker threads serving each udp socket */ char prefix_delimiter; /* character that marks a key prefix (for stats) */ int detail_enabled; /* nonzero if we're collecting detailed stats */ int reqs_per_event; /* Maximum number of io to process on each diff --git a/t/binary.t b/t/binary.t index 3a8cab3..68d8c00 100755 --- a/t/binary.t +++ b/t/binary.t @@ -2,7 +2,7 @@ use strict; use warnings; -use Test::More tests => 3373; +use Test::More tests => 3376; use FindBin qw($Bin); use lib "$Bin/lib"; use MemcachedTest; -- cgit v1.2.1