Do not install libmemcached_config.h
[awesomized/libmemcached] / clients / memslap.c
index 164fc0993dfdd961ab3d6eaf0f4f6a88e4ca2349..d42c06aefffab36b64bd52f6a1754f50a2ae9557 100644 (file)
@@ -6,7 +6,6 @@
 #include <sys/types.h>
 #include <sys/mman.h>
 #include <fcntl.h>
-#include <assert.h>
 #include <sys/time.h>
 #include <getopt.h>
 #include <pthread.h>
@@ -68,6 +67,7 @@ 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_binary= 0;
 static int opt_verbose= 0;
 static int opt_flush= 0;
 static int opt_non_blocking_io= 0;
@@ -77,6 +77,7 @@ static unsigned int opt_createial_load= 0;
 static unsigned int opt_concurrency= 0;
 static int opt_displayflag= 0;
 static char *opt_servers= NULL;
+static int opt_udp_io= 0;
 test_type opt_test= SET_TEST;
 
 int main(int argc, char *argv[])
@@ -139,8 +140,19 @@ void scheduler(memcached_server_st *servers, conclusions_st *conclusion)
                               PTHREAD_CREATE_DETACHED);
 
   memc= memcached_create(NULL);
+
+  /* We need to set udp behavior before adding servers to the client */
+  if (opt_udp_io)
+  {
+    memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_USE_UDP, opt_udp_io);
+    unsigned int x= 0;
+    for(x= 0; x < servers[0].count; x++ )
+      servers[x].type= MEMCACHED_CONNECTION_UDP;
+  }
   memcached_server_push(memc, servers);
 
+  memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, opt_binary);
+  
   if (opt_flush)
     flush_all(memc);
   if (opt_createial_load)
@@ -148,11 +160,10 @@ void scheduler(memcached_server_st *servers, conclusions_st *conclusion)
 
   /* 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);
+      memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, 1);
     if (opt_tcp_nodelay)
-      memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &value);
+      memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, 1);
   }
 
 
@@ -205,14 +216,7 @@ void scheduler(memcached_server_st *servers, conclusions_st *conclusion)
   */
   pthread_mutex_lock(&counter_mutex);
   while (thread_counter)
-  {
-    struct timespec abstime;
-
-    memset(&abstime, 0, sizeof(struct timespec));
-    abstime.tv_sec= 1;
-
-    pthread_cond_timedwait(&count_threshhold, &counter_mutex, &abstime);
-  }
+    pthread_cond_wait(&count_threshhold, &counter_mutex);
   pthread_mutex_unlock(&counter_mutex);
 
   gettimeofday(&end_time, NULL);
@@ -220,6 +224,7 @@ void scheduler(memcached_server_st *servers, conclusions_st *conclusion)
   conclusion->load_time= timedif(end_time, start_time);
   conclusion->read_time= timedif(end_time, start_time);
   pairs_free(pairs);
+  memcached_free(memc);
 }
 
 void options_parse(int argc, char *argv[])
@@ -244,6 +249,8 @@ void options_parse(int argc, char *argv[])
       {"test", required_argument, NULL, OPT_SLAP_TEST},
       {"verbose", no_argument, &opt_verbose, OPT_VERBOSE},
       {"version", no_argument, NULL, OPT_VERSION},
+      {"binary", no_argument, NULL, OPT_BINARY},
+      {"udp", no_argument, NULL, OPT_UDP},
       {0, 0, 0, 0},
     };
 
@@ -258,6 +265,18 @@ void options_parse(int argc, char *argv[])
     {
     case 0:
       break;
+    case OPT_UDP:
+      if (opt_test == GET_TEST)
+      {
+        fprintf(stderr, "You can not run a get test in UDP mode. UDP mode "
+                  "does not currently support get ops.\n");
+        exit(1);
+      }
+      opt_udp_io= 1;
+      break;
+    case OPT_BINARY:
+      opt_binary = 1;
+      break;
     case OPT_VERBOSE: /* --verbose or -v */
       opt_verbose = OPT_VERBOSE;
       break;
@@ -275,7 +294,15 @@ void options_parse(int argc, char *argv[])
       break;
     case OPT_SLAP_TEST:
       if (!strcmp(optarg, "get"))
+      {
+        if (opt_udp_io == 1)
+        {
+          fprintf(stderr, "You can not run a get test in UDP mode. UDP mode "
+                  "does not currently support get ops.\n");
+          exit(1);
+        }
         opt_test= GET_TEST ;
+      }
       else if (!strcmp(optarg, "set"))
         opt_test= SET_TEST;
       else 
@@ -286,6 +313,7 @@ void options_parse(int argc, char *argv[])
       break;
     case OPT_SLAP_CONCURRENCY:
       opt_concurrency= strtol(optarg, (char **)NULL, 10);
+      break;
     case OPT_SLAP_EXECUTE_NUMBER:
       opt_execute_number= strtol(optarg, (char **)NULL, 10);
       break;
@@ -354,6 +382,7 @@ void *run_task(void *p)
 
   if (context->execute_pairs)
     pairs_free(context->execute_pairs);
+
   free(context);
 
   pthread_mutex_lock(&counter_mutex);
@@ -377,7 +406,7 @@ pairs_st *load_create_data(memcached_st *memc, unsigned int number_of,
 
   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 );
+  memcached_behavior_set(clone, MEMCACHED_BEHAVIOR_NO_BLOCK, 0);
 
   pairs= pairs_generate(number_of, 400);
   *actual_loaded= execute_set(clone, pairs, number_of);