*
* Libmemcached library
*
- * Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ * Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/
* Copyright (C) 2006-2009 Brian Aker All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
*/
-#include <config.h>
+#include <mem_config.h>
#include <cassert>
+#include <cerrno>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
-#include <sys/types.h>
#include <unistd.h>
#include <iostream>
-#include <libmemcached/memcached.h>
+#include <libmemcached-1.0/memcached.h>
#include "client_options.h"
#include "utilities.h"
#define DEFAULT_EXECUTE_NUMBER 10000
#define DEFAULT_CONCURRENCY 1
+#define VALUE_BYTES 4096
+
#define PROGRAM_NAME "memslap"
#define PROGRAM_DESCRIPTION "Generates a load against a memcached custer of servers."
{
opt_servers= strdup(temp);
}
- else
+
+ if (opt_servers == NULL)
{
- fprintf(stderr, "No Servers provided\n");
- return EXIT_FAILURE;
+ std::cerr << "No Servers provided" << std::endl;
+ exit(EXIT_FAILURE);
}
}
memcached_server_st *servers= memcached_servers_parse(opt_servers);
+ if (servers == NULL or memcached_server_list_count(servers) == 0)
+ {
+ std::cerr << "Invalid server list provided:" << opt_servers << std::endl;
+ return EXIT_FAILURE;
+ }
pthread_mutex_init(&sleeper_mutex, NULL);
pthread_cond_init(&sleep_threshhold, NULL);
- scheduler(servers, &conclusion);
+ int error_code= EXIT_SUCCESS;
+ try {
+ scheduler(servers, &conclusion);
+ }
+ catch(std::exception& e)
+ {
+ std::cerr << "Died with exception: " << e.what() << std::endl;
+ error_code= EXIT_FAILURE;
+ }
free(opt_servers);
conclusions_print(&conclusion);
memcached_server_list_free(servers);
- return EXIT_SUCCESS;
+ return error_code;
}
void scheduler(memcached_server_st *servers, conclusions_st *conclusion)
pthread_t *threads= new (std::nothrow) pthread_t[opt_concurrency];
- if (not threads)
+ if (threads == NULL)
{
exit(EXIT_FAILURE);
}
if (opt_test == SET_TEST)
{
- context->execute_pairs= pairs_generate(opt_execute_number, 400);
+ context->execute_pairs= pairs_generate(opt_execute_number, VALUE_BYTES);
context->execute_number= opt_execute_number;
}
break;
case OPT_DEBUG: /* --debug or -d */
- opt_verbose = OPT_DEBUG;
+ opt_verbose= OPT_DEBUG;
break;
case OPT_VERSION: /* --version or -V */
break;
case OPT_SLAP_CONCURRENCY:
+ errno= 0;
opt_concurrency= (unsigned int)strtoul(optarg, (char **)NULL, 10);
+ if (errno != 0)
+ {
+ fprintf(stderr, "Invalid value for concurrency: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
break;
case OPT_SLAP_EXECUTE_NUMBER:
+ errno= 0;
opt_execute_number= (unsigned int)strtoul(optarg, (char **)NULL, 10);
+ if (errno != 0)
+ {
+ fprintf(stderr, "Invalid value for execute: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
break;
case OPT_SLAP_INITIAL_LOAD:
+ errno= 0;
opt_createial_load= (unsigned int)strtoul(optarg, (char **)NULL, 10);
+ if (errno != 0)
+ {
+ fprintf(stderr, "Invalid value for initial load: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
break;
case OPT_QUIET:
/* We always used non-blocking IO for load since it is faster */
memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_NO_BLOCK, 0);
- pairs_st *pairs= pairs_generate(number_of, 400);
+ pairs_st *pairs= pairs_generate(number_of, VALUE_BYTES);
*actual_loaded= execute_set(memc_clone, pairs, number_of);
memcached_free(memc_clone);