From 9b1cfe9bc09fad8ed0a111ea7db6ebf21def19be Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 6 Aug 2019 11:46:56 +0200 Subject: [BENCH] Fix a couple bugs in stress tester --- src/bench/connection.c | 135 +++++++++++++++++++++++-------------------------- src/bench/connection.h | 2 +- src/bench/main.c | 15 +++--- 3 files changed, 70 insertions(+), 82 deletions(-) (limited to 'src/bench') diff --git a/src/bench/connection.c b/src/bench/connection.c index 129ae3c..2e40019 100644 --- a/src/bench/connection.c +++ b/src/bench/connection.c @@ -18,23 +18,10 @@ static const size_t SHORTBUF = 100; #define SOCKET_KEEPALIVE_TIMEOUT (3) #define MAX_ALTS (8) #define MAX_HOSTS_PER_ADDRESS (2) -// If a server wasn't reachable this many times, we slowly start skipping it on measurements -static const int FAIL_BACKOFF_START_COUNT = 8; #define RTT_COUNT (4) /* Module variables */ - -// Init guard -static bool connectionInitDone = false; -static bool keepRunning = true; - -static struct { - int sockFd; - pthread_mutex_t sendMutex; - dnbd3_signal_t* panicSignal; - dnbd3_host_t currentServer; - uint64_t startupTime; -} connection; +static char trash[4096]; // Known alt servers typedef struct _alt_server { @@ -54,13 +41,13 @@ bool connection_init_n_times( const char *lowerImage, const uint16_t rid, int ntimes, - BenchCounters* counters, - bool closeSockets + BenchCounters* counters ) { for (int run_i = 0; run_i < ntimes; ++run_i) { counters->attempts++; - printf("."); + putchar('.'); + fflush(stdout); int sock = -1; char host[SHORTBUF]; serialized_buffer_t buffer; @@ -68,66 +55,70 @@ bool connection_init_n_times( char *remoteName; uint64_t remoteSize; - if ( !connectionInitDone && keepRunning ) { - dnbd3_host_t tempHosts[MAX_HOSTS_PER_ADDRESS]; - const char *current, *end; - int altIndex = 0; - memset( altservers, 0, sizeof altservers ); - connection.sockFd = -1; - current = hosts; - do { - // Get next host from string - while ( *current == ' ' ) current++; - end = strchr( current, ' ' ); - size_t len = (end == NULL ? SHORTBUF : (size_t)( end - current ) + 1); - if ( len > SHORTBUF ) len = SHORTBUF; - snprintf( host, len, "%s", current ); - int newHosts = sock_resolveToDnbd3Host( host, tempHosts, MAX_HOSTS_PER_ADDRESS ); - for ( int i = 0; i < newHosts; ++i ) { - if ( altIndex >= MAX_ALTS ) - break; - altservers[altIndex].host = tempHosts[i]; - altIndex += 1; - } - current = end + 1; - } while ( end != NULL && altIndex < MAX_ALTS ); - logadd( LOG_INFO, "Got %d servers from init call", altIndex ); - // Connect - for ( int i = 0; i < altIndex; ++i ) { - if ( altservers[i].host.type == 0 ) - continue; - // Try to connect - sock = sock_connect( &altservers[i].host, 500, SOCKET_KEEPALIVE_TIMEOUT * 1000 ); - if ( sock == -1 ) { - counters->fails++; - logadd( LOG_ERROR, "Could not connect to host" ); - } else if ( !dnbd3_select_image( sock, lowerImage, rid, 0 ) ) { - counters->fails++; - logadd( LOG_ERROR, "Could not send select image" ); - } else if ( !dnbd3_select_image_reply( &buffer, sock, &remoteVersion, &remoteName, &remoteRid, &remoteSize ) ) { - counters->fails++; - logadd( LOG_ERROR, "Could not read select image reply (%d)", errno ); - } else if ( rid != 0 && rid != remoteRid ) { - counters->fails++; - logadd( LOG_ERROR, "rid mismatch" ); - } else { - counters->success++; + dnbd3_host_t tempHosts[MAX_HOSTS_PER_ADDRESS]; + const char *current, *end; + int altIndex = 0; + memset( altservers, 0, sizeof altservers ); + current = hosts; + do { + // Get next host from string + while ( *current == ' ' ) current++; + end = strchr( current, ' ' ); + size_t len = (end == NULL ? SHORTBUF : (size_t)( end - current ) + 1); + if ( len > SHORTBUF ) len = SHORTBUF; + snprintf( host, len, "%s", current ); + int newHosts = sock_resolveToDnbd3Host( host, tempHosts, MAX_HOSTS_PER_ADDRESS ); + for ( int i = 0; i < newHosts; ++i ) { + if ( altIndex >= MAX_ALTS ) break; - } - // Failed - logadd( LOG_DEBUG1, "Server does not offer requested image... " ); - if ( sock != -1 ) { - close( sock ); - sock = -1; - } + altservers[altIndex].host = tempHosts[i]; + altIndex += 1; } + current = end + 1; + } while ( end != NULL && altIndex < MAX_ALTS ); + // Connect + for ( int i = 0; i < altIndex; ++i ) { + if ( altservers[i].host.type == 0 ) + continue; + // Try to connect + dnbd3_reply_t reply; + sock = sock_connect( &altservers[i].host, 500, SOCKET_KEEPALIVE_TIMEOUT * 1000 ); + if ( sock == -1 ) { + counters->fails++; + logadd( LOG_ERROR, "Could not connect to host" ); + } else if ( !dnbd3_select_image( sock, lowerImage, rid, 0 ) ) { + counters->fails++; + logadd( LOG_ERROR, "Could not send select image" ); + } else if ( !dnbd3_select_image_reply( &buffer, sock, &remoteVersion, &remoteName, &remoteRid, &remoteSize ) ) { + counters->fails++; + logadd( LOG_ERROR, "Could not read select image reply (%d)", errno ); + } else if ( rid != 0 && rid != remoteRid ) { + counters->fails++; + logadd( LOG_ERROR, "rid mismatch" ); + } else if ( !dnbd3_get_block( sock, run_i * 4096, 4096, 0, 0 ) ) { + counters->fails++; + logadd( LOG_ERROR, "send: get block failed" ); + } else if ( !dnbd3_get_reply( sock, &reply ) ) { + counters->fails++; + logadd( LOG_ERROR, "recv: get block header failed" ); + } else if ( recv( sock, trash, sizeof(trash), 0 ) != sizeof(trash) ) { + counters->fails++; + logadd( LOG_ERROR, "recv: get block payload failed" ); + } else { + counters->success++; + close( sock ); + sock = -1; + continue; + } + // Failed if ( sock != -1 ) { - // connectionInitDone = true; - if (closeSockets) { - close( sock ); - } + close( sock ); + sock = -1; } } + if ( sock != -1 ) { + close( sock ); + } } return true; } diff --git a/src/bench/connection.h b/src/bench/connection.h index 9cb59ef..ff71e15 100644 --- a/src/bench/connection.h +++ b/src/bench/connection.h @@ -19,7 +19,7 @@ typedef struct _dnbd3_async { } dnbd3_async_t; -bool connection_init_n_times(const char *hosts, const char *image, const uint16_t rid, int ntimes, BenchCounters* counters, bool closeSockets); +bool connection_init_n_times(const char *hosts, const char *image, const uint16_t rid, int ntimes, BenchCounters* counters); bool connection_init(const char *hosts, const char *image, const uint16_t rid); diff --git a/src/bench/main.c b/src/bench/main.c index 2f32dbf..c86af81 100644 --- a/src/bench/main.c +++ b/src/bench/main.c @@ -31,8 +31,6 @@ static void printUsage(char *argv0, int exitCode) printf( " -n --runs Number of connection attempts per thread\n" ); printf( " -t --threads number of threads\n" ); printf( " -l --log Write log to given location\n" ); - printf( " -d --debug Don't fork and print debug output (fuse > stderr, dnbd3 > stdout)\n" ); - // // fuse_main( 2, arg, &dnbd3_fuse_no_operations, NULL ); exit( exitCode ); } @@ -41,8 +39,8 @@ static const struct option longOpts[] = { { "host", required_argument, NULL, 'h' }, { "image", required_argument, NULL, 'i' }, { "nruns", optional_argument, NULL, 'n' }, - { "threads", optional_argument, NULL, 't' }, - { "help", optional_argument, NULL, 'H' }, + { "threads", required_argument, NULL, 't' }, + { "help", required_argument, NULL, 'H' }, { "version", no_argument, NULL, 'v' }, { 0, 0, 0, 0 } }; @@ -59,11 +57,10 @@ void* runBenchThread(void* t) { BenchThreadData* data = t; connection_init_n_times( data->server_address, - data->server_address, + data->image_name, 0, data->runs, - data->counter, - data->closeSockets); + data->counter); printf("Thread #%d finished\n", data->threadNumber); return NULL; } @@ -85,10 +82,10 @@ int main(int argc, char *argv[]) while ( ( opt = getopt_long( argc, argv, optString, longOpts, &lidx ) ) != -1 ) { switch ( opt ) { case 'h': - server_address = optarg; + server_address = strdup(optarg); break; case 'i': - image_Name = optarg; + image_Name = strdup(optarg); break; case 'n': n_runs = atoi(optarg); -- cgit v1.2.3-55-g7522