mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-21 11:35:53 +00:00
Merge branch 'master' of github.com:jedmccaleb/NewCoin
This commit is contained in:
66
src/cpp/ripple/LoadMonitor.cpp
Normal file
66
src/cpp/ripple/LoadMonitor.cpp
Normal file
@@ -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);
|
||||||
|
}
|
||||||
76
src/cpp/ripple/LoadMonitor.h
Normal file
76
src/cpp/ripple/LoadMonitor.h
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
#ifndef LOADMONITOR__H_
|
||||||
|
#define LOADMONITOR__H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <boost/thread/mutex.hpp>
|
||||||
|
|
||||||
|
#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
|
||||||
@@ -395,7 +395,7 @@ STPathSet* STPathSet::construct(SerializerIterator& s, SField::ref name)
|
|||||||
if (bIssuer)
|
if (bIssuer)
|
||||||
uIssuerID = s.get160();
|
uIssuerID = s.get160();
|
||||||
|
|
||||||
path.push_back(STPathElement(uAccountID, uCurrency, uIssuerID));
|
path.push_back(STPathElement(uAccountID, uCurrency, uIssuerID, bCurrency));
|
||||||
}
|
}
|
||||||
} while(1);
|
} while(1);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user