From 93104c79eba817e04b6d2082b6cae33d7682725d Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 19 Nov 2012 13:53:43 -0800 Subject: [PATCH 1/2] Load and latency monitoring class. This will allow us to assess our load level. --- src/cpp/ripple/LoadMonitor.cpp | 66 +++++++++++++++++++++++++++++ src/cpp/ripple/LoadMonitor.h | 76 ++++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 src/cpp/ripple/LoadMonitor.cpp create mode 100644 src/cpp/ripple/LoadMonitor.h diff --git a/src/cpp/ripple/LoadMonitor.cpp b/src/cpp/ripple/LoadMonitor.cpp new file mode 100644 index 0000000000..76e23ccf43 --- /dev/null +++ b/src/cpp/ripple/LoadMonitor.cpp @@ -0,0 +1,66 @@ +#include "LoadMonitor.h" + +void LoadMonitor::LoadMonitor::update() +{ // call with the mutex + time_t now = time(NULL); + + if (now == mLastUpdate) // current + return; + + if ((now < mLastUpdate) || (now > (mLastUpdate + 8))) + { // way out of date + mCounts = 0; + mLatencyEvents = 0; + mLatencyMS = 0; + mLastUpdate = now; + return; + } + + do + { // do exponential decay + ++mLastUpdate; + mCounts -= (mCounts / 4); + mLatencyEvents -= (mLatencyEvents / 4); + mLatencyMS -= (mLatencyMS / 4); + } while (mLastUpdate < now); +} + +void LoadMonitor::addCount(int counts) +{ + boost::mutex::scoped_lock sl(mLock); + + update(); + mCounts += counts; +} + +void LoadMonitor::addLatency(int latency) +{ + boost::mutex::scoped_lock sl(mLock); + + update(); + ++mLatencyEvents; + mLatencyMS += latency; +} + +void LoadMonitor::addCountAndLatency(int counts, int latency) +{ + boost::mutex::scoped_lock sl(mLock); + + update(); + mCounts += counts; + ++mLatencyEvents; + mLatencyMS += latency; +} + +void LoadMonitor::getCountAndLatency(uint64& count, uint64& latency) +{ + boost::mutex::scoped_lock sl(mLock); + + update(); + + count = mCounts / 4; + + if (mLatencyEvents == 0) + latency = 0; + else latency = mLatencyMS / (mLatencyEvents * 4); +} diff --git a/src/cpp/ripple/LoadMonitor.h b/src/cpp/ripple/LoadMonitor.h new file mode 100644 index 0000000000..17d7cf8a52 --- /dev/null +++ b/src/cpp/ripple/LoadMonitor.h @@ -0,0 +1,76 @@ +#ifndef LOADMONITOR__H_ +#define LOADMONITOR__H_ + +#include + +#include + +#include "types.h" + +// Monitors load levels and response times + +class LoadMonitor +{ +protected: + std::string mName; + uint64 mCounts; + uint64 mLatencyEvents; + uint64 mLatencyMS; + time_t mLastUpdate; + boost::mutex mLock; + + void update(); + +public: + LoadMonitor(const std::string& n) : mName(n), mCounts(0), mLatencyEvents(0), mLatencyMS(0) + { mLastUpdate = time(NULL); } + + void setName(const std::string& n) { mName = n; } + + const std::string& getName() const { return mName; } + + void addCount(int counts); + void addLatency(int latency); + void addCountAndLatency(int counts, int latency); + + void getCountAndLatency(uint64& count, uint64& latency); +}; + +class LoadEvent +{ +protected: + LoadMonitor& mMonitor; + bool mRunning; + int mCount; + boost::posix_time::ptime mStartTime; + +public: + LoadEvent(LoadMonitor& monitor, bool shouldStart, int count) : mMonitor(monitor), mRunning(false), mCount(count) + { + mStartTime = boost::posix_time::microsec_clock::universal_time(); + if (shouldStart) + start(); + } + + ~LoadEvent() + { + if (mRunning) + stop(); + } + + void start() + { // okay to call if already started + mRunning = true; + mStartTime = boost::posix_time::microsec_clock::universal_time(); + } + + void stop() + { + assert(mRunning); + mRunning = false; + mMonitor.addCountAndLatency(mCount, + (boost::posix_time::microsec_clock::universal_time() - mStartTime).total_milliseconds()); + } +}; + +#endif From 54fe46fedab60606970ae34f8899d26cd600cef5 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 19 Nov 2012 14:19:01 -0800 Subject: [PATCH 2/2] Fix STPath breakage. --- src/cpp/ripple/SerializedTypes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp/ripple/SerializedTypes.cpp b/src/cpp/ripple/SerializedTypes.cpp index 61f526eeb0..b9daae2fe5 100644 --- a/src/cpp/ripple/SerializedTypes.cpp +++ b/src/cpp/ripple/SerializedTypes.cpp @@ -395,7 +395,7 @@ STPathSet* STPathSet::construct(SerializerIterator& s, SField::ref name) if (bIssuer) uIssuerID = s.get160(); - path.push_back(STPathElement(uAccountID, uCurrency, uIssuerID)); + path.push_back(STPathElement(uAccountID, uCurrency, uIssuerID, bCurrency)); } } while(1); }