From 02154a24101eeb9bbcb76e6bb17034bb587021ac Mon Sep 17 00:00:00 2001 From: Samuel Just Date: Wed, 5 Jun 2013 12:27:56 -0700 Subject: rados: --num-objects will now cause bench to stop after that many objects Signed-off-by: Samuel Just --- src/common/obj_bencher.cc | 31 ++++++++++++++++++++----------- src/common/obj_bencher.h | 6 ++++-- src/rados.cc | 3 ++- src/tools/rest_bench.cc | 3 ++- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/common/obj_bencher.cc b/src/common/obj_bencher.cc index 7444d687c8e..6490b4f5932 100644 --- a/src/common/obj_bencher.cc +++ b/src/common/obj_bencher.cc @@ -164,7 +164,10 @@ void *ObjBencher::status_printer(void *_bencher) { return NULL; } -int ObjBencher::aio_bench(int operation, int secondsToRun, int concurrentios, int op_size, bool cleanup) { +int ObjBencher::aio_bench( + int operation, int secondsToRun, + int maxObjectsToCreate, + int concurrentios, int op_size, bool cleanup) { int object_size = op_size; int num_objects = 0; char* contentsChars = new char[op_size]; @@ -203,7 +206,7 @@ int ObjBencher::aio_bench(int operation, int secondsToRun, int concurrentios, in sanitize_object_contents(&data, data.object_size); if (OP_WRITE == operation) { - r = write_bench(secondsToRun, concurrentios); + r = write_bench(secondsToRun, maxObjectsToCreate, concurrentios); if (r != 0) goto out; } else if (OP_SEQ_READ == operation) { @@ -296,10 +299,15 @@ int ObjBencher::fetch_bench_metadata(const std::string& metadata_file, int* obje return 0; } -int ObjBencher::write_bench(int secondsToRun, int concurrentios) { +int ObjBencher::write_bench(int secondsToRun, int maxObjectsToCreate, + int concurrentios) { + if (maxObjectsToCreate > 0 && concurrentios > maxObjectsToCreate) + concurrentios = maxObjectsToCreate; out(cout) << "Maintaining " << concurrentios << " concurrent writes of " - << data.object_size << " bytes for at least " - << secondsToRun << " seconds." << std::endl; + << data.object_size << " bytes for up to " + << secondsToRun << " seconds or " + << maxObjectsToCreate << " objects" + << std::endl; bufferlist* newContents = 0; std::string prefix = generate_object_prefix(); @@ -356,8 +364,9 @@ int ObjBencher::write_bench(int secondsToRun, int concurrentios) { runtime.set_from_double(secondsToRun); stopTime = data.start_time + runtime; slot = 0; - while( ceph_clock_now(g_ceph_context) < stopTime ) { - lock.Lock(); + lock.Lock(); + while( ceph_clock_now(g_ceph_context) < stopTime && + (!maxObjectsToCreate || data.started < maxObjectsToCreate)) { bool found = false; while (1) { int old_slot = slot; @@ -410,15 +419,15 @@ int ObjBencher::write_bench(int secondsToRun, int concurrentios) { if (r < 0) {//naughty; doesn't clean up heap space. goto ERR; } - lock.Lock(); - ++data.started; - ++data.in_flight; - lock.Unlock(); delete contents[slot]; name[slot] = newName; contents[slot] = newContents; newContents = 0; + lock.Lock(); + ++data.started; + ++data.in_flight; } + lock.Unlock(); while (data.finished < data.started) { slot = data.finished % concurrentios; diff --git a/src/common/obj_bencher.h b/src/common/obj_bencher.h index 60159646ad7..d626eda376d 100644 --- a/src/common/obj_bencher.h +++ b/src/common/obj_bencher.h @@ -60,7 +60,7 @@ protected: int fetch_bench_metadata(const std::string& metadata_file, int* object_size, int* num_objects, int* prevPid); - int write_bench(int secondsToRun, int concurrentios); + int write_bench(int secondsToRun, int maxObjects, int concurrentios); int seq_read_bench(int secondsToRun, int concurrentios, int num_objects, int writePid); int clean_up(int num_objects, int prevPid, int concurrentios); @@ -91,7 +91,9 @@ protected: public: ObjBencher() : show_time(false), lock("ObjBencher::lock") {} virtual ~ObjBencher() {} - int aio_bench(int operation, int secondsToRun, int concurrentios, int op_size, bool cleanup); + int aio_bench( + int operation, int secondsToRun, int maxObjectsToCreate, + int concurrentios, int op_size, bool cleanup); int clean_up(const std::string& prefix, int concurrentios); void set_show_time(bool dt) { diff --git a/src/rados.cc b/src/rados.cc index 778a9a6c53f..17e837cc559 100644 --- a/src/rados.cc +++ b/src/rados.cc @@ -1979,7 +1979,8 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts, usage_exit(); RadosBencher bencher(rados, io_ctx); bencher.set_show_time(show_time); - ret = bencher.aio_bench(operation, seconds, concurrent_ios, op_size, cleanup); + ret = bencher.aio_bench(operation, seconds, num_objs, + concurrent_ios, op_size, cleanup); if (ret != 0) cerr << "error during benchmark: " << ret << std::endl; } diff --git a/src/tools/rest_bench.cc b/src/tools/rest_bench.cc index 3b82cbc8338..99fd16b5a34 100644 --- a/src/tools/rest_bench.cc +++ b/src/tools/rest_bench.cc @@ -785,7 +785,8 @@ int main(int argc, const char **argv) if (ret != 0) cerr << "error during cleanup: " << ret << std::endl; } else { - ret = bencher.aio_bench(operation, seconds, concurrent_ios, op_size, cleanup); + ret = bencher.aio_bench(operation, seconds, 0, + concurrent_ios, op_size, cleanup); if (ret != 0) { cerr << "error during benchmark: " << ret << std::endl; } -- cgit v1.2.1