From 17991cd5a04950555e985d3aef67c18ddd12a096 Mon Sep 17 00:00:00 2001 From: Igor Canadi Date: Mon, 28 Oct 2013 16:31:44 -0700 Subject: [PATCH] Fix data race in BlobStore benchmark Summary: Apparently C++ doesn't like it if you copy around its atomic<> variables. When running a benchmark for a longer time, benchmark used to stall. Changed WorkerThread in config to WorkerThread*. It works now. Test Plan: Ran benchmark Reviewers: dhruba Reviewed By: dhruba CC: leveldb Differential Revision: https://reviews.facebook.net/D13731 --- tools/blob_store_bench.cc | 54 +++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/tools/blob_store_bench.cc b/tools/blob_store_bench.cc index e2118efe7..0d0751ead 100644 --- a/tools/blob_store_bench.cc +++ b/tools/blob_store_bench.cc @@ -125,16 +125,20 @@ static void WorkerThreadBody(void* arg) { t->stopped.store(true); } -Result StartBenchmark(vector& config) { +Result StartBenchmark(vector& config) { for (auto w : config) { - env->StartThread(WorkerThreadBody, &w); + env->StartThread(WorkerThreadBody, w); } Result result; for (auto w : config) { - while (!w.stopped.load()); - result = result + w.result; + while (!w->stopped.load()); + result = result + w->result; + } + + for (auto w : config) { + delete w; } delete bs; @@ -142,7 +146,7 @@ Result StartBenchmark(vector& config) { return result; } -vector SetupBenchmarkBalanced() { +vector SetupBenchmarkBalanced() { string test_path; env->GetTestDirectory(&test_path); test_path.append("/blob_store"); @@ -160,19 +164,19 @@ vector SetupBenchmarkBalanced() { bs = new BlobStore(test_path, block_size, file_size / block_size, 10000, env); - vector config; + vector config; for (int i = 0; i < number_of_threads; ++i) { - config.push_back(WorkerThread(data_read_from, - data_read_to, - read_write_ratio, - working_set_size)); + config.push_back(new WorkerThread(data_read_from, + data_read_to, + read_write_ratio, + working_set_size)); }; return config; } -vector SetupBenchmarkWriteHeavy() { +vector SetupBenchmarkWriteHeavy() { string test_path; env->GetTestDirectory(&test_path); test_path.append("/blob_store"); @@ -190,19 +194,19 @@ vector SetupBenchmarkWriteHeavy() { bs = new BlobStore(test_path, block_size, file_size / block_size, 10000, env); - vector config; + vector config; for (int i = 0; i < number_of_threads; ++i) { - config.push_back(WorkerThread(data_read_from, - data_read_to, - read_write_ratio, - working_set_size)); + config.push_back(new WorkerThread(data_read_from, + data_read_to, + read_write_ratio, + working_set_size)); }; return config; } -vector SetupBenchmarkReadHeavy() { +vector SetupBenchmarkReadHeavy() { string test_path; env->GetTestDirectory(&test_path); test_path.append("/blob_store"); @@ -220,13 +224,13 @@ vector SetupBenchmarkReadHeavy() { bs = new BlobStore(test_path, block_size, file_size / block_size, 10000, env); - vector config; + vector config; for (int i = 0; i < number_of_threads; ++i) { - config.push_back(WorkerThread(data_read_from, - data_read_to, - read_write_ratio, - working_set_size)); + config.push_back(new WorkerThread(data_read_from, + data_read_to, + read_write_ratio, + working_set_size)); }; return config; @@ -238,19 +242,19 @@ int main(int argc, const char** argv) { { printf("--- Balanced read/write benchmark ---\n"); - vector config = SetupBenchmarkBalanced(); + vector config = SetupBenchmarkBalanced(); Result r = StartBenchmark(config); r.print(); } { printf("--- Write heavy benchmark ---\n"); - vector config = SetupBenchmarkWriteHeavy(); + vector config = SetupBenchmarkWriteHeavy(); Result r = StartBenchmark(config); r.print(); } { printf("--- Read heavy benchmark ---\n"); - vector config = SetupBenchmarkReadHeavy(); + vector config = SetupBenchmarkReadHeavy(); Result r = StartBenchmark(config); r.print(); }