summaryrefslogtreecommitdiffstats
path: root/src/bench
diff options
context:
space:
mode:
Diffstat (limited to 'src/bench')
-rw-r--r--src/bench/CMakeLists.txt22
-rw-r--r--src/bench/connection.c149
-rw-r--r--src/bench/connection.h4
-rw-r--r--src/bench/helper.h3
-rw-r--r--src/bench/main.c41
-rw-r--r--src/bench/serialize.c5
6 files changed, 125 insertions, 99 deletions
diff --git a/src/bench/CMakeLists.txt b/src/bench/CMakeLists.txt
new file mode 100644
index 0000000..24542a7
--- /dev/null
+++ b/src/bench/CMakeLists.txt
@@ -0,0 +1,22 @@
+cmake_minimum_required(VERSION 3.10)
+
+# set the project name
+project(dnbd3-bench
+ LANGUAGES C)
+
+# add compile option to enable enhanced POSIX pthread features
+add_definitions(-D_GNU_SOURCE)
+
+set(DNBD3_BENCH_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/connection.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/helper.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/main.c)
+set(DNBD3_BENCH_HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/connection.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/helper.h)
+
+add_executable(dnbd3-bench ${DNBD3_BENCH_SOURCE_FILES})
+target_link_libraries(dnbd3-bench dnbd3-version dnbd3-shared ${CMAKE_THREAD_LIBS_INIT})
+install(TARGETS dnbd3-bench RUNTIME DESTINATION bin
+ COMPONENT bench)
+
+add_linter(dnbd3-bench-lint "${DNBD3_BENCH_SOURCE_FILES}" "${DNBD3_BENCH_HEADER_FILES}")
+add_linter_fix(dnbd3-bench-lint-fix "${DNBD3_BENCH_SOURCE_FILES}" "${DNBD3_BENCH_HEADER_FILES}")
diff --git a/src/bench/connection.c b/src/bench/connection.c
index 129ae3c..974bc8a 100644
--- a/src/bench/connection.c
+++ b/src/bench/connection.c
@@ -1,10 +1,10 @@
#include "connection.h"
#include "helper.h"
-#include "../config.h"
-#include "../shared/protocol.h"
-#include "../shared/fdsignal.h"
-#include "../shared/sockhelper.h"
-#include "../shared/log.h"
+#include <dnbd3/config.h>
+#include <dnbd3/shared/protocol.h>
+#include <dnbd3/shared/fdsignal.h>
+#include <dnbd3/shared/sockhelper.h>
+#include <dnbd3/shared/log.h>
#include <stdlib.h>
#include <pthread.h>
@@ -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,14 @@ bool connection_init_n_times(
const char *lowerImage,
const uint16_t rid,
int ntimes,
- BenchCounters* counters,
- bool closeSockets
+ uint64_t blockSize,
+ 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 +56,85 @@ 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 )
+ 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;
+ 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, 3500, 10000 );
+ if ( sock == -1 ) {
+ counters->fails++;
+ logadd( LOG_ERROR, "Could not connect to host (errno=%d)", errno );
+ } 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 * blockSize, blockSize, 0, 0 ) ) {
+ } else if ( !dnbd3_get_block( sock, (((uint64_t)rand() << 16) + rand()) % (remoteSize - blockSize), blockSize, 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 ( reply.cmd != CMD_GET_BLOCK ) {
+ counters->fails++;
+ logadd( LOG_ERROR, "recv: get block reply is not CMD_GET_BLOCK" );
+ } else {
+ int rv, togo = blockSize;
+ do {
+ rv = recv( sock, trash, MIN( sizeof(trash), togo ), MSG_WAITALL|MSG_NOSIGNAL );
+ if ( rv == -1 && errno == EINTR )
+ continue;
+ if ( rv <= 0 )
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 ) ) {
+ togo -= rv;
+ } while ( togo > 0 );
+ if ( togo != 0 ) {
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" );
+ logadd( LOG_ERROR, "recv: get block payload failed (remaining %d)", togo );
} else {
counters->success++;
- break;
- }
- // Failed
- logadd( LOG_DEBUG1, "Server does not offer requested image... " );
- if ( sock != -1 ) {
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..422c93e 100644
--- a/src/bench/connection.h
+++ b/src/bench/connection.h
@@ -1,7 +1,7 @@
#ifndef _CONNECTION_H_
#define _CONNECTION_H_
-#include "../shared/fdsignal.h"
+#include <dnbd3/shared/fdsignal.h>
#include <stdbool.h>
#include <stdint.h>
#include "helper.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, uint64_t blockSize, BenchCounters* counters);
bool connection_init(const char *hosts, const char *image, const uint16_t rid);
diff --git a/src/bench/helper.h b/src/bench/helper.h
index 8342a79..53f32bf 100644
--- a/src/bench/helper.h
+++ b/src/bench/helper.h
@@ -1,7 +1,7 @@
#ifndef IMAGEHELPER_H
#define IMAGEHELPER_H
-#include "../types.h"
+#include <dnbd3/types.h>
#include <netdb.h>
#include <stdbool.h>
@@ -29,6 +29,7 @@ typedef struct BenchThreadData {
char* server_address;
char * image_name;
int runs;
+ int bs;
int threadNumber;
bool closeSockets;
} BenchThreadData;
diff --git a/src/bench/main.c b/src/bench/main.c
index 2f32dbf..37e2821 100644
--- a/src/bench/main.c
+++ b/src/bench/main.c
@@ -4,8 +4,9 @@
#include "connection.h"
#include "helper.h"
-#include "../shared/protocol.h"
-#include "../shared/log.h"
+#include <dnbd3/shared/protocol.h>
+#include <dnbd3/shared/log.h>
+#include <dnbd3/version.h>
#include <stdio.h>
#include <stdlib.h>
@@ -17,12 +18,9 @@
#define debugf(...) do { logadd( LOG_DEBUG1, __VA_ARGS__ ); } while (0)
-/* Debug/Benchmark variables */
-static bool useDebug = false;
-
-
static void printUsage(char *argv0, int exitCode)
{
+ printf( "Version: %s\n", DNBD3_VERSION_LONG );
printf( "Usage: %s [--debug] --host <serverAddress(es)> --image <imageName> [--rid revision]\n", argv0 );
printf( "Or: %s [-d] -h <serverAddress(es)> -i <imageName> [-r revision]\n", argv0 );
printf( " -h --host List of space separated hosts to use\n" );
@@ -30,19 +28,18 @@ static void printUsage(char *argv0, int exitCode)
printf( " -r --rid Revision to use (omit or pass 0 for latest)\n" );
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 );
+ printf( " -b --blocksize Size of blocks to request (def. 4096)\n" );
exit( exitCode );
}
-static const char *optString = "h:i:n:t:HvVd";
+static const char *optString = "b:h:i:n:t:Hv";
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' },
+ { "blocksize", required_argument, NULL, 'b' },
+ { "help", no_argument, NULL, 'H' },
{ "version", no_argument, NULL, 'v' },
{ 0, 0, 0, 0 }
};
@@ -59,11 +56,11 @@ 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->bs,
+ data->counter);
printf("Thread #%d finished\n", data->threadNumber);
return NULL;
}
@@ -77,6 +74,9 @@ int main(int argc, char *argv[])
bool closeSockets = false;
int n_runs = 100;
int n_threads = 1;
+ int bs = 4096;
+
+ log_init();
if ( argc <= 1 || strcmp( argv[1], "--help" ) == 0 || strcmp( argv[1], "--usage" ) == 0 ) {
printUsage( argv[0], 0 );
@@ -85,10 +85,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);
@@ -96,15 +96,15 @@ int main(int argc, char *argv[])
case 't':
n_threads = atoi(optarg);
break;
+ case 'b':
+ bs = atoi(optarg);
+ break;
case 'c':
closeSockets = true;
break;
case 'H':
printUsage( argv[0], 0 );
break;
- case 'd':
- useDebug = true;
- break;
default:
printUsage( argv[0], EXIT_FAILURE );
}
@@ -126,6 +126,7 @@ int main(int argc, char *argv[])
server_address,
image_Name,
n_runs,
+ bs,
i,
closeSockets};
threadData[i] = tmp2;
diff --git a/src/bench/serialize.c b/src/bench/serialize.c
deleted file mode 100644
index 4934132..0000000
--- a/src/bench/serialize.c
+++ /dev/null
@@ -1,5 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include <stdint.h>
-
-#include "../serialize.c"