From 67fc8c80ac31b2b89a17d6c258d9cbae6382142e Mon Sep 17 00:00:00 2001 From: Michael Vrable Date: Wed, 24 Feb 2010 14:47:42 -0800 Subject: [PATCH] Implement a synthetic benchmark for bulk reads of file data. --- .gitignore | 1 + microbench/CMakeLists.txt | 3 ++ microbench/readbench.c | 33 ++++++-------- microbench/run.sh | 20 +++++++-- microbench/statbench.c | 90 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 123 insertions(+), 24 deletions(-) create mode 100644 microbench/statbench.c diff --git a/.gitignore b/.gitignore index de1736b..9542663 100644 --- a/.gitignore +++ b/.gitignore @@ -11,5 +11,6 @@ kvstore/lib*.so kvstore/kvstore microbench/bench microbench/readbench +microbench/statbench nfs3/nfsproxy nfs3/synclient diff --git a/microbench/CMakeLists.txt b/microbench/CMakeLists.txt index 80119f5..368517e 100644 --- a/microbench/CMakeLists.txt +++ b/microbench/CMakeLists.txt @@ -4,4 +4,7 @@ target_link_libraries(bench pthread rt) add_executable(readbench readbench.c) target_link_libraries(readbench pthread rt) +add_executable(statbench statbench.c) +target_link_libraries(statbench pthread rt) + set(CMAKE_C_FLAGS "-Wall -std=gnu99 ${CMAKE_C_FLAGS}") diff --git a/microbench/readbench.c b/microbench/readbench.c index 043a2cf..5a397e3 100644 --- a/microbench/readbench.c +++ b/microbench/readbench.c @@ -11,6 +11,7 @@ struct thread_state { pthread_t thread; + const char *filename; int thread_num; long long timestamp; }; @@ -56,40 +57,37 @@ void *benchmark_thread(void *arg) { struct thread_state *ts = (struct thread_state *)arg; - char namebuf[64]; - sprintf(namebuf, "file-%d", ts->thread_num + 1); - printf("Opening %s\n", namebuf); + printf("Opening %s\n", ts->filename); int64_t start, end; start = now_hires(); - struct stat stat_buf; - stat(namebuf, &stat_buf); + //struct stat stat_buf; + //stat(namebuf, &stat_buf); -#if 0 - FILE *f = fopen(namebuf, "rb"); + FILE *f = fopen(ts->filename, "rb"); if (f == NULL) { perror("fopen"); return NULL; } - char buf[4096]; - fread(buf, 1, sizeof(buf), f); -#endif + char buf[65536]; + while (fread(buf, 1, sizeof(buf), f) > 0) { } end = now_hires(); printf("Thread %d: Time = %"PRIi64"\n", ts->thread_num, end - start); - // fclose(f); + fclose(f); return NULL; } -void launch_thread(int i) +void launch_thread(int i, const char *filename) { threads[i].thread_num = i; - printf("Launching thread %d...\n", i); + threads[i].filename = filename; + printf("Launching thread %d [%s]...\n", i, filename); if (pthread_create(&threads[i].thread, NULL, benchmark_thread, &threads[i]) != 0) { fprintf(stderr, "Error launching thread!\n"); exit(1); @@ -104,17 +102,12 @@ void wait_thread(int n) int main(int argc, char *argv[]) { - int threads = 8; - - if (argc > 1) - threads = atoi(argv[1]); - if (threads > MAX_THREADS) - threads = MAX_THREADS; + int threads = argc - 1; printf("Testing with %d threads\n", threads); for (int i = 0; i < threads; i++) { - launch_thread(i); + launch_thread(i, argv[i + 1]); } for (int i = 0; i < threads; i++) { diff --git a/microbench/run.sh b/microbench/run.sh index 9c40e0d..8a0dd74 100755 --- a/microbench/run.sh +++ b/microbench/run.sh @@ -6,6 +6,8 @@ source "$HOME/bin/aws-keys" BLUESKY="$HOME/local/bluesky.git" NFSD="$BLUESKY/nfs3/nfsproxy" +SIZES="32 64 128 256 512 512 1024 1536 2048 2560 3072 3584 4096 5120 6144 7168 8192" + die() { echo "FATAL ERROR: $@" exit 1 @@ -35,6 +37,9 @@ benchmark_setup() { for i in {1..64}; do dd if=/dev/urandom of=/mnt/bluesky/file-$i bs=32k count=1 done + for s in $SIZES; do + dd if=/dev/urandom of=/mnt/bluesky/size-$s bs=1k count=$s + done sleep 15 run_cleanup } @@ -43,10 +48,10 @@ benchmark_cleanup() { echo "Cleaning up from benchmark runs..." 1>&2 } -run_test() { +run_thread_test() { run_setup echo "Running test" 1>&2 - (cd /mnt/bluesky; $BLUESKY/microbench/readbench "$@") >results-t$1-s$BLUESKY_OPT_SYNC_FRONTENDS + (cd /mnt/bluesky; $BLUESKY/microbench/statbench "$@") >results-t$1-s$BLUESKY_OPT_SYNC_FRONTENDS run_cleanup run_setup @@ -57,14 +62,21 @@ run_test() { benchmark_setup +for s in $SIZES; do + run_setup + echo "Running read test $s" 1>&2 + (cd /mnt/bluesky; $BLUESKY/microbench/readbench size-$s) >results-large$s-t1 + run_cleanup +done + export BLUESKY_OPT_SYNC_FRONTENDS=0 for t in 1 2 4 6 8 10 12 14 16 20 24 28 32 40 48 56 64; do - run_test $t + run_thread_test $t done export BLUESKY_OPT_SYNC_FRONTENDS=1 for t in 1 2 4 6 8 10 12 14 16 20 24 28 32 40 48 56 64; do - run_test $t + run_thread_test $t done benchmark_cleanup diff --git a/microbench/statbench.c b/microbench/statbench.c new file mode 100644 index 0000000..5b85668 --- /dev/null +++ b/microbench/statbench.c @@ -0,0 +1,90 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct thread_state { + pthread_t thread; + int thread_num; + long long timestamp; +}; + +#define MAX_THREADS 128 +struct thread_state threads[MAX_THREADS]; + +int64_t now_hires() +{ + struct timespec time; + + if (clock_gettime(CLOCK_REALTIME, &time) != 0) { + perror("clock_gettime"); + return 0; + } + + return (int64_t)(time.tv_sec) * 1000000000 + time.tv_nsec; +} + +void *benchmark_thread(void *arg) +{ + struct thread_state *ts = (struct thread_state *)arg; + + char namebuf[64]; + sprintf(namebuf, "file-%d", ts->thread_num + 1); + printf("Opening %s\n", namebuf); + + int64_t start, end; + + start = now_hires(); + + struct stat stat_buf; + stat(namebuf, &stat_buf); + + end = now_hires(); + printf("Thread %d: Time = %"PRIi64"\n", ts->thread_num, end - start); + + return NULL; +} + +void launch_thread(int i) +{ + threads[i].thread_num = i; + printf("Launching thread %d...\n", i); + if (pthread_create(&threads[i].thread, NULL, benchmark_thread, &threads[i]) != 0) { + fprintf(stderr, "Error launching thread!\n"); + exit(1); + } +} + +void wait_thread(int n) +{ + void *result; + pthread_join(threads[n].thread, &result); +} + +int main(int argc, char *argv[]) +{ + int threads = 8; + + if (argc > 1) + threads = atoi(argv[1]); + if (threads > MAX_THREADS) + threads = MAX_THREADS; + + printf("Testing with %d threads\n", threads); + + for (int i = 0; i < threads; i++) { + launch_thread(i); + } + + for (int i = 0; i < threads; i++) { + wait_thread(i); + } + + return 0; +} -- 2.20.1