X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Fmemslap.c;h=486ff7cedf5ffaf915a3a5bda798ee9440a8f4f3;hb=4c269c98f4b92850758184713a305679dffb60d3;hp=2e83acdb7969d1f33a17a7f886102226bbdb2a1e;hpb=7bfd925c54662cf1f67b651559dd91f77bfe8817;p=awesomized%2Flibmemcached diff --git a/src/memslap.c b/src/memslap.c index 2e83acdb..486ff7ce 100644 --- a/src/memslap.c +++ b/src/memslap.c @@ -1,10 +1,12 @@ #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -48,7 +50,7 @@ struct thread_context_st { pairs_st *execute_pairs; unsigned int execute_number; test_type test; - memcached_server_st *servers; + memcached_st *memc; }; struct conclusions_st { @@ -62,12 +64,16 @@ struct conclusions_st { void options_parse(int argc, char *argv[]); void conclusions_print(conclusions_st *conclusion); void scheduler(memcached_server_st *servers, conclusions_st *conclusion); -pairs_st *load_initial_data(memcached_server_st *servers, unsigned int number_of, - unsigned int *actual_loaded); +pairs_st *load_create_data(memcached_st *memc, unsigned int number_of, + unsigned int *actual_loaded); +void flush_all(memcached_st *memc); static int opt_verbose= 0; +static int opt_flush= 0; +static int opt_non_blocking_io= 0; +static int opt_tcp_nodelay= 0; static unsigned int opt_execute_number= 0; -static unsigned int opt_initial_load= 0; +static unsigned int opt_createial_load= 0; static unsigned int opt_concurrency= 0; static int opt_displayflag= 0; static char *opt_servers= NULL; @@ -84,9 +90,16 @@ int main(int argc, char *argv[]) options_parse(argc, argv); if (!opt_servers) - exit(0); + { + char *temp; + + if ((temp= getenv("MEMCACHED_SERVERS"))) + opt_servers= strdup(temp); + else + exit(1); + } - servers= parse_opt_servers(opt_servers); + servers= memcached_servers_parse(opt_servers); pthread_mutex_init(&counter_mutex, NULL); pthread_cond_init(&count_threshhold, NULL); @@ -97,10 +110,10 @@ int main(int argc, char *argv[]) free(opt_servers); - (void)pthread_mutex_init(&counter_mutex, NULL); - (void)pthread_cond_init(&count_threshhold, NULL); - (void)pthread_mutex_init(&sleeper_mutex, NULL); - (void)pthread_cond_init(&sleep_threshhold, NULL); + (void)pthread_mutex_destroy(&counter_mutex); + (void)pthread_cond_destroy(&count_threshhold); + (void)pthread_mutex_destroy(&sleeper_mutex); + (void)pthread_cond_destroy(&sleep_threshhold); conclusions_print(&conclusion); memcached_server_list_free(servers); @@ -110,7 +123,8 @@ int main(int argc, char *argv[]) void scheduler(memcached_server_st *servers, conclusions_st *conclusion) { unsigned int x; - unsigned int actual_loaded; + unsigned int actual_loaded= 0; /* Fix warning */ + memcached_st *memc; struct timeval start_time, end_time; pthread_t mainthread; /* Thread descriptor */ @@ -121,8 +135,23 @@ void scheduler(memcached_server_st *servers, conclusions_st *conclusion) pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - if (opt_initial_load) - pairs= load_initial_data(servers, opt_initial_load, &actual_loaded); + memc= memcached_create(NULL); + memcached_server_push(memc, servers); + + if (opt_flush) + flush_all(memc); + if (opt_createial_load) + pairs= load_create_data(memc, opt_createial_load, &actual_loaded); + + /* We set this after we have loaded */ + { + unsigned int value= 1; + if (opt_non_blocking_io) + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, &value); + if (opt_tcp_nodelay) + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &value); + } + pthread_mutex_lock(&counter_mutex); thread_counter= 0; @@ -135,8 +164,9 @@ void scheduler(memcached_server_st *servers, conclusions_st *conclusion) { thread_context_st *context; context= (thread_context_st *)malloc(sizeof(thread_context_st)); + memset(context, 0, sizeof(thread_context_st)); - context->servers= servers; + context->memc= memcached_clone(NULL, memc); context->test= opt_test; context->initial_pairs= pairs; @@ -202,9 +232,12 @@ void options_parse(int argc, char *argv[]) {"debug", no_argument, &opt_verbose, OPT_DEBUG}, {"execute-number", required_argument, NULL, OPT_SLAP_EXECUTE_NUMBER}, {"flag", no_argument, &opt_displayflag, OPT_FLAG}, + {"flush", no_argument, &opt_flush, OPT_FLUSH}, {"help", no_argument, NULL, OPT_HELP}, {"initial-load", required_argument, NULL, OPT_SLAP_INITIAL_LOAD}, /* Number to load initially */ + {"non-blocking", no_argument, &opt_non_blocking_io, OPT_SLAP_NON_BLOCK}, {"servers", required_argument, NULL, OPT_SERVERS}, + {"tcp-nodelay", no_argument, &opt_tcp_nodelay, OPT_SLAP_TCP_NODELAY}, {"test", required_argument, NULL, OPT_SLAP_TEST}, {"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, {"version", no_argument, NULL, OPT_VERSION}, @@ -254,7 +287,7 @@ void options_parse(int argc, char *argv[]) opt_execute_number= strtol(optarg, (char **)NULL, 10); break; case OPT_SLAP_INITIAL_LOAD: - opt_initial_load= strtol(optarg, (char **)NULL, 10); + opt_createial_load= strtol(optarg, (char **)NULL, 10); break; case '?': /* getopt_long already printed an error message. */ @@ -264,8 +297,8 @@ void options_parse(int argc, char *argv[]) } } - if (opt_test == GET_TEST && opt_initial_load == 0) - opt_initial_load= DEFAULT_INITIAL_LOAD; + if (opt_test == GET_TEST && opt_createial_load == 0) + opt_createial_load= DEFAULT_INITIAL_LOAD; if (opt_execute_number == 0) opt_execute_number= DEFAULT_EXECUTE_NUMBER; @@ -294,9 +327,7 @@ void *run_task(void *p) thread_context_st *context= (thread_context_st *)p; memcached_st *memc; - memc= memcached_init(NULL); - - memcached_server_push(memc, context->servers); + memc= context->memc; pthread_mutex_lock(&sleeper_mutex); while (master_wakeup) @@ -316,30 +347,39 @@ void *run_task(void *p) break; } + memcached_free(memc); + + if (context->execute_pairs) + pairs_free(context->execute_pairs); + free(context); + pthread_mutex_lock(&counter_mutex); thread_counter--; pthread_cond_signal(&count_threshhold); pthread_mutex_unlock(&counter_mutex); - memcached_deinit(memc); - - free(context); return NULL; } -pairs_st *load_initial_data(memcached_server_st *servers, unsigned int number_of, - unsigned int *actual_loaded) +void flush_all(memcached_st *memc) { - memcached_st *memc; + memcached_flush(memc, 0); +} + +pairs_st *load_create_data(memcached_st *memc, unsigned int number_of, + unsigned int *actual_loaded) +{ + memcached_st *clone; pairs_st *pairs; - memc= memcached_init(NULL); - memcached_server_push(memc, servers); + clone= memcached_clone(NULL, memc); + /* We always used non-blocking IO for load since it is faster */ + memcached_behavior_set(clone, MEMCACHED_BEHAVIOR_NO_BLOCK, NULL ); pairs= pairs_generate(number_of); - *actual_loaded= execute_set(memc, pairs, number_of); + *actual_loaded= execute_set(clone, pairs, number_of); - memcached_deinit(memc); + memcached_free(clone); return pairs; }