From cf7d13a7e90ced80d1a9ad2d2130c310c3d418b5 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 26 Mar 2013 13:33:00 -0700 Subject: [PATCH] rbd: add --io-pattern option to bench-write Write to random offsets instead of sequentially. Signed-off-by: Sage Weil --- src/rbd.cc | 28 +++++++++++++++++++++++----- src/test/cli/rbd/help.t | 6 +++++- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/rbd.cc b/src/rbd.cc index ca74769c5bd39..29f438bd44338 100644 --- a/src/rbd.cc +++ b/src/rbd.cc @@ -113,7 +113,11 @@ void usage() " lock list show locks held on an image\n" " lock add [--shared ] take a lock called id on an image\n" " lock remove release a lock on an image\n" -" bench-write --io-size --io-threads --io-total \n" +" bench-write simple write benchmark\n" +" --io-size write size\n" +" --io-threads ios in flight\n" +" --io-total total bytes to write\n" +" --io-pattern write pattern\n" "\n" ", are [pool/]name[@snap], or you may specify\n" "individual pieces of names with -p/--pool, --image, and/or --snap.\n" @@ -849,7 +853,8 @@ void rbd_bencher_completion(void *vc, void *pc) } static int do_bench_write(librbd::Image& image, uint64_t io_size, - uint64_t io_threads, uint64_t io_bytes) + uint64_t io_threads, uint64_t io_bytes, + string pattern) { rbd_bencher b(&image); @@ -857,10 +862,14 @@ static int do_bench_write(librbd::Image& image, uint64_t io_size, << " io_size " << io_size << " io_threads " << io_threads << " bytes " << io_bytes + << " pattern " << pattern << std::endl; + if (pattern != "rand" && pattern != "seq") + return -EINVAL; + bufferptr bp(io_size); - bp.zero(); + memset(bp.c_str(), rand() & 0xff, io_size); bufferlist bl; bl.push_back(bp); @@ -868,13 +877,20 @@ static int do_bench_write(librbd::Image& image, uint64_t io_size, utime_t last; unsigned ios = 0; + uint64_t size = 0; + image.size(&size); + printf(" SEC OPS OPS/SEC BYTES/SEC\n"); uint64_t off; for (off = 0; off < io_bytes; off += io_size) { b.wait_for(io_threads - 1); uint64_t i = 0; + uint64_t real_off = off; + if (pattern == "rand") { + real_off = (rand() % (size / io_size)) * io_size; + } while (i < io_threads && - b.start_write(io_threads, off, io_size, bl)) { + b.start_write(io_threads, real_off, io_size, bl)) { ++i; ++ios; } @@ -1742,6 +1758,7 @@ int main(int argc, const char **argv) int pretty_format = 0; long long stripe_unit = 0, stripe_count = 0; long long bench_io_size = 4096, bench_io_threads = 16, bench_bytes = 1 << 30; + string bench_pattern = "seq"; std::string val; std::ostringstream err; @@ -1797,6 +1814,7 @@ int main(int argc, const char **argv) } else if (ceph_argparse_withlonglong(args, i, &bench_io_size, &err, "--io-size", (char*)NULL)) { } else if (ceph_argparse_withlonglong(args, i, &bench_io_threads, &err, "--io-threads", (char*)NULL)) { } else if (ceph_argparse_withlonglong(args, i, &bench_bytes, &err, "--io-total", (char*)NULL)) { + } else if (ceph_argparse_witharg(args, i, &bench_pattern, &err, "--io-pattern", (char*)NULL)) { } else if (ceph_argparse_withlonglong(args, i, &stripe_count, &err, "--stripe-count", (char*)NULL)) { } else if (ceph_argparse_witharg(args, i, &val, "--path", (char*)NULL)) { path = strdup(val.c_str()); @@ -2441,7 +2459,7 @@ if (!set_conf_param(v, p1, p2, p3)) { \ break; case OPT_BENCH_WRITE: - r = do_bench_write(image, bench_io_size, bench_io_threads, bench_bytes); + r = do_bench_write(image, bench_io_size, bench_io_threads, bench_bytes, bench_pattern); if (r < 0) { cerr << "bench-write failed: " << cpp_strerror(-r) << std::endl; return EXIT_FAILURE; diff --git a/src/test/cli/rbd/help.t b/src/test/cli/rbd/help.t index 39d2a4c0d4556..e32325d39d3bb 100644 --- a/src/test/cli/rbd/help.t +++ b/src/test/cli/rbd/help.t @@ -39,7 +39,11 @@ lock list show locks held on an image lock add [--shared ] take a lock called id on an image lock remove release a lock on an image - bench-write --io-size --io-threads --io-total + bench-write simple write benchmark + --io-size write size + --io-threads ios in flight + --io-total total bytes to write + --io-pattern write pattern , are [pool/]name[@snap], or you may specify individual pieces of names with -p/--pool, --image, and/or --snap. -- 2.39.5