From 2a45c2cda8a9f7a953ca8d7b8db0e677018464a9 Mon Sep 17 00:00:00 2001 From: sears Date: Mon, 9 Aug 2010 20:21:41 +0000 Subject: [PATCH] add no-op network call, and a simple benchmark that exercises it git-svn-id: svn+ssh://svn.corp.yahoo.com/yahoo/yrl/labs/pnuts/code/logstore@980 8dad8b1f-cf64-0410-95b6-bcf113ffbcfe --- CMakeLists.txt | 4 +- benchmarks/CMakeLists.txt | 1 + benchmarks/tcpclient_noop.cpp | 75 +++++++++++++++++++++++++++++++++++ logserver.cpp | 6 +++ network.h | 5 ++- 5 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 benchmarks/CMakeLists.txt create mode 100644 benchmarks/tcpclient_noop.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0adc23e..adc73d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ Project(Stasis) SET(PACKAGE_VERSION 1) -SUBDIRS(test util) +SUBDIRS(test util benchmarks) # Main decisions SET(BUILD_SHARED_LIBS ON) @@ -55,7 +55,7 @@ if(NOT HAVE_STASIS) message(STATUS "stasis not found; only building client library") endif(NOT HAVE_STASIS) -SET(CLIENT_LIBRARIES logstore_client) +SET(CLIENT_LIBRARIES logstore_client pthread) IF ( "${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" ) SET(COMMON_LIBRARIES logstore stasis m pthread stdc++) diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt new file mode 100644 index 0000000..83a25e8 --- /dev/null +++ b/benchmarks/CMakeLists.txt @@ -0,0 +1 @@ +CREATE_CLIENT_EXECUTABLE(tcpclient_noop) diff --git a/benchmarks/tcpclient_noop.cpp b/benchmarks/tcpclient_noop.cpp new file mode 100644 index 0000000..bc0838c --- /dev/null +++ b/benchmarks/tcpclient_noop.cpp @@ -0,0 +1,75 @@ +/* + * tcpclient_noop.cpp + * + * Created on: Feb 23, 2010 + * Author: sears + */ + +#include "../tcpclient.h" +#include "../network.h" +#include "../datatuple.h" + +void usage(char * argv[]) { + fprintf(stderr, "usage %s numthreads threadopcount [host [port]]\n", argv[0]); +} + +#include "../util/util_main.h" +#include +int threadopcount; + +int thrargc; +char ** thrargv; + +void * worker (void * arg) { + logstore_handle_t * l = util_open_conn(thrargc-2, thrargv+2); + for(int i = 0; i < threadopcount; i++) { + datatuple * ret = logstore_client_op(l, OP_DBG_NOOP); + if(ret == NULL) { + perror("No-op failed"); return (void*)-1; + } else { + datatuple::freetuple(ret); + } + } + logstore_client_close(l); + return 0; +} + +int main(int argc, char * argv[]) { + if(argc < 3) { + usage(argv); + return 1; + } + thrargc = argc; + thrargv = argv; + + int numthreads = atoi(argv[1]); + threadopcount = (atoi(argv[2])/numthreads); + + pthread_t * threads = (pthread_t*)malloc(sizeof(*threads) * numthreads); + + struct timeval start, stop; + gettimeofday(&start, 0); + for(int i = 0; i < numthreads; i++) { + pthread_create(&threads[i], 0, worker, 0); + } + int had_err = 0; + for(int i = 0; i < numthreads; i++) { + void * err; + pthread_join(threads[i], &err); + if(err) { + had_err = 1; + } + } + gettimeofday(&stop,0); + if(!had_err) { + double startf = ((double)start.tv_sec) + (double)start.tv_usec / 1000000.0; + double stopf = ((double)stop.tv_sec) + (double)stop.tv_usec / 1000000.0; + double elapsed = stopf -startf; + printf("%5d threads, %6d ops/thread, %6.2f seconds, %7.1f ops/thread-second, %6.1f ops/sec\n", + numthreads, threadopcount, elapsed, ((double)threadopcount)/elapsed, (((double)numthreads)*(double)threadopcount)/elapsed); + } + free(threads); + return 0; + +} + diff --git a/logserver.cpp b/logserver.cpp index 8b2cf20..03de589 100644 --- a/logserver.cpp +++ b/logserver.cpp @@ -796,6 +796,9 @@ int op_dbg_drop_database(pthread_data * data) { fprintf(stderr, "...DROP DATABASE COMPLETE\n"); return writeoptosocket(*(data->workitem), LOGSTORE_RESPONSE_SUCCESS); } +int op_dbg_noop(pthread_data * data) { + return writeoptosocket(*(data->workitem), LOGSTORE_RESPONSE_SUCCESS); +} int dispatch_request(network_op_t opcode, datatuple * tuple, datatuple * tuple2, pthread_data* data) { int err = 0; @@ -841,6 +844,9 @@ int dispatch_request(network_op_t opcode, datatuple * tuple, datatuple * tuple2, { err = op_dbg_drop_database(data); } + else if(opcode == OP_DBG_NOOP) { + err = op_dbg_noop(data); + } return err; } diff --git a/network.h b/network.h index 4da28b3..1d566c5 100644 --- a/network.h +++ b/network.h @@ -43,9 +43,10 @@ static const network_op_t OP_STAT_PERF_REPORT = 15; static const network_op_t OP_STAT_HISTOGRAM = 16; // Return N approximately equal size partitions (including split points + cardinalities) N=1 estimates table cardinality. -static const network_op_t OP_DBG_DROP_DATABASE = 17; +static const network_op_t OP_DBG_DROP_DATABASE = 17; static const network_op_t OP_DBG_BLOCKMAP = 18; -static const network_op_t LOGSTORE_LAST_REQUEST_CODE = 18; +static const network_op_t OP_DBG_NOOP = 19; +static const network_op_t LOGSTORE_LAST_REQUEST_CODE = 19; //error codes static const network_op_t LOGSTORE_FIRST_ERROR = 27;