Merge Monty
authorBrian Aker <brian@gaz>
Thu, 14 Jan 2010 05:18:46 +0000 (21:18 -0800)
committerBrian Aker <brian@gaz>
Thu, 14 Jan 2010 05:18:46 +0000 (21:18 -0800)
ChangeLog
clients/memcp.c
clients/memslap.c
clients/ms_memslap.h
clients/ms_setting.c
docs/memslap.pod
example/memcached_light.c
tests/include.am
tests/mem_functions.c

index 53f776c092c23210555bb1a81aaae7c3f8cb0df7..308aac834bcf737af58fb8e6ca9418a9d465a788 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 0.38
 
+ * memslap now creates a configuration file at ~/.memslap.cnf
+
  * memcached_purge() now calls any callbacks registered during get
    execution.
 
index 8109ea7e9c19194dd759e910091f4ce5889290dd..1a3307cf2965616e49acd462dd047d7201429bc2 100644 (file)
@@ -85,7 +85,9 @@ int main(int argc, char *argv[])
     char *temp;
 
     if ((temp= getenv("MEMCACHED_SERVERS")))
+    {
       opt_servers= strdup(temp);
+    }
     else
     {
       fprintf(stderr, "No Servers provided\n");
index 11b4df8735ffe0f50a49522552fbaf1f9c04efd1..efda8affae122722bb2f5aae61db84ad7d31488d 100644 (file)
@@ -311,6 +311,7 @@ void ms_help_command(const char *command_name, const char *description)
   {
     printf("    -%c, --%s%c\n", long_options[x].val, long_options[x].name,
            long_options[x].has_arg ? '=' : ' ');
+
     if ((help_message= (char *)ms_lookup_help(long_options[x].val)) != NULL)
     {
       printf("        %s\n", help_message);
@@ -430,7 +431,7 @@ static void ms_options_parse(int argc, char *argv[])
       break;
 
     case OPT_CONCURRENCY:       /* --concurrency or -c */
-      ms_setting.nconns= atoi(optarg);
+      ms_setting.nconns= (int)strtol(optarg, (char **) NULL, 10);
       if (ms_setting.nconns <= 0)
       {
         fprintf(stderr, "Concurrency must be greater than 0.:-)\n");
@@ -439,7 +440,7 @@ static void ms_options_parse(int argc, char *argv[])
       break;
 
     case OPT_EXECUTE_NUMBER:        /* --execute_number or -x */
-      ms_setting.exec_num= atoll(optarg);
+      ms_setting.exec_num= (int)strtol(optarg, (char **) NULL, 10);
       if (ms_setting.exec_num <= 0)
       {
         fprintf(stderr, "Execute number must be greater than 0.:-)\n");
@@ -448,7 +449,7 @@ static void ms_options_parse(int argc, char *argv[])
       break;
 
     case OPT_THREAD_NUMBER:     /* --threads or -T */
-      ms_setting.nthreads= atoi(optarg);
+      ms_setting.nthreads= (int)strtol(optarg, (char **) NULL, 10);
       if (ms_setting.nthreads <= 0)
       {
         fprintf(stderr, "Threads number must be greater than 0.:-)\n");
@@ -457,7 +458,7 @@ static void ms_options_parse(int argc, char *argv[])
       break;
 
     case OPT_FIXED_LTH:         /* --fixed_size or -X */
-      ms_setting.fixed_value_size= (size_t)atoi(optarg);
+      ms_setting.fixed_value_size= (size_t)strtoull(optarg, (char **) NULL, 10);
       if ((ms_setting.fixed_value_size <= 0)
           || (ms_setting.fixed_value_size > MAX_VALUE_SIZE))
       {
@@ -478,7 +479,7 @@ static void ms_options_parse(int argc, char *argv[])
       break;
 
     case OPT_GETS_DIVISION:         /* --division or -d */
-      ms_setting.mult_key_num= atoi(optarg);
+      ms_setting.mult_key_num= (int)strtol(optarg, (char **) NULL, 10);
       if (ms_setting.mult_key_num <= 0)
       {
         fprintf(stderr, "Multi-get key number must be greater than 0.:-)\n");
@@ -564,7 +565,7 @@ static void ms_options_parse(int argc, char *argv[])
       break;
 
     case OPT_SOCK_PER_CONN:         /* --conn_sock or -n */
-      ms_setting.sock_per_conn= atoi(optarg);
+      ms_setting.sock_per_conn= (int)strtol(optarg, (char **) NULL, 10);
       if (ms_setting.sock_per_conn <= 0)
       {
         fprintf(stderr, "Number of socks of each concurrency "
@@ -601,7 +602,7 @@ static void ms_options_parse(int argc, char *argv[])
       break;
 
     case OPT_REP_WRITE_SRV:         /* --rep_write or -p */
-      ms_setting.rep_write_srv= atoi(optarg);
+      ms_setting.rep_write_srv= (int)strtol(optarg, (char **) NULL, 10);
       if (ms_setting.rep_write_srv <= 0)
       {
         fprintf(stderr,
@@ -626,8 +627,17 @@ static int ms_check_para()
 {
   if (ms_setting.srv_str == NULL)
   {
-    fprintf(stderr, "No Servers provided.\n\n");
-    return -1;
+    char *temp;
+
+    if ((temp= getenv("MEMCACHED_SERVERS")))
+    {
+      ms_setting.srv_str= strdup(temp);
+    }
+    else
+    {
+      fprintf(stderr, "No Servers provided\n\n");
+      return -1;
+    }
   }
 
   if (ms_setting.nconns % ms_setting.nthreads != 0)
@@ -794,8 +804,8 @@ static void ms_monitor_slap_mode()
       second++;
 
       if ((ms_setting.stat_freq > 0) && (second % ms_setting.stat_freq == 0)
-          && ((int32_t)ms_stats.active_conns >= ms_setting.nconns)
-          && (ms_stats.active_conns <= (uint32_t)INT_MAX))
+          && (ms_stats.active_conns >= ms_setting.nconns)
+          && (ms_stats.active_conns <= INT_MAX))
       {
         ms_print_statistics(second);
       }
index 87caca5dc1408ba422c5fec17c7e09ee1520dddd..8777c5bb2466a14419a37b5e6be47699c926adb4 100644 (file)
@@ -71,7 +71,7 @@ typedef struct statistic
 /* global status statistic structure */
 typedef struct stats
 {
-  volatile uint32_t active_conns;   /* active connections */
+  volatile int32_t active_conns;   /* active connections */
   size_t bytes_read;              /* read bytes */
   size_t bytes_written;           /* written bytes */
   size_t obj_bytes;               /* object bytes */
index 2821ec524d2254bbb8713de66ef5e8f45d4d43b3..d269e33022250c4007713d6ce76516e945b58614 100644 (file)
 
 #include <ctype.h>
 #include <inttypes.h>
+#include <limits.h>
+#include <pwd.h>
 #include <strings.h>
+#include <sys/types.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+
 
 #include "ms_setting.h"
 #include "ms_conn.h"
@@ -23,6 +30,8 @@
 #define RAND_CHAR_SIZE             (10 * 1024 * 1024)      /* 10M character table */
 #define RESERVED_RAND_CHAR_SIZE    (2 * 1024 * 1024)       /* reserved 2M to avoid pointer sloping over */
 
+#define DEFAULT_CONFIG_NAME ".memslap.cnf"
+
 #define DEFAULT_THREADS_NUM        1                       /* default start one thread */
 #define DEFAULT_CONNS_NUM          16                      /* default each thread with 16 connections */
 #define DEFAULT_EXE_NUM            0                       /* default execute number is 0 */
@@ -327,12 +336,30 @@ static int ms_read_is_data(char *line, ssize_t nread)
  */
 static void ms_no_config_file()
 {
-  FILE *fd= fopen("config", "w+");
+  char userpath[PATH_MAX];
+  struct passwd *usr= NULL;
+  FILE *fd;
+
+  usr= getpwuid(getuid());
 
+  snprintf(userpath, PATH_MAX, "%s/%s", usr->pw_dir, DEFAULT_CONFIG_NAME);
+
+  if (access (userpath, F_OK | R_OK) == 0)
+    goto exit;
+
+  fd= fopen(userpath, "w+");
+
+  if (fd == NULL)
+  {
+    fprintf(stderr, "Could not create default configure file %s\n", userpath);
+    perror(strerror(errno));
+    exit(1);
+  }
   fprintf(fd, "%s", DEFAULT_CONGIF_STR);
   fclose(fd);
 
-  ms_setting.cfg_file= strdup("config");
+exit:
+  ms_setting.cfg_file= strdup(userpath);
 } /* ms_no_config_file */
 
 
@@ -355,13 +382,11 @@ static void ms_parse_cfg_file(char *cfg_file)
   int end_of_file= 0;
   ms_key_distr_t *key_distr= NULL;
   ms_value_distr_t *val_distr= NULL;
-  bool no_cfg= false;
 
   if (cfg_file == NULL)
   {
     ms_no_config_file();
     cfg_file= ms_setting.cfg_file;
-    no_cfg= true;
   }
 
   /*read key value configure file*/
@@ -376,6 +401,7 @@ static void ms_parse_cfg_file(char *cfg_file)
     if ((((nread= getline(&line, &read_len, f)) == 1)
          || ! ms_read_is_data(line, nread)) && (nread != EOF)) /* bypass blank line */
       continue;
+
     if (nread == EOF)
     {
       fprintf(stderr, "Bad configuration file, no configuration find.\n");
@@ -528,13 +554,10 @@ static void ms_parse_cfg_file(char *cfg_file)
 
   fclose(f);
 
-  if (no_cfg)
-  {
-    remove(ms_setting.cfg_file);
-  }
-
   if (line != NULL)
+  {
     free(line);
+  }
 } /* ms_parse_cfg_file */
 
 
@@ -849,6 +872,7 @@ static void ms_init_random_block()
  */
 static void ms_print_setting()
 {
+  fprintf(stdout, "servers : %s\n", ms_setting.srv_str);
   fprintf(stdout, "threads count: %d\n", ms_setting.nthreads);
   fprintf(stdout, "concurrency: %d\n", ms_setting.nconns);
   if (ms_setting.run_time > 0)
@@ -927,9 +951,9 @@ void ms_setting_init_pre()
 static void ms_setting_slapmode_init_post()
 {
   ms_setting.total_key_rng_cnt= KEY_RANGE_COUNT_INIT;
-  ms_setting.key_distr= (ms_key_distr_t *)malloc(
-    (size_t)ms_setting.total_key_rng_cnt
-    * sizeof(ms_key_distr_t));
+  ms_setting.key_distr= 
+    (ms_key_distr_t *)malloc((size_t)ms_setting.total_key_rng_cnt * sizeof(ms_key_distr_t));
+
   if (ms_setting.key_distr == NULL)
   {
     fprintf(stderr, "Can't allocate key distribution structure.\n");
@@ -937,10 +961,10 @@ static void ms_setting_slapmode_init_post()
   }
 
   ms_setting.total_val_rng_cnt= VALUE_RANGE_COUNT_INIT;
-  ms_setting.value_distr= (ms_value_distr_t *)malloc(
-    (size_t)ms_setting.total_val_rng_cnt
-    * sizeof(
-      ms_value_distr_t));
+
+  ms_setting.value_distr= 
+    (ms_value_distr_t *)malloc((size_t)ms_setting.total_val_rng_cnt * sizeof( ms_value_distr_t));
+
   if (ms_setting.value_distr == NULL)
   {
     fprintf(stderr, "Can't allocate value distribution structure.\n");
index 6332a32bb98953fe84d356a387d8b7d4a2a0484b..462f67fe944489cd2bf2146bdd3b88900e13e263 100644 (file)
@@ -507,8 +507,11 @@ commands together as “mulit-get” to the server.
 
 =head1 Configuration file
 
-This section describes the format of the configuration file. Below is a
-sample configuration file:
+This section describes the format of the configuration file.  By default
+when no configuration file is specified memslap reads the default
+one located at ~/.memslap.cnf.
+
+Below is a sample configuration file:
 
  ***************************************************************************
  #comments should start with '#'
@@ -590,6 +593,8 @@ At the beginning, memslap displays some configuration information as follows:
 
 =over 4
 
+=item servers : 127.0.0.1:11211
+
 =item threads count: 1
 
 =item concurrency: 16
@@ -608,6 +613,10 @@ At the beginning, memslap displays some configuration information as follows:
 
 =over 4
 
+=item servers : "servers"
+
+The servers used by memslap.
+
 =item threads count
 
 The number of threads memslap runs with.
index d88e5861a97a76c80a8455b0a72d2ffc061b060c..4a53217ab831dfd966cae7cc9990c4455770da7d 100644 (file)
@@ -285,10 +285,12 @@ int main(int argc, char **argv)
     uint32_t pid;
 
     pid_file= fopen(global_options.pid_file, "w+");
-    perror(strerror(errno));
 
     if (pid_file == NULL)
+    {
+      perror(strerror(errno));
       abort();
+    }
 
     pid= (uint32_t)getpid();
     fprintf(pid_file, "%u\n", pid);
index 259da130cfd70f9d475ab0aae161e55c98d7bcbc..379e9e4aab94f106568aeec9b7769f0c3a3e75e8 100644 (file)
@@ -119,6 +119,8 @@ clients:
        cat tests/Xumemc.pid | xargs kill
        rm tests/Xumemc.pid
 
+MEMSLAP_COMMAND= clients/memslap $(COLLECTION) $(SUITE)
+
 MEM_COMMAND= tests/testapp $(COLLECTION) $(SUITE)
 
 HASH_COMMAND= tests/testhashkit $(COLLECTION) $(SUITE)
@@ -135,12 +137,17 @@ gdb-mem:
 gdb-hash:
        $(DEBUG_COMMAND) $(HASH_COMMAND)
 
+gdb-memslap:
+       $(DEBUG_COMMAND)  $(MEMSLAP_COMMAND)
+
 valgrind-mem:
        $(VALGRIND_COMMAND)  $(MEM_COMMAND)
 
 valgrind-hash:
        $(VALGRIND_COMMAND) $(HASH_COMMAND)
 
+valgrind-memslap:
+       $(VALGRIND_COMMAND) $(MEMSLAP_COMMAND)
 
 PHONY += valgrind
 valgrind: tests/testapp tests/testhashkit valgrind-mem valgrind-hash 
index 1d4b94a9d4c5c9683fcc01d8a363fd2a6683cb77..804227fc726fc077a8f67e19ed6b1cbb91ba42a6 100644 (file)
@@ -3130,11 +3130,10 @@ static test_return_t  cleanup_pairs(memcached_st *memc __attribute__((unused)))
 
 static test_return_t  generate_pairs(memcached_st *memc __attribute__((unused)))
 {
-  unsigned long long x;
   global_pairs= pairs_generate(GLOBAL_COUNT, 400);
   global_count= GLOBAL_COUNT;
 
-  for (x= 0; x < global_count; x++)
+  for (size_t x= 0; x < global_count; x++)
   {
     global_keys[x]= global_pairs[x].key;
     global_keys_length[x]=  global_pairs[x].key_length;
@@ -3145,11 +3144,10 @@ static test_return_t  generate_pairs(memcached_st *memc __attribute__((unused)))
 
 static test_return_t  generate_large_pairs(memcached_st *memc __attribute__((unused)))
 {
-  unsigned long long x;
   global_pairs= pairs_generate(GLOBAL2_COUNT, MEMCACHED_MAX_BUFFER+10);
   global_count= GLOBAL2_COUNT;
 
-  for (x= 0; x < global_count; x++)
+  for (size_t x= 0; x < global_count; x++)
   {
     global_keys[x]= global_pairs[x].key;
     global_keys_length[x]=  global_pairs[x].key_length;
@@ -3202,7 +3200,6 @@ static test_return_t  generate_buffer_data(memcached_st *memc)
 
 static test_return_t  get_read_count(memcached_st *memc)
 {
-  unsigned int x;
   memcached_return_t rc;
   memcached_st *memc_clone;
 
@@ -3217,7 +3214,7 @@ static test_return_t  get_read_count(memcached_st *memc)
     uint32_t flags;
     uint32_t count;
 
-    for (x= count= 0; x < global_count; x++)
+    for (size_t x= count= 0; x < global_count; x++)
     {
       return_value= memcached_get(memc_clone, global_keys[x], global_keys_length[x],
                                   &return_value_length, &flags, &rc);
@@ -3237,7 +3234,6 @@ static test_return_t  get_read_count(memcached_st *memc)
 
 static test_return_t  get_read(memcached_st *memc)
 {
-  unsigned int x;
   memcached_return_t rc;
 
   {
@@ -3245,7 +3241,7 @@ static test_return_t  get_read(memcached_st *memc)
     size_t return_value_length;
     uint32_t flags;
 
-    for (x= 0; x < global_count; x++)
+    for (size_t x= 0; x < global_count; x++)
     {
       return_value= memcached_get(memc, global_keys[x], global_keys_length[x],
                                   &return_value_length, &flags, &rc);
@@ -3315,9 +3311,7 @@ static test_return_t  mget_read_function(memcached_st *memc)
 
 static test_return_t  delete_generate(memcached_st *memc)
 {
-  unsigned int x;
-
-  for (x= 0; x < global_count; x++)
+  for (size_t x= 0; x < global_count; x++)
   {
     (void)memcached_delete(memc, global_keys[x], global_keys_length[x], (time_t)0);
   }
@@ -3342,7 +3336,6 @@ static test_return_t  delete_buffer_generate(memcached_st *memc)
 
 static test_return_t  add_host_test1(memcached_st *memc)
 {
-  unsigned int x;
   memcached_return_t rc;
   char servername[]= "0.example.com";
   memcached_server_st *servers;
@@ -3351,11 +3344,11 @@ static test_return_t  add_host_test1(memcached_st *memc)
   test_truth(servers);
   test_truth(1 == memcached_server_list_count(servers));
 
-  for (x= 2; x < 20; x++)
+  for (size_t x= 2; x < 20; x++)
   {
     char buffer[SMALL_STRING_LEN];
 
-    snprintf(buffer, SMALL_STRING_LEN, "%u.example.com", 400+x);
+    snprintf(buffer, SMALL_STRING_LEN, "%zu.example.com", 400+x);
     servers= memcached_server_list_append_with_weight(servers, buffer, 401, 0,
                                      &rc);
     test_truth(rc == MEMCACHED_SUCCESS);
@@ -3924,10 +3917,10 @@ static test_return_t noreply_test(memcached_st *memc)
 
   for (int count=0; count < 5; ++count)
   {
-    for (int x=0; x < 100; ++x)
+    for (size_t x= 0; x < 100; ++x)
     {
       char key[10];
-      size_t len= (size_t)sprintf(key, "%d", x);
+      size_t len= (size_t)sprintf(key, "%zu", x);
       switch (count)
       {
       case 0:
@@ -3958,7 +3951,7 @@ static test_return_t noreply_test(memcached_st *memc)
     ** way it is supposed to do!!!!
     */
     int no_msg=0;
-    for (uint32_t x=0; x < memcached_server_count(memc); ++x)
+    for (size_t x= 0; x < memcached_server_count(memc); ++x)
     {
       memcached_server_instance_st *instance=
         memcached_server_instance_fetch(memc, x);
@@ -3971,10 +3964,11 @@ static test_return_t noreply_test(memcached_st *memc)
     /*
      ** Now validate that all items was set properly!
      */
-    for (int x=0; x < 100; ++x)
+    for (size_t x= 0; x < 100; ++x)
     {
       char key[10];
-      size_t len= (size_t)sprintf(key, "%d", x);
+
+      size_t len= (size_t)sprintf(key, "%zu", x);
       size_t length;
       uint32_t flags;
       char* value=memcached_get(memc, key, strlen(key),
@@ -4118,7 +4112,8 @@ static test_return_t connection_pool_test(memcached_st *memc)
   memcached_st* mmc[10];
   memcached_return_t rc;
 
-  for (int x= 0; x < 10; ++x) {
+  for (size_t x= 0; x < 10; ++x)
+  {
     mmc[x]= memcached_pool_pop(pool, false, &rc);
     test_truth(mmc[x] != NULL);
     test_truth(rc == MEMCACHED_SUCCESS);
@@ -4144,7 +4139,8 @@ static test_return_t connection_pool_test(memcached_st *memc)
   rc= memcached_set(mmc[0], key, keylen, "0", 1, 0, 0);
   test_truth(rc == MEMCACHED_SUCCESS);
 
-  for (unsigned int x= 0; x < 10; ++x) {
+  for (size_t x= 0; x < 10; ++x) 
+  {
     uint64_t number_value;
     rc= memcached_increment(mmc[x], key, keylen, 1, &number_value);
     test_truth(rc == MEMCACHED_SUCCESS);
@@ -4152,8 +4148,10 @@ static test_return_t connection_pool_test(memcached_st *memc)
   }
 
   // Release them..
-  for (int x= 0; x < 10; ++x)
+  for (size_t x= 0; x < 10; ++x)
+  {
     test_truth(memcached_pool_push(pool, mmc[x]) == MEMCACHED_SUCCESS);
+  }
 
 
   /* verify that I can set behaviors on the pool when I don't have all
@@ -4274,7 +4272,7 @@ static test_return_t replication_mget_test(memcached_st *memc)
   const char *keys[]= { "bubba", "key1", "key2", "key3" };
   size_t len[]= { 5, 4, 4, 4 };
 
-  for (int x=0; x< 4; ++x)
+  for (size_t x= 0; x< 4; ++x)
   {
     rc= memcached_set(memc, keys[x], len[x], "0", 1, 0, 0);
     test_truth(rc == MEMCACHED_SUCCESS);
@@ -4354,7 +4352,8 @@ static test_return_t replication_randomize_mget_test(memcached_st *memc)
 
   memcached_quit(memc);
 
-  for (int x=0; x< 7; ++x) {
+  for (size_t x= 0; x< 7; ++x)
+  {
     const char key[2]= { [0]= (const char)x };
 
     rc= memcached_mget_by_key(memc_clone, key, 1, keys, len, 7);
@@ -4387,7 +4386,7 @@ static test_return_t replication_delete_test(memcached_st *memc)
   const char *keys[]= { "bubba", "key1", "key2", "key3" };
   size_t len[]= { 5, 4, 4, 4 };
 
-  for (int x=0; x< 4; ++x)
+  for (size_t x= 0; x< 4; ++x)
   {
     rc= memcached_delete_by_key(memc, keys[0], len[0], keys[x], len[x], 0);
     test_truth(rc == MEMCACHED_SUCCESS);
@@ -4399,7 +4398,7 @@ static test_return_t replication_delete_test(memcached_st *memc)
    * This is to verify correct behavior in the library
    */
   uint32_t hash= memcached_generate_hash(memc, keys[0], len[0]);
-  for (uint32_t x= 0; x < (repl + 1); ++x)
+  for (size_t x= 0; x < (repl + 1); ++x)
   {
     memcached_server_instance_st *instance=
       memcached_server_instance_fetch(memc_clone, x);
@@ -4412,7 +4411,7 @@ static test_return_t replication_delete_test(memcached_st *memc)
   memcached_result_st result_obj;
   for (uint32_t host= 0; host < memc_clone->number_of_hosts; ++host)
   {
-    for (int x= 'a'; x <= 'z'; ++x)
+    for (size_t x= 'a'; x <= 'z'; ++x)
     {
       const char key[2]= { [0]= (const char)x };
 
@@ -4447,9 +4446,8 @@ static uint16_t *get_udp_request_ids(memcached_st *memc)
 {
   uint16_t *ids= malloc(sizeof(uint16_t) * memcached_server_count(memc));
   assert(ids != NULL);
-  unsigned int x;
 
-  for (x= 0; x < memcached_server_count(memc); x++)
+  for (size_t x= 0; x < memcached_server_count(memc); x++)
   {
     memcached_server_instance_st *instance=
       memcached_server_instance_fetch(memc, x);
@@ -4462,11 +4460,10 @@ static uint16_t *get_udp_request_ids(memcached_st *memc)
 
 static test_return_t post_udp_op_check(memcached_st *memc, uint16_t *expected_req_ids)
 {
-  unsigned int x;
   memcached_server_st *cur_server = memcached_server_list(memc);
   uint16_t *cur_req_ids = get_udp_request_ids(memc);
 
-  for (x= 0; x < memcached_server_count(memc); x++)
+  for (size_t x= 0; x < memcached_server_count(memc); x++)
   {
     test_truth(cur_server[x].cursor_active == 0);
     test_truth(cur_req_ids[x] == expected_req_ids[x]);
@@ -4493,10 +4490,9 @@ static test_return_t init_udp(memcached_st *memc)
     return TEST_SKIPPED;
 
   uint32_t num_hosts= memcached_server_count(memc);
-  unsigned int x= 0;
   memcached_server_st servers[num_hosts];
   memcpy(servers, memcached_server_list(memc), sizeof(memcached_server_st) * num_hosts);
-  for (x= 0; x < num_hosts; x++)
+  for (size_t x= 0; x < num_hosts; x++)
   {
     memcached_server_instance_st *set_instance=
       memcached_server_instance_fetch(memc, x);
@@ -4506,7 +4502,7 @@ static test_return_t init_udp(memcached_st *memc)
 
   memc->number_of_hosts= 0;
   memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_USE_UDP, 1);
-  for (x= 0; x < num_hosts; x++)
+  for (size_t x= 0; x < num_hosts; x++)
   {
     memcached_server_instance_st *set_instance=
       memcached_server_instance_fetch(memc, x);
@@ -4585,9 +4581,9 @@ static test_return_t set_udp_behavior_test(memcached_st *memc)
 
 static test_return_t udp_set_test(memcached_st *memc)
 {
-  unsigned int x= 0;
   unsigned int num_iters= 1025; //request id rolls over at 1024
-  for (x= 0; x < num_iters;x++)
+
+  for (size_t x= 0; x < num_iters;x++)
   {
     memcached_return_t rc;
     const char *key= "foo";
@@ -4640,14 +4636,15 @@ static test_return_t udp_set_too_big_test(memcached_st *memc)
                     value, MAX_UDP_DATAGRAM_LENGTH,
                     (time_t)0, (uint32_t)0);
   test_truth(rc == MEMCACHED_WRITE_FAILURE);
+
   return post_udp_op_check(memc,expected_ids);
 }
 
 static test_return_t udp_delete_test(memcached_st *memc)
 {
-  unsigned int x= 0;
   unsigned int num_iters= 1025; //request id rolls over at 1024
-  for (x= 0; x < num_iters;x++)
+
+  for (size_t x= 0; x < num_iters;x++)
   {
     memcached_return_t rc;
     const char *key= "foo";
@@ -4686,9 +4683,11 @@ static test_return_t udp_verbosity_test(memcached_st *memc)
 {
   memcached_return_t rc;
   uint16_t *expected_ids= get_udp_request_ids(memc);
-  unsigned int x;
-  for (x= 0; x < memcached_server_count(memc); x++)
+
+  for (size_t x= 0; x < memcached_server_count(memc); x++)
+  {
     increment_request_id(&expected_ids[x]);
+  }
 
   rc= memcached_verbosity(memc,3);
   test_truth(rc == MEMCACHED_SUCCESS);
@@ -4706,9 +4705,11 @@ static test_return_t udp_flush_test(memcached_st *memc)
 {
   memcached_return_t rc;
   uint16_t *expected_ids= get_udp_request_ids(memc);
-  unsigned int x;
-  for (x= 0; x < memcached_server_count(memc);x++)
+
+  for (size_t x= 0; x < memcached_server_count(memc); x++)
+  {
     increment_request_id(&expected_ids[x]);
+  }
 
   rc= memcached_flush(memc,0);
   test_truth(rc == MEMCACHED_SUCCESS);
@@ -4810,8 +4811,7 @@ static test_return_t udp_mixed_io_test(memcached_st *memc)
     {"udp_version_test", 0,
       (test_callback_fn)udp_version_test}
   };
-  unsigned int x= 0;
-  for (x= 0; x < 500; x++)
+  for (size_t x= 0; x < 500; x++)
   {
     current_op= mixed_io_ops[random() % 9];
     test_truth(current_op.test_fn(memc) == TEST_SUCCESS);