Commit b5737d0b authored by Maged Michael's avatar Maged Michael Committed by Facebook Github Bot

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
parent b85ce097
...@@ -84,7 +84,7 @@ namespace folly { ...@@ -84,7 +84,7 @@ namespace folly {
/// class ConcurrentFoo : public FlatCombining<ConcurrentFoo> { /// class ConcurrentFoo : public FlatCombining<ConcurrentFoo> {
/// Foo foo_; // sequential data structure /// Foo foo_; // sequential data structure
/// public: /// 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; /// T result;
/// // Note: fn must be copyable to folly::Function without dynamic /// // Note: fn must be copyable to folly::Function without dynamic
/// // allocation. Otherwise, it is recommended to use the custom /// // allocation. Otherwise, it is recommended to use the custom
...@@ -369,7 +369,6 @@ class FlatCombining { ...@@ -369,7 +369,6 @@ class FlatCombining {
Rec* allocRec() { Rec* allocRec() {
auto idx = recsPool_.allocIndex(); auto idx = recsPool_.allocIndex();
if (idx == NULL_INDEX) { if (idx == NULL_INDEX) {
outOfSpaceCount_.fetch_add(1);
return nullptr; return nullptr;
} }
Rec& rec = recsPool_[idx]; Rec& rec = recsPool_[idx];
...@@ -386,20 +385,24 @@ class FlatCombining { ...@@ -386,20 +385,24 @@ class FlatCombining {
recsPool_.recycleIndex(idx); recsPool_.recycleIndex(idx);
} }
// Returns a count of the number of combined operations so far. // Returns the number of uncombined operations so far.
uint64_t getCombinedOpCount() { uint64_t getNumUncombined() const {
std::lock_guard<Mutex> guard(m_); return uncombined_;
}
// Returns the number of combined operations so far.
uint64_t getNumCombined() const {
return combined_; return combined_;
} }
// Returns a count of the number of combining passes so far. // Returns the number of combining passes so far.
uint64_t getCombiningPasses() { uint64_t getNumPasses() const {
std::lock_guard<Mutex> guard(m_);
return passes_; return passes_;
} }
uint64_t getOutOfSpaceCount() { // Returns the number of combining sessions so far.
return outOfSpaceCount_.load(); uint64_t getNumSessions() const {
return sessions_;
} }
protected: protected:
...@@ -424,10 +427,10 @@ class FlatCombining { ...@@ -424,10 +427,10 @@ class FlatCombining {
Pool recsPool_; Pool recsPool_;
FOLLY_ALIGN_TO_AVOID_FALSE_SHARING FOLLY_ALIGN_TO_AVOID_FALSE_SHARING
uint64_t uncombined_ = 0;
uint64_t combined_ = 0; uint64_t combined_ = 0;
uint64_t passes_ = 0; uint64_t passes_ = 0;
uint64_t sessions_ = 0; uint64_t sessions_ = 0;
Atom<uint64_t> outOfSpaceCount_{0};
template <typename OpFunc, typename FillFunc, typename ResFn> template <typename OpFunc, typename FillFunc, typename ResFn>
void requestOp( void requestOp(
...@@ -440,6 +443,7 @@ class FlatCombining { ...@@ -440,6 +443,7 @@ class FlatCombining {
std::unique_lock<Mutex> l(this->m_, std::defer_lock); std::unique_lock<Mutex> l(this->m_, std::defer_lock);
if (l.try_lock()) { if (l.try_lock()) {
// No contention // No contention
++uncombined_;
tryCombining(); tryCombining();
opFn(); opFn();
return; return;
...@@ -456,6 +460,8 @@ class FlatCombining { ...@@ -456,6 +460,8 @@ class FlatCombining {
if (rec == nullptr) { if (rec == nullptr) {
// Can't use FC - Must acquire lock // Can't use FC - Must acquire lock
l.lock(); l.lock();
++uncombined_;
tryCombining();
opFn(); opFn();
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment