]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rados: --num-objects will now cause bench to stop after that many objects
authorSamuel Just <sam.just@inktank.com>
Wed, 5 Jun 2013 19:27:56 +0000 (12:27 -0700)
committerSamuel Just <sam.just@inktank.com>
Fri, 7 Jun 2013 22:59:40 +0000 (15:59 -0700)
Reviewed-by: David Zafman <david.zafman@inktank.com>
Signed-off-by: Samuel Just <sam.just@inktank.com>
src/common/obj_bencher.cc
src/common/obj_bencher.h
src/rados.cc
src/tools/rest_bench.cc

index 7444d687c8ee8c56832b451c783f7b8bf0b796c4..6490b4f5932157be88efb62c61a49aecfe24ffc5 100644 (file)
@@ -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;
index 60159646ad7ef645e74a8e52a46cb0e56bf135c3..d626eda376da53d3a42200127ef8949e8a93c04f 100644 (file)
@@ -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) {
index 230379894542dafadcd3881b88cef2a4c75a8df2..7d6f2160cb4c4d068b0e28d6cc5593b411fb0406 100644 (file)
@@ -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;
   }
index 3b82cbc83387a22480089ef5bf85d680d5e677b3..99fd16b5a344cecf023b01b44bcbc2f9a4cc9c95 100644 (file)
@@ -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;
     }