mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-28 06:55:50 +00:00
Move LoadMonitor definitions to the .cpp
This commit is contained in:
@@ -2,25 +2,47 @@
|
||||
|
||||
SETUP_LOG (LoadMonitor)
|
||||
|
||||
void LoadMonitor::update()
|
||||
{ // call with the mutex
|
||||
LoadMonitor::LoadMonitor ()
|
||||
: mCounts (0)
|
||||
, mLatencyEvents (0)
|
||||
, mLatencyMSAvg (0)
|
||||
, mLatencyMSPeak (0)
|
||||
, mTargetLatencyAvg (0)
|
||||
, mTargetLatencyPk (0)
|
||||
, mLastUpdate (UptimeTimer::getInstance().getElapsedSeconds ())
|
||||
{
|
||||
}
|
||||
|
||||
// VFALCO: NOTE WHY do we need "the mutex?" This dependence on
|
||||
// a hidden global, especially a synchronization primitive,
|
||||
// is a flawed design.
|
||||
// It's not clear exactly which data needs to be protected.
|
||||
//
|
||||
// call with the mutex
|
||||
void LoadMonitor::update ()
|
||||
{
|
||||
int now = UptimeTimer::getInstance().getElapsedSeconds ();
|
||||
|
||||
// VFALCO: TODO stop returning from the middle of functions.
|
||||
|
||||
if (now == mLastUpdate) // current
|
||||
return;
|
||||
|
||||
if ((now < mLastUpdate) || (now > (mLastUpdate + 8)))
|
||||
{ // way out of date
|
||||
{
|
||||
// way out of date
|
||||
mCounts = 0;
|
||||
mLatencyEvents = 0;
|
||||
mLatencyMSAvg = 0;
|
||||
mLatencyMSPeak = 0;
|
||||
mLastUpdate = now;
|
||||
// VFALCO: TODO, don't return from the middle...
|
||||
return;
|
||||
}
|
||||
|
||||
// do exponential decay
|
||||
do
|
||||
{ // do exponential decay
|
||||
{
|
||||
++mLastUpdate;
|
||||
mCounts -= ((mCounts + 3) / 4);
|
||||
mLatencyEvents -= ((mLatencyEvents + 3) / 4);
|
||||
@@ -29,7 +51,7 @@ void LoadMonitor::update()
|
||||
} while (mLastUpdate < now);
|
||||
}
|
||||
|
||||
void LoadMonitor::addCount()
|
||||
void LoadMonitor::addCount ()
|
||||
{
|
||||
boost::mutex::scoped_lock sl(mLock);
|
||||
|
||||
@@ -37,7 +59,7 @@ void LoadMonitor::addCount()
|
||||
++mCounts;
|
||||
}
|
||||
|
||||
void LoadMonitor::addLatency(int latency)
|
||||
void LoadMonitor::addLatency (int latency)
|
||||
{
|
||||
if (latency == 1)
|
||||
latency = 0;
|
||||
@@ -54,7 +76,7 @@ void LoadMonitor::addLatency(int latency)
|
||||
mLatencyMSPeak = lp;
|
||||
}
|
||||
|
||||
void LoadMonitor::addCountAndLatency(const std::string& name, int latency)
|
||||
void LoadMonitor::addCountAndLatency (const std::string& name, int latency)
|
||||
{
|
||||
if (latency > 500)
|
||||
{
|
||||
@@ -76,7 +98,19 @@ void LoadMonitor::addCountAndLatency(const std::string& name, int latency)
|
||||
mLatencyMSPeak = lp;
|
||||
}
|
||||
|
||||
bool LoadMonitor::isOver()
|
||||
void LoadMonitor::setTargetLatency (uint64 avg, uint64 pk)
|
||||
{
|
||||
mTargetLatencyAvg = avg;
|
||||
mTargetLatencyPk = pk;
|
||||
}
|
||||
|
||||
bool LoadMonitor::isOverTarget (uint64 avg, uint64 peak)
|
||||
{
|
||||
return (mTargetLatencyPk && (peak > mTargetLatencyPk)) ||
|
||||
(mTargetLatencyAvg && (avg > mTargetLatencyAvg));
|
||||
}
|
||||
|
||||
bool LoadMonitor::isOver ()
|
||||
{
|
||||
boost::mutex::scoped_lock sl(mLock);
|
||||
|
||||
@@ -88,7 +122,7 @@ bool LoadMonitor::isOver()
|
||||
return isOverTarget(mLatencyMSAvg / (mLatencyEvents * 4), mLatencyMSPeak / (mLatencyEvents * 4));
|
||||
}
|
||||
|
||||
void LoadMonitor::getCountAndLatency(uint64& count, uint64& latencyAvg, uint64& latencyPeak, bool& isOver)
|
||||
void LoadMonitor::getCountAndLatency (uint64& count, uint64& latencyAvg, uint64& latencyPeak, bool& isOver)
|
||||
{
|
||||
boost::mutex::scoped_lock sl(mLock);
|
||||
|
||||
@@ -106,7 +140,8 @@ void LoadMonitor::getCountAndLatency(uint64& count, uint64& latencyAvg, uint64&
|
||||
latencyAvg = mLatencyMSAvg / (mLatencyEvents * 4);
|
||||
latencyPeak = mLatencyMSPeak / (mLatencyEvents * 4);
|
||||
}
|
||||
isOver = isOverTarget(latencyAvg, latencyPeak);
|
||||
|
||||
isOver = isOverTarget(latencyAvg, latencyPeak);
|
||||
}
|
||||
|
||||
// vim:ts=4
|
||||
|
||||
@@ -12,39 +12,27 @@
|
||||
class LoadMonitor
|
||||
{
|
||||
public:
|
||||
LoadMonitor()
|
||||
: mCounts(0)
|
||||
, mLatencyEvents(0)
|
||||
, mLatencyMSAvg(0)
|
||||
, mLatencyMSPeak(0)
|
||||
, mTargetLatencyAvg(0)
|
||||
, mTargetLatencyPk(0)
|
||||
{
|
||||
mLastUpdate = UptimeTimer::getInstance().getElapsedSeconds ();
|
||||
}
|
||||
LoadMonitor ();
|
||||
|
||||
void addCount();
|
||||
void addLatency(int latency);
|
||||
void addCountAndLatency(const std::string& name, int latency);
|
||||
void addCount ();
|
||||
|
||||
void addLatency (int latency);
|
||||
|
||||
void setTargetLatency(uint64 avg, uint64 pk)
|
||||
{
|
||||
mTargetLatencyAvg = avg;
|
||||
mTargetLatencyPk = pk;
|
||||
}
|
||||
void addCountAndLatency (const std::string& name, int latency);
|
||||
|
||||
bool isOverTarget(uint64 avg, uint64 peak)
|
||||
{
|
||||
return (mTargetLatencyPk && (peak > mTargetLatencyPk)) ||
|
||||
(mTargetLatencyAvg && (avg > mTargetLatencyAvg));
|
||||
}
|
||||
void setTargetLatency (uint64 avg, uint64 pk);
|
||||
|
||||
void getCountAndLatency(uint64& count, uint64& latencyAvg, uint64& latencyPeak, bool& isOver);
|
||||
bool isOver();
|
||||
bool isOverTarget(uint64 avg, uint64 peak);
|
||||
|
||||
// VFALCO: TODO, make this return the values in a struct.
|
||||
void getCountAndLatency (uint64& count, uint64& latencyAvg, uint64& latencyPeak, bool& isOver);
|
||||
|
||||
bool isOver ();
|
||||
|
||||
private:
|
||||
void update();
|
||||
void update ();
|
||||
|
||||
boost::mutex mLock;
|
||||
uint64 mCounts;
|
||||
uint64 mLatencyEvents;
|
||||
uint64 mLatencyMSAvg;
|
||||
@@ -52,7 +40,6 @@ private:
|
||||
uint64 mTargetLatencyAvg;
|
||||
uint64 mTargetLatencyPk;
|
||||
int mLastUpdate;
|
||||
boost::mutex mLock;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user