From fd57d99b6bbd2ec7d5e4c1f4f7cfcf4ba351050b Mon Sep 17 00:00:00 2001 From: Haomai Wang Date: Sat, 28 Dec 2013 17:57:43 +0800 Subject: [PATCH] Fix rbd bench-write improper behavior "rbd bench-write" eject all write operations with the same offset at the same time. It will result in non-objective performance result from this command. fix #7066 Co-Author: Rongze Zhu Signed-off-by: Haomai Wang --- src/rbd.cc | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/rbd.cc b/src/rbd.cc index 2e87b62664d85..1cc792f2be01f 100644 --- a/src/rbd.cc +++ b/src/rbd.cc @@ -913,19 +913,34 @@ static int do_bench_write(librbd::Image& image, uint64_t io_size, uint64_t size = 0; image.size(&size); + vector thread_offset; + uint64_t i; + uint64_t start_pos; + + // disturb all thread's offset, used by seq write + for (i = 0; i < io_threads; i++) { + start_pos = (rand() % (size / io_size)) * io_size; + thread_offset.push_back(start_pos); + } + 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, real_off, io_size, bl)) { + i = 0; + while (i < io_threads && off < io_bytes && + b.start_write(io_threads, thread_offset[i], io_size, bl)) { ++i; ++ios; + off += io_size; + + if (pattern == "rand") { + thread_offset[i] = (rand() % (size / io_size)) * io_size; + } else { + thread_offset[i] += io_size; + if (thread_offset[i] + io_size > size) + thread_offset[i] = 0; + } } utime_t now = ceph_clock_now(NULL); -- 2.39.5