From: Brian Aker Date: Sun, 30 Sep 2007 18:05:22 +0000 (-0700) Subject: memcap works, though it does nothing useful at the moment :) X-Git-Tag: 0.3~5 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=113160884d25c401dc352cfab093b5b7b1a4fde0;p=m6w6%2Flibmemcached memcap works, though it does nothing useful at the moment :) --- diff --git a/src/Makefile.am b/src/Makefile.am index 4a119db3..67a8612f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -21,4 +21,4 @@ memflush_SOURCES = memflush.c utilities.c memflush_LDADD = $(LDADDS) memslap_SOURCES = memslap.c utilities.c generator.c -memslap_LDADD = $(LDADDS) +memslap_LDADD = $(LDADDS) -lpthread diff --git a/src/generator.h b/src/generator.h index c1c37f5b..6528cce1 100644 --- a/src/generator.h +++ b/src/generator.h @@ -13,4 +13,3 @@ struct pairs_st { pairs_st *pairs_generate(unsigned long long number_of); void pairs_free(pairs_st *pairs); -static void get_random_string(char *buffer, size_t size); diff --git a/src/memcat.c b/src/memcat.c index 05011c0a..81c0a85d 100644 --- a/src/memcat.c +++ b/src/memcat.c @@ -21,13 +21,18 @@ int main(int argc, char *argv[]) size_t string_length; uint16_t flags; memcached_return rc; - - memc= memcached_init(NULL); + memcached_server_st *servers; options_parse(argc, argv); - if (opt_servers) - parse_opt_servers(memc, opt_servers); + if (!opt_servers) + return 0; + + memc= memcached_init(NULL); + + servers= parse_opt_servers(opt_servers); + memcached_server_push(memc, servers); + memcached_server_list_free(servers); while (optind < argc) { diff --git a/src/memcp.c b/src/memcp.c index 3cc0109a..9123028b 100644 --- a/src/memcp.c +++ b/src/memcp.c @@ -25,15 +25,22 @@ int main(int argc, char *argv[]) { memcached_st *memc; memcached_return rc; + memcached_server_st *servers; options_parse(argc, argv); memc= memcached_init(NULL); + if (!opt_servers) + return 0; + if (opt_servers) - parse_opt_servers(memc, opt_servers); + servers= parse_opt_servers(opt_servers); else - parse_opt_servers(memc, argv[--argc]); + servers= parse_opt_servers(argv[--argc]); + + memcached_server_push(memc, servers); + memcached_server_list_free(servers); while (optind < argc) { diff --git a/src/memflush.c b/src/memflush.c index b864bf60..a1a9ccad 100644 --- a/src/memflush.c +++ b/src/memflush.c @@ -16,13 +16,18 @@ int main(int argc, char *argv[]) { memcached_st *memc; memcached_return rc; + memcached_server_st *servers; options_parse(argc, argv); + if (!opt_servers) + return 0; + memc= memcached_init(NULL); - if (opt_servers) - parse_opt_servers(memc, opt_servers); + servers= parse_opt_servers(opt_servers); + memcached_server_push(memc, servers); + memcached_server_list_free(servers); rc = memcached_flush(memc, opt_expire); if (rc != MEMCACHED_SUCCESS) diff --git a/src/memrm.c b/src/memrm.c index db992914..e07654f3 100644 --- a/src/memrm.c +++ b/src/memrm.c @@ -16,13 +16,18 @@ int main(int argc, char *argv[]) { memcached_st *memc; memcached_return rc; + memcached_server_st *servers; options_parse(argc, argv); + if (!opt_servers) + return 0; + memc= memcached_init(NULL); - if (opt_servers) - parse_opt_servers(memc, opt_servers); + servers= parse_opt_servers(opt_servers); + memcached_server_push(memc, servers); + memcached_server_list_free(servers); while (optind < argc) { diff --git a/src/memslap.c b/src/memslap.c index 6945b7d9..fad016ec 100644 --- a/src/memslap.c +++ b/src/memslap.c @@ -34,9 +34,9 @@ typedef enum { } run_action; struct thread_context_st { - unsigned int x; pairs_st *pairs; run_action action; + memcached_server_st *servers; }; struct conclusions_st { @@ -49,68 +49,62 @@ struct conclusions_st { /* Prototypes */ void options_parse(int argc, char *argv[]); void conclusions_print(conclusions_st *conclusion); -void scheduler(conclusions_st *conclusion); +void scheduler(memcached_server_st *servers, conclusions_st *conclusion); static int opt_verbose= 0; static unsigned int opt_default_pairs= 100; -static unsigned int opt_concurrency= 1; +static unsigned int opt_concurrency= 10; static int opt_displayflag= 0; static char *opt_servers= NULL; int main(int argc, char *argv[]) { - unsigned int x; - memcached_return rc; - memcached_st *memc; - pairs_st *pairs; conclusions_st conclusion; + memcached_server_st *servers; memset(&conclusion, 0, sizeof(conclusions_st)); srandom(time(NULL)); - memc= memcached_init(NULL); options_parse(argc, argv); if (!opt_servers) exit(0); - parse_opt_servers(memc, opt_servers); - - pairs= pairs_generate(opt_default_pairs); + servers= parse_opt_servers(opt_servers); pthread_mutex_init(&counter_mutex, NULL); pthread_cond_init(&count_threshhold, NULL); pthread_mutex_init(&sleeper_mutex, NULL); pthread_cond_init(&sleep_threshhold, NULL); - scheduler(&conclusion); - - pairs_free(pairs); + scheduler(servers, &conclusion); free(opt_servers); - memcached_deinit(memc); - (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); conclusions_print(&conclusion); + memcached_server_list_free(servers); return 0; } -void scheduler(conclusions_st *conclusion) +void scheduler(memcached_server_st *servers, conclusions_st *conclusion) { unsigned int x; struct timeval start_time, end_time; pthread_t mainthread; /* Thread descriptor */ pthread_attr_t attr; /* Thread attributes */ + pairs_st *pairs; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + pairs= pairs_generate(opt_default_pairs); + pthread_mutex_lock(&counter_mutex); thread_counter= 0; @@ -123,6 +117,10 @@ void scheduler(conclusions_st *conclusion) thread_context_st *context; context= (thread_context_st *)malloc(sizeof(thread_context_st)); + context->servers= servers; + context->pairs= pairs; + context->action= AC_SET; + /* now you create the thread */ if (pthread_create(&mainthread, &attr, run_task, (void *)context) != 0) @@ -161,6 +159,7 @@ void scheduler(conclusions_st *conclusion) conclusion->load_time= timedif(end_time, start_time); conclusion->read_time= timedif(end_time, start_time); + pairs_free(pairs); } void options_parse(int argc, char *argv[]) @@ -231,6 +230,13 @@ void *run_task(void *p) { unsigned int x; thread_context_st *context= (thread_context_st *)p; + memcached_return rc; + memcached_st *memc; + pairs_st *pairs= context->pairs; + + memc= memcached_init(NULL); + + memcached_server_push(memc, context->servers); pthread_mutex_lock(&sleeper_mutex); while (master_wakeup) @@ -240,7 +246,6 @@ void *run_task(void *p) pthread_mutex_unlock(&sleeper_mutex); /* Do Stuff */ - switch (context->action) { case AC_SET: @@ -252,7 +257,6 @@ void *run_task(void *p) if (rc != MEMCACHED_SUCCESS) fprintf(stderr, "Failured on insert of %.*s\n", (unsigned int)pairs[x].key_length, pairs[x].key); - conclusion->rows_loaded++; } break; case AC_GET: @@ -269,7 +273,6 @@ void *run_task(void *p) if (rc != MEMCACHED_SUCCESS) fprintf(stderr, "Failured on read of %.*s\n", (unsigned int)pairs[x].key_length, pairs[x].key); - conclusion->rows_read++; free(value); } break; @@ -279,6 +282,9 @@ void *run_task(void *p) thread_counter--; pthread_cond_signal(&count_threshhold); pthread_mutex_unlock(&counter_mutex); + memcached_deinit(memc); free(context); + + return NULL; } diff --git a/src/memstat.c b/src/memstat.c index bc81cb07..a82f3f12 100644 --- a/src/memstat.c +++ b/src/memstat.c @@ -20,59 +20,63 @@ static char *opt_servers= NULL; int main(int argc, char *argv[]) { + unsigned int x; + memcached_return rc; memcached_st *memc; + memcached_stat_st *stat; + memcached_server_st *servers; + memcached_server_st *server_list; - memc= memcached_init(NULL); options_parse(argc, argv); - if (opt_servers) + if (!opt_servers) + return 0; + + memc= memcached_init(NULL); + + servers= parse_opt_servers(opt_servers); + memcached_server_push(memc, servers); + memcached_server_list_free(servers); + + stat= memcached_stat(memc, NULL, &rc); + + if (rc != MEMCACHED_SUCCESS || rc != MEMCACHED_SOME_ERRORS); { - unsigned int x; - memcached_return rc; - memcached_stat_st *stat; - memcached_server_st *server_list; + printf("Failure to communicate with servers (%s)\n", + memcached_strerror(memc, rc)); + exit(1); + } - parse_opt_servers(memc, opt_servers); - stat= memcached_stat(memc, NULL, &rc); + server_list= memcached_server_list(memc); - if (rc != MEMCACHED_SUCCESS || rc != MEMCACHED_SOME_ERRORS); - { - printf("Failure to communicate with servers (%s)\n", - memcached_strerror(memc, rc)); - exit(1); - } + printf("Listing %u Server\n\n", memcached_server_count(memc)); + for (x= 0; x < memcached_server_count(memc); x++) + { + char **list; + char **ptr; - server_list= memcached_server_list(memc); + list= memcached_stat_get_keys(memc, &stat[x], &rc); + assert(list); + assert(rc == MEMCACHED_SUCCESS); - printf("Listing %u Server\n\n", memcached_server_count(memc)); - for (x= 0; x < memcached_server_count(memc); x++) + printf("Server: %s (%u)\n", memcached_server_name(memc, server_list[x]), + memcached_server_port(memc, server_list[x])); + for (ptr= list; *ptr; ptr++) { - char **list; - char **ptr; - - list= memcached_stat_get_keys(memc, &stat[x], &rc); - assert(list); - assert(rc == MEMCACHED_SUCCESS); - - printf("Server: %s (%u)\n", memcached_server_name(memc, server_list[x]), - memcached_server_port(memc, server_list[x])); - for (ptr= list; *ptr; ptr++) - { - memcached_return rc; - char *value= memcached_stat_get_value(memc, &stat[x], *ptr, &rc); - - printf("\t %s: %s\n", *ptr, value); - free(value); - } - - free(list); - printf("\n"); + memcached_return rc; + char *value= memcached_stat_get_value(memc, &stat[x], *ptr, &rc); + + printf("\t %s: %s\n", *ptr, value); + free(value); } - free(stat); - free(opt_servers); + free(list); + printf("\n"); } + free(stat); + free(opt_servers); + memcached_deinit(memc); return 0; @@ -81,15 +85,15 @@ int main(int argc, char *argv[]) void options_parse(int argc, char *argv[]) { static struct option long_options[]= - { - {"version", no_argument, NULL, OPT_VERSION}, - {"help", no_argument, NULL, OPT_HELP}, - {"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, - {"debug", no_argument, &opt_verbose, OPT_DEBUG}, - {"servers", required_argument, NULL, OPT_SERVERS}, - {"flag", no_argument, &opt_displayflag, OPT_FLAG}, - {0, 0, 0, 0}, - }; + { + {"version", no_argument, NULL, OPT_VERSION}, + {"help", no_argument, NULL, OPT_HELP}, + {"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, + {"debug", no_argument, &opt_verbose, OPT_DEBUG}, + {"servers", required_argument, NULL, OPT_SERVERS}, + {"flag", no_argument, &opt_displayflag, OPT_FLAG}, + {0, 0, 0, 0}, + }; int option_index= 0; int option_rv; diff --git a/src/utilities.c b/src/utilities.c index 3252df86..a2dc944f 100644 --- a/src/utilities.c +++ b/src/utilities.c @@ -2,16 +2,16 @@ #include #include -void parse_opt_servers(memcached_st *memc, - char *server_strings) +memcached_server_st *parse_opt_servers(char *server_strings) { char *string; unsigned int port; char *begin_ptr; char *end_ptr; + memcached_server_st *servers= NULL; + memcached_return rc; assert(server_strings); - assert(memc); end_ptr= server_strings + strlen(server_strings); @@ -47,11 +47,13 @@ void parse_opt_servers(memcached_st *memc, port= strtol(ptr, (char **)NULL, 10); } - memcached_server_add(memc, buffer, port); + servers= memcached_server_list_append(servers, buffer, port, &rc); if (isspace(*begin_ptr)) begin_ptr++; } + + return servers; } long int timedif(struct timeval a, struct timeval b) diff --git a/src/utilities.h b/src/utilities.h index 777c7765..12f50349 100644 --- a/src/utilities.h +++ b/src/utilities.h @@ -1,7 +1,6 @@ #include -void parse_opt_servers (memcached_st *ptr, - char *opt_servers); +memcached_server_st *parse_opt_servers(char *server_strings); char *strdup_cleanup(const char *str); void cleanup(void); long int timedif(struct timeval a, struct timeval b);