From: Michael Wallner Date: Thu, 12 Nov 2020 11:15:57 +0000 (+0100) Subject: bin/memslap: execute_* functions are not common X-Git-Tag: 1.1.0-beta1~113 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=bc9d34a66017dfd3b8430d45ded8ecf13ad4f1a8;p=awesomized%2Flibmemcached bin/memslap: execute_* functions are not common --- diff --git a/src/bin/common/CMakeLists.txt b/src/bin/common/CMakeLists.txt index 858fd598..b068045f 100644 --- a/src/bin/common/CMakeLists.txt +++ b/src/bin/common/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(libclient_common STATIC utilities.cc generator.cc execute.cc) +add_library(libclient_common STATIC utilities.cc generator.cc) add_library(client_common ALIAS libclient_common) target_link_libraries(libclient_common PUBLIC libmemcached) target_include_directories(libclient_common PUBLIC diff --git a/src/bin/common/execute.cc b/src/bin/common/execute.cc deleted file mode 100644 index 2e436af8..00000000 --- a/src/bin/common/execute.cc +++ /dev/null @@ -1,117 +0,0 @@ -/* - +--------------------------------------------------------------------+ - | libmemcached - C/C++ Client Library for memcached | - +--------------------------------------------------------------------+ - | Redistribution and use in source and binary forms, with or without | - | modification, are permitted under the terms of the BSD license. | - | You should have received a copy of the license in a bundled file | - | named LICENSE; in case you did not receive a copy you can review | - | the terms online at: https://opensource.org/licenses/BSD-3-Clause | - +--------------------------------------------------------------------+ - | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ | - | Copyright (c) 2020 Michael Wallner | - +--------------------------------------------------------------------+ -*/ - -#include "mem_config.h" -#include "execute.h" - -unsigned int execute_set(memcached_st *memc, pairs_st *pairs, unsigned int number_of) { - uint32_t count = 0; - for (; count < number_of; ++count) { - memcached_return_t rc = memcached_set(memc, pairs[count].key, pairs[count].key_length, - pairs[count].value, pairs[count].value_length, 0, 0); - if (memcached_failed(rc)) { - fprintf(stderr, "%s:%d Failure on %u insert (%s) of %.*s\n", __FILE__, __LINE__, count, - memcached_last_error_message(memc), (unsigned int) pairs[count].key_length, - pairs[count].key); - - // We will try to reconnect and see if that fixes the issue - memcached_quit(memc); - - return count; - } - } - - return count; -} - -/* - Execute a memcached_get() on a set of pairs. - Return the number of rows retrieved. -*/ -unsigned int execute_get(memcached_st *memc, pairs_st *pairs, unsigned int number_of) { - unsigned int x; - unsigned int retrieved; - - for (retrieved = 0, x = 0; x < number_of; x++) { - size_t value_length; - uint32_t flags; - - unsigned int fetch_key = (unsigned int) ((unsigned int) random() % number_of); - - memcached_return_t rc; - char *value = memcached_get(memc, pairs[fetch_key].key, pairs[fetch_key].key_length, - &value_length, &flags, &rc); - - if (memcached_failed(rc)) { - fprintf(stderr, "%s:%d Failure on read(%s) of %.*s\n", __FILE__, __LINE__, - memcached_last_error_message(memc), (unsigned int) pairs[fetch_key].key_length, - pairs[fetch_key].key); - } else { - retrieved++; - } - - ::free(value); - } - - return retrieved; -} - -/** - * Callback function to count the number of results - */ -static memcached_return_t callback_counter(const memcached_st *ptr, memcached_result_st *result, - void *context) { - (void) ptr; - (void) result; - unsigned int *counter = (unsigned int *) context; - *counter = *counter + 1; - - return MEMCACHED_SUCCESS; -} - -/** - * Try to run a large mget to get all of the keys - * @param memc memcached handle - * @param keys the keys to get - * @param key_length the length of the keys - * @param number_of the number of keys to try to get - * @return the number of keys received - */ -unsigned int execute_mget(memcached_st *memc, const char *const *keys, size_t *key_length, - unsigned int number_of) { - unsigned int retrieved = 0; - memcached_execute_fn callbacks[] = {callback_counter}; - memcached_return_t rc; - rc = memcached_mget_execute(memc, keys, key_length, (size_t) number_of, callbacks, &retrieved, 1); - - if (rc == MEMCACHED_SUCCESS || rc == MEMCACHED_NOTFOUND || rc == MEMCACHED_BUFFERED - || rc == MEMCACHED_END) - { - rc = memcached_fetch_execute(memc, callbacks, (void *) &retrieved, 1); - if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_NOTFOUND && rc != MEMCACHED_END) { - fprintf(stderr, "%s:%d Failed to execute mget: %s\n", __FILE__, __LINE__, - memcached_strerror(memc, rc)); - memcached_quit(memc); - return 0; - } - } else { - fprintf(stderr, "%s:%d Failed to execute mget: %s\n", __FILE__, __LINE__, - memcached_strerror(memc, rc)); - memcached_quit(memc); - return 0; - } - - return retrieved; -} diff --git a/src/bin/common/execute.h b/src/bin/common/execute.h deleted file mode 100644 index 9b08d8ad..00000000 --- a/src/bin/common/execute.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - +--------------------------------------------------------------------+ - | libmemcached - C/C++ Client Library for memcached | - +--------------------------------------------------------------------+ - | Redistribution and use in source and binary forms, with or without | - | modification, are permitted under the terms of the BSD license. | - | You should have received a copy of the license in a bundled file | - | named LICENSE; in case you did not receive a copy you can review | - | the terms online at: https://opensource.org/licenses/BSD-3-Clause | - +--------------------------------------------------------------------+ - | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ | - | Copyright (c) 2020 Michael Wallner | - +--------------------------------------------------------------------+ -*/ - -#pragma once - -#include - -#include "libmemcached-1.0/memcached.h" -#include "generator.h" - -#ifdef __cplusplus -extern "C" { -#endif - -unsigned int execute_set(memcached_st *memc, pairs_st *pairs, unsigned int number_of); -unsigned int execute_get(memcached_st *memc, pairs_st *pairs, unsigned int number_of); -unsigned int execute_mget(memcached_st *memc, const char *const *keys, size_t *key_length, - unsigned int number_of); - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/src/bin/memslap.cc b/src/bin/memslap.cc index 621217e2..bc187a82 100644 --- a/src/bin/memslap.cc +++ b/src/bin/memslap.cc @@ -37,7 +37,6 @@ #include "client_options.h" #include "utilities.h" #include "generator.h" -#include "execute.h" #define DEFAULT_INITIAL_LOAD 10000 #define DEFAULT_EXECUTE_NUMBER 10000 @@ -125,6 +124,107 @@ static char *opt_servers = NULL; static bool opt_udp_io = false; test_t opt_test = SET_TEST; + +unsigned int execute_set(memcached_st *memc, pairs_st *pairs, unsigned int number_of) { + uint32_t count = 0; + for (; count < number_of; ++count) { + memcached_return_t rc = memcached_set(memc, pairs[count].key, pairs[count].key_length, + pairs[count].value, pairs[count].value_length, 0, 0); + if (memcached_failed(rc)) { + fprintf(stderr, "%s:%d Failure on %u insert (%s) of %.*s\n", __FILE__, __LINE__, count, + memcached_last_error_message(memc), (unsigned int) pairs[count].key_length, + pairs[count].key); + + // We will try to reconnect and see if that fixes the issue + memcached_quit(memc); + + return count; + } + } + + return count; +} + +/* + Execute a memcached_get() on a set of pairs. + Return the number of rows retrieved. +*/ +static unsigned int execute_get(memcached_st *memc, pairs_st *pairs, unsigned int number_of) { + unsigned int x; + unsigned int retrieved; + + for (retrieved = 0, x = 0; x < number_of; x++) { + size_t value_length; + uint32_t flags; + + unsigned int fetch_key = (unsigned int) ((unsigned int) random() % number_of); + + memcached_return_t rc; + char *value = memcached_get(memc, pairs[fetch_key].key, pairs[fetch_key].key_length, + &value_length, &flags, &rc); + + if (memcached_failed(rc)) { + fprintf(stderr, "%s:%d Failure on read(%s) of %.*s\n", __FILE__, __LINE__, + memcached_last_error_message(memc), (unsigned int) pairs[fetch_key].key_length, + pairs[fetch_key].key); + } else { + retrieved++; + } + + ::free(value); + } + + return retrieved; +} + +/** + * Callback function to count the number of results + */ +static memcached_return_t callback_counter(const memcached_st *ptr, memcached_result_st *result, + void *context) { + (void) ptr; + (void) result; + unsigned int *counter = (unsigned int *) context; + *counter = *counter + 1; + + return MEMCACHED_SUCCESS; +} + +/** + * Try to run a large mget to get all of the keys + * @param memc memcached handle + * @param keys the keys to get + * @param key_length the length of the keys + * @param number_of the number of keys to try to get + * @return the number of keys received + */ +static unsigned int execute_mget(memcached_st *memc, const char *const *keys, size_t *key_length, + unsigned int number_of) { + unsigned int retrieved = 0; + memcached_execute_fn callbacks[] = {callback_counter}; + memcached_return_t rc; + rc = memcached_mget_execute(memc, keys, key_length, (size_t) number_of, callbacks, &retrieved, 1); + + if (rc == MEMCACHED_SUCCESS || rc == MEMCACHED_NOTFOUND || rc == MEMCACHED_BUFFERED + || rc == MEMCACHED_END) + { + rc = memcached_fetch_execute(memc, callbacks, (void *) &retrieved, 1); + if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_NOTFOUND && rc != MEMCACHED_END) { + fprintf(stderr, "%s:%d Failed to execute mget: %s\n", __FILE__, __LINE__, + memcached_strerror(memc, rc)); + memcached_quit(memc); + return 0; + } + } else { + fprintf(stderr, "%s:%d Failed to execute mget: %s\n", __FILE__, __LINE__, + memcached_strerror(memc, rc)); + memcached_quit(memc); + return 0; + } + + return retrieved; +} + extern "C" { static __attribute__((noreturn)) void *run_task(void *p) { @@ -151,7 +251,7 @@ static __attribute__((noreturn)) void *run_task(void *p) { case MGET_TEST: execute_mget(context->memc, (const char *const *) context->keys, context->key_lengths, - context->initial_number); + context->initial_number); break; } @@ -159,7 +259,9 @@ static __attribute__((noreturn)) void *run_task(void *p) { pthread_exit(0); } -} + +} // extern "C" + int main(int argc, char *argv[]) { conclusions_st conclusion;