From 3ce648d349e1e51b6324a237a665fbd0f54b8996 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 13 Jan 2016 13:05:49 -0500 Subject: [PATCH] rados: bench: add --max-objects Signed-off-by: Sage Weil --- src/common/obj_bencher.cc | 28 +++++++++++++++++++--------- src/common/obj_bencher.h | 4 ++-- src/tools/rados/rados.cc | 13 ++++++++++++- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/common/obj_bencher.cc b/src/common/obj_bencher.cc index 71b077800c08..a77febc6cb81 100644 --- a/src/common/obj_bencher.cc +++ b/src/common/obj_bencher.cc @@ -207,9 +207,10 @@ void *ObjBencher::status_printer(void *_bencher) { int ObjBencher::aio_bench( int operation, int secondsToRun, int concurrentios, size_t op_size, size_t object_size, + unsigned max_objects, bool cleanup, const std::string& run_name, bool no_verify) { - if (concurrentios <= 0) + if (concurrentios <= 0) return -EINVAL; int num_objects = 0; @@ -221,7 +222,9 @@ int ObjBencher::aio_bench( //get data from previous write run, if available if (operation != OP_WRITE) { - r = fetch_bench_metadata(run_name_meta, &op_size, &object_size, &num_objects, &prevPid); + size_t prev_op_size, prev_object_size; + r = fetch_bench_metadata(run_name_meta, &prev_op_size, &prev_object_size, + &num_objects, &prevPid); if (r < 0) { if (r == -ENOENT) cerr << "Must write data before running a read benchmark!" << std::endl; @@ -250,7 +253,7 @@ int ObjBencher::aio_bench( formatter->open_object_section("bench"); if (OP_WRITE == operation) { - r = write_bench(secondsToRun, concurrentios, run_name_meta); + r = write_bench(secondsToRun, concurrentios, run_name_meta, max_objects); if (r != 0) goto out; } else if (OP_SEQ_READ == operation) { @@ -352,7 +355,8 @@ int ObjBencher::fetch_bench_metadata(const std::string& metadata_file, } int ObjBencher::write_bench(int secondsToRun, - int concurrentios, const string& run_name_meta) { + int concurrentios, const string& run_name_meta, + unsigned max_objects) { if (concurrentios <= 0) return -EINVAL; @@ -360,13 +364,15 @@ int ObjBencher::write_bench(int secondsToRun, out(cout) << "Maintaining " << concurrentios << " concurrent writes of " << data.op_size << " bytes to objects of size " << data.object_size << " for up to " - << secondsToRun << " seconds" + << secondsToRun << " seconds or " + << max_objects << " objects" << std::endl; } else { formatter->dump_format("concurrent_ios", "%d", concurrentios); formatter->dump_format("object_size", "%d", data.object_size); formatter->dump_format("op_size", "%d", data.op_size); formatter->dump_format("seconds_to_run", "%d", secondsToRun); + formatter->dump_format("max_objects", "%d", max_objects); } bufferlist* newContents = 0; @@ -436,7 +442,7 @@ int ObjBencher::write_bench(int secondsToRun, stopTime = data.start_time + runtime; slot = 0; lock.Lock(); - while(ceph_clock_now(cct) < stopTime) { + while (!secondsToRun || ceph_clock_now(cct) < stopTime) { bool found = false; while (1) { int old_slot = slot; @@ -495,6 +501,10 @@ int ObjBencher::write_bench(int secondsToRun, lock.Lock(); ++data.started; ++data.in_flight; + if (max_objects && + data.started > (data.object_size * max_objects + data.op_size - 1) / + data.op_size) + break; } lock.Unlock(); @@ -662,8 +672,8 @@ int ObjBencher::seq_read_bench(int seconds_to_run, int num_objects, int concurre bufferlist *cur_contents; slot = 0; - while (seconds_to_run && (ceph_clock_now(cct) < finish_time) && - num_objects > data.started) { + while ((!seconds_to_run || ceph_clock_now(cct) < finish_time) && + num_objects > data.started) { lock.Lock(); int old_slot = slot; bool found = false; @@ -892,7 +902,7 @@ int ObjBencher::rand_read_bench(int seconds_to_run, int num_objects, int concurr int rand_id; slot = 0; - while (seconds_to_run && (ceph_clock_now(g_ceph_context) < finish_time)) { + while ((!seconds_to_run || ceph_clock_now(g_ceph_context) < finish_time)) { lock.Lock(); int old_slot = slot; bool found = false; diff --git a/src/common/obj_bencher.h b/src/common/obj_bencher.h index e5cfbd016f6a..a717c5da0ede 100644 --- a/src/common/obj_bencher.h +++ b/src/common/obj_bencher.h @@ -75,7 +75,7 @@ protected: int fetch_bench_metadata(const std::string& metadata_file, size_t* op_size, size_t* object_size, int* num_objects, int* prevPid); - int write_bench(int secondsToRun, int concurrentios, const string& run_name_meta); + int write_bench(int secondsToRun, int concurrentios, const string& run_name_meta, unsigned max_objects); int seq_read_bench(int secondsToRun, int num_objects, int concurrentios, int writePid, bool no_verify=false); int rand_read_bench(int secondsToRun, int num_objects, int concurrentios, int writePid, bool no_verify=false); @@ -109,7 +109,7 @@ public: virtual ~ObjBencher() {} int aio_bench( int operation, int secondsToRun, - int concurrentios, size_t op_size, size_t object_size, + int concurrentios, size_t op_size, size_t object_size, unsigned max_objects, bool cleanup, const std::string& run_name, bool no_verify=false); int clean_up(const std::string& prefix, int concurrentios, const std::string& run_name); diff --git a/src/tools/rados/rados.cc b/src/tools/rados/rados.cc index 8cdb9c8d8e77..36f620bc209d 100644 --- a/src/tools/rados/rados.cc +++ b/src/tools/rados/rados.cc @@ -162,6 +162,8 @@ void usage(ostream& out) " set the block size for put/get ops and for write benchmarking\n" " -o object_size\n" " set the object size for put/get ops and for write benchmarking\n" +" --max-objects\n" +" set the max number of objects for write benchmarking\n" " -s name\n" " --snap name\n" " select given snap name for (read) IO\n" @@ -1222,6 +1224,7 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts, int concurrent_ios = 16; unsigned op_size = default_op_size; unsigned object_size = 0; + unsigned max_objects = 0; bool block_size_specified = false; int bench_write_dest = 0; bool cleanup = true; @@ -1313,6 +1316,12 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts, } block_size_specified = true; } + i = opts.find("max-objects"); + if (i != opts.end()) { + if (rados_sistrtoll(i, &max_objects)) { + return -EINVAL; + } + } i = opts.find("snap"); if (i != opts.end()) { snapname = i->second.c_str(); @@ -2537,7 +2546,7 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts, object_size = op_size; ret = bencher.aio_bench(operation, seconds, concurrent_ios, op_size, object_size, - cleanup, run_name, no_verify); + max_objects, cleanup, run_name, no_verify); if (ret != 0) cerr << "error during benchmark: " << ret << std::endl; if (formatter && output) @@ -3016,6 +3025,8 @@ int main(int argc, const char **argv) opts["block-size"] = val; } else if (ceph_argparse_witharg(args, i, &val, "--object-size", (char*)NULL)) { opts["object-size"] = val; + } else if (ceph_argparse_witharg(args, i, &val, "--max-objects", (char*)NULL)) { + opts["max-objects"] = val; } else if (ceph_argparse_witharg(args, i, &val, "-o", (char*)NULL)) { opts["object-size"] = val; } else if (ceph_argparse_witharg(args, i, &val, "-s", "--snap", (char*)NULL)) { -- 2.47.3