From: tridao Date: Tue, 18 Jul 2023 21:02:33 +0000 (-0300) Subject: Add allocator op metrics X-Git-Tag: v19.0.0~773^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=db95414abd9ee25846d9780c28b04b1509acc048;p=ceph.git Add allocator op metrics Specifically total latency, average latency and total ops Signed-off-by: Tri Dao --- diff --git a/src/test/objectstore/Fragmentation_simulator.cc b/src/test/objectstore/Fragmentation_simulator.cc index c938e67f8594..0619ce172d2e 100644 --- a/src/test/objectstore/Fragmentation_simulator.cc +++ b/src/test/objectstore/Fragmentation_simulator.cc @@ -100,6 +100,7 @@ int FragmentationSimulator::begin_simulation_with_generators() { os->print_status(); os->print_per_object_fragmentation(); os->print_per_access_fragmentation(); + os->print_allocator_profile(); return 0; } diff --git a/src/test/objectstore/ObjectStoreImitator.cc b/src/test/objectstore/ObjectStoreImitator.cc index 6870d9c81f75..2010a39756f5 100644 --- a/src/test/objectstore/ObjectStoreImitator.cc +++ b/src/test/objectstore/ObjectStoreImitator.cc @@ -5,6 +5,7 @@ * Author: Tri Dao, daominhtri0503@gmail.com */ #include "test/objectstore/ObjectStoreImitator.h" +#include "common/Clock.h" #include "common/errno.h" #include "include/ceph_assert.h" #include "include/intarith.h" @@ -14,6 +15,26 @@ #define dout_context cct #define OBJECT_MAX_SIZE 0xffffffff // 32 bits +// ---------- Allocator ---------- + +void ObjectStoreImitator::release_alloc(PExtentVector &old_extents) { + utime_t start = ceph_clock_now(); + alloc->release(old_extents); + alloc_ops++; + alloc_time += static_cast(ceph_clock_now() - start); +} + +int64_t ObjectStoreImitator::allocate_alloc(uint64_t want_size, + uint64_t block_size, + uint64_t max_alloc_size, + int64_t hint, + PExtentVector *extents) { + utime_t start = ceph_clock_now(); + int64_t ret = + alloc->allocate(want_size, block_size, max_alloc_size, hint, extents); + alloc_time += static_cast(ceph_clock_now() - start); + return ret; +} // ---------- Object ----------- @@ -228,6 +249,13 @@ void ObjectStoreImitator::print_per_access_fragmentation() { } } +void ObjectStoreImitator::print_allocator_profile() { + double avg = alloc_time / alloc_ops; + std::cout << "Total alloc ops latency: " << alloc_time + << ", total ops: " << alloc_ops + << ", average alloc op latency: " << avg << std::endl; +} + // ------- Transactions ------- int ObjectStoreImitator::queue_transactions(CollectionHandle &ch, @@ -527,7 +555,7 @@ int ObjectStoreImitator::_do_zero(CollectionRef &c, ObjectRef &o, uint64_t offset, size_t length) { PExtentVector old_extents; o->punch_hole(offset, length, old_extents); - alloc->release(old_extents); + release_alloc(old_extents); return 0; } @@ -609,7 +637,7 @@ int ObjectStoreImitator::_do_write(CollectionRef &c, ObjectRef &o, PExtentVector punched; o->punch_hole(offset, length, punched); - alloc->release(punched); + release_alloc(punched); // all writes will trigger an allocation int r = _do_alloc_write(c, o, bl, offset, length); @@ -655,14 +683,14 @@ int ObjectStoreImitator::_do_alloc_write(CollectionRef coll, ObjectRef &o, PExtentVector prealloc; int64_t prealloc_left = - alloc->allocate(need, min_alloc_size, need, 0, &prealloc); + allocate_alloc(need, min_alloc_size, need, 0, &prealloc); if (prealloc_left < 0 || prealloc_left < (int64_t)need) { derr << __func__ << " failed to allocate 0x" << std::hex << need << " allocated 0x" << (prealloc_left < 0 ? 0 : prealloc_left) << " min_alloc_size 0x" << min_alloc_size << " available 0x " << alloc->get_free() << std::dec << dendl; if (prealloc.size()) - alloc->release(prealloc); + release_alloc(prealloc); return -ENOSPC; } @@ -700,7 +728,7 @@ int ObjectStoreImitator::_do_alloc_write(CollectionRef coll, ObjectRef &o, ++prealloc_pos; } - alloc->release(old_extents); + release_alloc(old_extents); } ceph_assert(prealloc_pos == prealloc.end()); @@ -717,7 +745,7 @@ void ObjectStoreImitator::_do_truncate(CollectionRef &c, ObjectRef &o, PExtentVector old_extents; o->punch_hole(offset, o->size - offset, old_extents); o->size = offset; - alloc->release(old_extents); + release_alloc(old_extents); } int ObjectStoreImitator::_rename(CollectionRef &c, ObjectRef &oldo, diff --git a/src/test/objectstore/ObjectStoreImitator.h b/src/test/objectstore/ObjectStoreImitator.h index 4116ab9b2adc..81a8e83e93ed 100644 --- a/src/test/objectstore/ObjectStoreImitator.h +++ b/src/test/objectstore/ObjectStoreImitator.h @@ -190,8 +190,16 @@ private: ceph::buffer::list &bl, uint32_t op_flags = 0, uint64_t retry_count = 0); + void release_alloc(PExtentVector &old_extents); + int64_t allocate_alloc(uint64_t want_size, uint64_t block_size, + uint64_t max_alloc_size, int64_t hint, + PExtentVector *extents); + // Members + double alloc_time = 0.0; + uint64_t alloc_ops = 0; + boost::scoped_ptr alloc; std::atomic nid_last = {0}; @@ -215,11 +223,10 @@ public: min_alloc_size(min_alloc_size_) {} ~ObjectStoreImitator() = default; - void init_alloc(const std::string &alloc_type, uint64_t size); - void print_status(); - void verify_objects(CollectionHandle &ch); + void verify_objects(CollectionHandle &ch); + void print_status(); // Generate metrics for per-object fragmentation (how fragmented are each // object's extents), defined by: frag_score = 1 - sum((size proportion of // each extents / object size) ^ index of each extent in a vector sorted by @@ -231,6 +238,8 @@ public: // Jumps are how many times we have to stop reading continuous extents void print_per_access_fragmentation(); + // Print allocator average latency + void print_allocator_profile(); // Overrides // This is often not called directly but through queue_transaction