From b5737d0b620202f4c7d7d7bdb08cd79908892c51 Mon Sep 17 00:00:00 2001 From: Maged Michael Date: Mon, 17 Apr 2017 17:59:47 -0700 Subject: [PATCH] Flat combining: Update statistics. Summary: Modified FC stats. Added number of sessions and removed the number of out-of-memory record allocations. Removed locking from reading stats to avoid deadlock if the lock is already held. Reading stats now assumes exclusive access. Reviewed By: djwatson Differential Revision: D4857132 fbshipit-source-id: 81e4f25040af3691f3e82fe3794ee72c7ff53a99 --- .../flat_combining/FlatCombining.h | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/folly/experimental/flat_combining/FlatCombining.h b/folly/experimental/flat_combining/FlatCombining.h index 445d29a3..5f678596 100644 --- a/folly/experimental/flat_combining/FlatCombining.h +++ b/folly/experimental/flat_combining/FlatCombining.h @@ -84,7 +84,7 @@ namespace folly { /// class ConcurrentFoo : public FlatCombining { /// Foo foo_; // sequential data structure /// public: -/// T bar(V v) { // thread-safe execution of foo_.bar(v) +/// T bar(V& v) { // thread-safe execution of foo_.bar(v) /// T result; /// // Note: fn must be copyable to folly::Function without dynamic /// // allocation. Otherwise, it is recommended to use the custom @@ -369,7 +369,6 @@ class FlatCombining { Rec* allocRec() { auto idx = recsPool_.allocIndex(); if (idx == NULL_INDEX) { - outOfSpaceCount_.fetch_add(1); return nullptr; } Rec& rec = recsPool_[idx]; @@ -386,20 +385,24 @@ class FlatCombining { recsPool_.recycleIndex(idx); } - // Returns a count of the number of combined operations so far. - uint64_t getCombinedOpCount() { - std::lock_guard guard(m_); + // Returns the number of uncombined operations so far. + uint64_t getNumUncombined() const { + return uncombined_; + } + + // Returns the number of combined operations so far. + uint64_t getNumCombined() const { return combined_; } - // Returns a count of the number of combining passes so far. - uint64_t getCombiningPasses() { - std::lock_guard guard(m_); + // Returns the number of combining passes so far. + uint64_t getNumPasses() const { return passes_; } - uint64_t getOutOfSpaceCount() { - return outOfSpaceCount_.load(); + // Returns the number of combining sessions so far. + uint64_t getNumSessions() const { + return sessions_; } protected: @@ -424,10 +427,10 @@ class FlatCombining { Pool recsPool_; FOLLY_ALIGN_TO_AVOID_FALSE_SHARING + uint64_t uncombined_ = 0; uint64_t combined_ = 0; uint64_t passes_ = 0; uint64_t sessions_ = 0; - Atom outOfSpaceCount_{0}; template void requestOp( @@ -440,6 +443,7 @@ class FlatCombining { std::unique_lock l(this->m_, std::defer_lock); if (l.try_lock()) { // No contention + ++uncombined_; tryCombining(); opFn(); return; @@ -456,6 +460,8 @@ class FlatCombining { if (rec == nullptr) { // Can't use FC - Must acquire lock l.lock(); + ++uncombined_; + tryCombining(); opFn(); return; } -- 2.34.1