#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <fcntl.h>
+#include <assert.h>
#include <sys/time.h>
#include <getopt.h>
#include <pthread.h>
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,
+pairs_st *load_create_data(memcached_server_st *servers, unsigned int number_of,
unsigned int *actual_loaded);
+void flush_all(memcached_server_st *servers);
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;
options_parse(argc, argv);
if (!opt_servers)
- exit(0);
+ {
+ char *temp;
- servers= parse_opt_servers(opt_servers);
+ if ((temp= getenv("MEMCACHED_SERVERS")))
+ opt_servers= strdup(temp);
+ else
+ exit(1);
+ }
+
+ servers= memcached_servers_parse(opt_servers);
pthread_mutex_init(&counter_mutex, NULL);
pthread_cond_init(&count_threshhold, NULL);
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);
pthread_attr_setdetachstate(&attr,
PTHREAD_CREATE_DETACHED);
- if (opt_initial_load)
- pairs= load_initial_data(servers, opt_initial_load, &actual_loaded);
+ if (opt_flush)
+ flush_all(servers);
+ if (opt_createial_load)
+ pairs= load_create_data(servers, opt_createial_load, &actual_loaded);
pthread_mutex_lock(&counter_mutex);
thread_counter= 0;
{"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},
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. */
}
}
- 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;
{
thread_context_st *context= (thread_context_st *)p;
memcached_st *memc;
-
- memc= memcached_init(NULL);
+ unsigned int value= 1;
+
+ memc= memcached_create(NULL);
+ WATCHPOINT_ASSERT(memc);
+ 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);
memcached_server_push(memc, context->servers);
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,
+void flush_all(memcached_server_st *servers)
+{
+ memcached_st *memc;
+
+ memc= memcached_create(NULL);
+
+ memcached_server_push(memc, servers);
+
+ memcached_flush(memc, 0);
+
+ memcached_free(memc);
+}
+
+pairs_st *load_create_data(memcached_server_st *servers, unsigned int number_of,
unsigned int *actual_loaded)
{
memcached_st *memc;
pairs_st *pairs;
- memc= memcached_init(NULL);
+ memc= memcached_create(NULL);
+ /* We always used non-blocking IO for load since it is faster */
+ memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, NULL );
memcached_server_push(memc, servers);
pairs= pairs_generate(number_of);
*actual_loaded= execute_set(memc, pairs, number_of);
- memcached_deinit(memc);
+ memcached_free(memc);
return pairs;
}