memflush_LDADD = $(LDADDS)
memslap_SOURCES = memslap.c utilities.c generator.c
-memslap_LDADD = $(LDADDS)
+memslap_LDADD = $(LDADDS) -lpthread
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);
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)
{
{
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)
{
{
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)
{
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)
{
} run_action;
struct thread_context_st {
- unsigned int x;
pairs_st *pairs;
run_action action;
+ memcached_server_st *servers;
};
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;
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)
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[])
{
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)
pthread_mutex_unlock(&sleeper_mutex);
/* Do Stuff */
-
switch (context->action)
{
case AC_SET:
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:
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;
thread_counter--;
pthread_cond_signal(&count_threshhold);
pthread_mutex_unlock(&counter_mutex);
+ memcached_deinit(memc);
free(context);
+
+ return 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;
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;
#include <strings.h>
#include <memcached.h>
-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);
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)
#include <memcached.h>
-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);