]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rados: bench: add --max-objects 7195/head
authorSage Weil <sage@redhat.com>
Wed, 13 Jan 2016 18:05:49 +0000 (13:05 -0500)
committerSage Weil <sage@redhat.com>
Mon, 25 Jan 2016 16:10:26 +0000 (11:10 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/common/obj_bencher.cc
src/common/obj_bencher.h
src/tools/rados/rados.cc

index 71b077800c08beca3c4c5257a5c9c47438b8b265..a77febc6cb81c2d3a944952b086221af09acddb3 100644 (file)
@@ -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;
index e5cfbd016f6ac56c8893d20dfbee14a2235f7de2..a717c5da0edebbfbda9d939eacd4c8880b74f4b9 100644 (file)
@@ -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);
 
index 8cdb9c8d8e7782922b454374b088eba63e6e872f..36f620bc209de665472ed2e9d99a7b8a1c4eb739 100644 (file)
@@ -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)) {