From 5aa810404b2df974acfc027bfe6e4db419629ee9 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 5 Feb 2013 21:33:42 -0800 Subject: [PATCH 1/5] Track uptime. Update local fee schedule based on load manager. --- src/cpp/ripple/Application.cpp | 1 + src/cpp/ripple/JobQueue.cpp | 10 +++++ src/cpp/ripple/JobQueue.h | 1 + src/cpp/ripple/LoadManager.cpp | 68 +++++++++++++++++++++++++++++++++- src/cpp/ripple/LoadManager.h | 8 ++++ src/cpp/ripple/LoadMonitor.cpp | 14 +++++++ src/cpp/ripple/LoadMonitor.h | 5 ++- src/cpp/ripple/RPCHandler.cpp | 24 ++++++++++++ 8 files changed, 128 insertions(+), 3 deletions(-) diff --git a/src/cpp/ripple/Application.cpp b/src/cpp/ripple/Application.cpp index 2f5d9f68a1..072ceb0b71 100644 --- a/src/cpp/ripple/Application.cpp +++ b/src/cpp/ripple/Application.cpp @@ -52,6 +52,7 @@ Application::Application() : mJobQueue.setThreadCount(); mSweepTimer.expires_from_now(boost::posix_time::seconds(10)); mSweepTimer.async_wait(boost::bind(&Application::sweep, this)); + mLoadMgr.init(); } extern const char *RpcDBInit[], *TxnDBInit[], *LedgerDBInit[], *WalletDBInit[], *HashNodeDBInit[], *NetNodeDBInit[]; diff --git a/src/cpp/ripple/JobQueue.cpp b/src/cpp/ripple/JobQueue.cpp index 5d0106f381..3a795fd141 100644 --- a/src/cpp/ripple/JobQueue.cpp +++ b/src/cpp/ripple/JobQueue.cpp @@ -181,6 +181,16 @@ Json::Value JobQueue::getJson(int) return ret; } +int JobQueue::isOverloaded() +{ + int count = 0; + boost::mutex::scoped_lock sl(mJobLock); + for (int i = 0; i < NUM_JOB_TYPES; ++i) + if (mJobLoads[i].isOver()) + ++count; + return count; +} + void JobQueue::shutdown() { // shut down the job queue without completing pending jobs cLog(lsINFO) << "Job queue shutting down"; diff --git a/src/cpp/ripple/JobQueue.h b/src/cpp/ripple/JobQueue.h index 1df31aca7e..22bfefad95 100644 --- a/src/cpp/ripple/JobQueue.h +++ b/src/cpp/ripple/JobQueue.h @@ -108,6 +108,7 @@ public: LoadEvent::autoptr getLoadEventAP(JobType t) { return LoadEvent::autoptr(new LoadEvent(mJobLoads[t], true, 1)); } + int isOverloaded(); Json::Value getJson(int c = 0); }; diff --git a/src/cpp/ripple/LoadManager.cpp b/src/cpp/ripple/LoadManager.cpp index daacb52153..f8454c663d 100644 --- a/src/cpp/ripple/LoadManager.cpp +++ b/src/cpp/ripple/LoadManager.cpp @@ -1,15 +1,18 @@ #include "LoadManager.h" #include +#include +#include #include "Log.h" #include "Config.h" +#include "Application.h" SETUP_LOG(); LoadManager::LoadManager(int creditRate, int creditLimit, int debitWarn, int debitLimit) : mCreditRate(creditRate), mCreditLimit(creditLimit), mDebitWarn(debitWarn), mDebitLimit(debitLimit), - mCosts(LT_MAX) + mShutdown(false), mUptime(0), mCosts(LT_MAX) { addLoadCost(LoadCost(LT_InvalidRequest, 10, LC_CPU | LC_Network)); addLoadCost(LoadCost(LT_RequestNoReply, 1, LC_CPU | LC_Disk)); @@ -25,6 +28,30 @@ LoadManager::LoadManager(int creditRate, int creditLimit, int debitWarn, int deb addLoadCost(LoadCost(LT_CheapQuery, 1, LC_CPU)); } +void LoadManager::init() +{ + boost::thread(boost::bind(&LoadManager::threadEntry, this)).detach(); +} + +LoadManager::~LoadManager() +{ + { + boost::mutex::scoped_lock sl(mLock); + mShutdown = true; + } + + do + { + boost::this_thread::sleep(boost::posix_time::milliseconds(100)); + { + boost::mutex::scoped_lock sl(mLock); + if (!mShutdown) + return; + } + } + while (1); +} + int LoadManager::getCreditRate() const { @@ -239,6 +266,45 @@ Json::Value LoadFeeTrack::getJson(uint64 baseFee, uint32 referenceFeeUnits) return j; } +int LoadManager::getUptime() +{ + boost::mutex::scoped_lock sl(mLock); + return mUptime; +} + +void LoadManager::threadEntry() +{ + boost::posix_time::ptime t = boost::posix_time::microsec_clock::universal_time(); + while (1) + { + { + boost::mutex::scoped_lock sl(mLock); + if (mShutdown) + { + mShutdown = false; + return; + } + ++mUptime; + } + + if (theApp->getJobQueue().isOverloaded()) + theApp->getFeeTrack().raiseLocalFee(); + else + theApp->getFeeTrack().lowerLocalFee(); + + t += boost::posix_time::seconds(1); + boost::posix_time::time_duration when = t - boost::posix_time::microsec_clock::universal_time(); + + if (when.is_negative()) + { + cLog(lsWARNING) << "Backwards time jump"; + t = boost::posix_time::microsec_clock::universal_time(); + } + else + boost::this_thread::sleep(when); + } +} + BOOST_AUTO_TEST_SUITE(LoadManager_test) BOOST_AUTO_TEST_CASE(LoadFeeTrack_test) diff --git a/src/cpp/ripple/LoadManager.h b/src/cpp/ripple/LoadManager.h index 0cecd6c1e1..071d0f1436 100644 --- a/src/cpp/ripple/LoadManager.h +++ b/src/cpp/ripple/LoadManager.h @@ -86,6 +86,9 @@ protected: int mDebitWarn; // when a source drops below this, we warn int mDebitLimit; // when a source drops below this, we cut it off (should be negative) + bool mShutdown; + int mUptime; + mutable boost::mutex mLock; void canonicalize(LoadSource&, const time_t now) const; @@ -94,9 +97,13 @@ protected: void addLoadCost(const LoadCost& c) { mCosts[static_cast(c.mType)] = c; } + void threadEntry(); + public: LoadManager(int creditRate = 10, int creditLimit = 50, int debitWarn = -50, int debitLimit = -100); + ~LoadManager(); + void init(); int getCreditRate() const; int getCreditLimit() const; @@ -113,6 +120,7 @@ public: bool adjust(LoadSource&, LoadType l) const; int getCost(LoadType t) { return mCosts[static_cast(t)].mCost; } + int getUptime(); }; class LoadFeeTrack diff --git a/src/cpp/ripple/LoadMonitor.cpp b/src/cpp/ripple/LoadMonitor.cpp index b014c330ec..312de87a72 100644 --- a/src/cpp/ripple/LoadMonitor.cpp +++ b/src/cpp/ripple/LoadMonitor.cpp @@ -69,6 +69,18 @@ void LoadMonitor::addCountAndLatency(int counts, int latency) mLatencyMSPeak = lp; } +bool LoadMonitor::isOver() +{ + boost::mutex::scoped_lock sl(mLock); + + update(); + + if (mLatencyEvents == 0) + return 0; + + return isOverTarget(mLatencyMSAvg / (mLatencyEvents * 4), mLatencyMSPeak / (mLatencyEvents * 4)); +} + void LoadMonitor::getCountAndLatency(uint64& count, uint64& latencyAvg, uint64& latencyPeak, bool& isOver) { boost::mutex::scoped_lock sl(mLock); @@ -89,3 +101,5 @@ void LoadMonitor::getCountAndLatency(uint64& count, uint64& latencyAvg, uint64& } isOver = isOverTarget(latencyAvg, latencyPeak); } + +// vim:ts=4 diff --git a/src/cpp/ripple/LoadMonitor.h b/src/cpp/ripple/LoadMonitor.h index ba210b75c3..efda49b53b 100644 --- a/src/cpp/ripple/LoadMonitor.h +++ b/src/cpp/ripple/LoadMonitor.h @@ -35,8 +35,8 @@ public: void setTargetLatency(uint64 avg, uint64 pk) { - mTargetLatencyAvg = avg * 4; - mTargetLatencyPk = pk * 4; + mTargetLatencyAvg = avg; + mTargetLatencyPk = pk; } bool isOverTarget(uint64 avg, uint64 peak) @@ -46,6 +46,7 @@ public: } void getCountAndLatency(uint64& count, uint64& latencyAvg, uint64& latencyPeak, bool& isOver); + bool isOver(); }; class LoadEvent diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index 8fa825b86a..7def72ca93 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -1786,6 +1786,21 @@ Json::Value RPCHandler::doLogin(Json::Value jvRequest) } #endif +static void textTime(std::string& text, int& seconds, const char *unitName, int unitVal) +{ + int i = seconds / unitVal; + if (i == 0) + return; + seconds -= unitVal * i; + if (!text.empty()) + text += ", "; + text += boost::lexical_cast(i); + text += " "; + text += unitName; + if (i > 1) + text += "s"; +} + // { // min_count: // optional, defaults to 10 // } @@ -1807,6 +1822,15 @@ Json::Value RPCHandler::doGetCounts(Json::Value jvRequest) if (dbKB > 0) ret["dbKB"] = dbKB; + std::string uptime; + int s = theApp->getLoadManager().getUptime(); + textTime(uptime, s, "year", 365*24*60*60); + textTime(uptime, s, "day", 24*60*60); + textTime(uptime, s, "hour", 24*60); + textTime(uptime, s, "minute", 60); + textTime(uptime, s, "second", 1); + ret["uptime"] = uptime; + return ret; } From fadceb072dca1581435e8fcc3f616be8e5609e85 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 5 Feb 2013 21:55:18 -0800 Subject: [PATCH 2/5] Get the time jump logic right. --- src/cpp/ripple/LoadManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cpp/ripple/LoadManager.cpp b/src/cpp/ripple/LoadManager.cpp index f8454c663d..485202b8fa 100644 --- a/src/cpp/ripple/LoadManager.cpp +++ b/src/cpp/ripple/LoadManager.cpp @@ -295,9 +295,9 @@ void LoadManager::threadEntry() t += boost::posix_time::seconds(1); boost::posix_time::time_duration when = t - boost::posix_time::microsec_clock::universal_time(); - if (when.is_negative()) + if ((when.is_negative()) || (when.total_seconds() > 1)) { - cLog(lsWARNING) << "Backwards time jump"; + cLog(lsWARNING) << "time jump"; t = boost::posix_time::microsec_clock::universal_time(); } else From 8c36646b8cbd1f6e44fcb011796f69a9c60fa255 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 5 Feb 2013 22:06:30 -0800 Subject: [PATCH 3/5] Make a fast, monotonic timer. --- src/cpp/ripple/LoadManager.cpp | 16 ++++++++++++++++ src/cpp/ripple/LoadManager.h | 2 ++ src/cpp/ripple/RPCHandler.cpp | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/cpp/ripple/LoadManager.cpp b/src/cpp/ripple/LoadManager.cpp index 485202b8fa..013c7f2af6 100644 --- a/src/cpp/ripple/LoadManager.cpp +++ b/src/cpp/ripple/LoadManager.cpp @@ -10,6 +10,17 @@ SETUP_LOG(); +static volatile int* uptimePtr = NULL; + +int upTime() +{ + static time_t firstCall = time(NULL); + if (uptimePtr != NULL) + return *uptimePtr; + cLog(lsWARNING) << "slow uptime"; + return static_cast(time(NULL) - firstCall); +} + LoadManager::LoadManager(int creditRate, int creditLimit, int debitWarn, int debitLimit) : mCreditRate(creditRate), mCreditLimit(creditLimit), mDebitWarn(debitWarn), mDebitLimit(debitLimit), mShutdown(false), mUptime(0), mCosts(LT_MAX) @@ -26,15 +37,20 @@ LoadManager::LoadManager(int creditRate, int creditLimit, int debitWarn, int deb addLoadCost(LoadCost(LT_RequestData, 5, LC_Disk | LC_Network)); addLoadCost(LoadCost(LT_CheapQuery, 1, LC_CPU)); + } void LoadManager::init() { + if (uptimePtr == NULL) + uptimePtr = static_cast(&mUptime); boost::thread(boost::bind(&LoadManager::threadEntry, this)).detach(); } LoadManager::~LoadManager() { + if (uptimePtr == &mUptime) + uptimePtr = NULL; { boost::mutex::scoped_lock sl(mLock); mShutdown = true; diff --git a/src/cpp/ripple/LoadManager.h b/src/cpp/ripple/LoadManager.h index 071d0f1436..dea9c6c0b4 100644 --- a/src/cpp/ripple/LoadManager.h +++ b/src/cpp/ripple/LoadManager.h @@ -9,6 +9,8 @@ #include "types.h" +extern int upTime(); + enum LoadType { // types of load that can be placed on the server diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index 7def72ca93..064b49860f 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -1823,7 +1823,7 @@ Json::Value RPCHandler::doGetCounts(Json::Value jvRequest) ret["dbKB"] = dbKB; std::string uptime; - int s = theApp->getLoadManager().getUptime(); + int s = upTime(); textTime(uptime, s, "year", 365*24*60*60); textTime(uptime, s, "day", 24*60*60); textTime(uptime, s, "hour", 24*60); From 180845498384455b1c57196f29eae0afe9a9f8db Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 5 Feb 2013 22:31:26 -0800 Subject: [PATCH 4/5] Use the new uptime code. Replace slow, non-monotonic 'time(NULL)' calls with fast, almost-always-monotonic 'upTime()' calls. --- src/cpp/ripple/KeyCache.h | 14 ++++++++------ src/cpp/ripple/LedgerAcquire.cpp | 4 ++-- src/cpp/ripple/LedgerAcquire.h | 6 +++--- src/cpp/ripple/LoadManager.cpp | 10 +++++----- src/cpp/ripple/LoadManager.h | 11 +++++++---- src/cpp/ripple/LoadMonitor.cpp | 2 +- src/cpp/ripple/LoadMonitor.h | 5 +++-- src/cpp/ripple/Suppression.cpp | 8 +++++--- src/cpp/ripple/Suppression.h | 2 +- src/cpp/ripple/TaggedCache.h | 17 +++++++++-------- 10 files changed, 44 insertions(+), 35 deletions(-) diff --git a/src/cpp/ripple/KeyCache.h b/src/cpp/ripple/KeyCache.h index 63bc2e80c6..13387fb6d2 100644 --- a/src/cpp/ripple/KeyCache.h +++ b/src/cpp/ripple/KeyCache.h @@ -6,11 +6,13 @@ #include #include +extern int upTime(); + template class KeyCache { // Maintains a cache of keys with no associated data public: typedef c_Key key_type; - typedef boost::unordered_map map_type; + typedef boost::unordered_map map_type; typedef typename map_type::iterator map_iterator; protected: @@ -65,7 +67,7 @@ public: if (it == mCache.end()) return false; if (refresh) - it->second = time(NULL); + it->second = upTime(); return true; } @@ -88,19 +90,19 @@ public: map_iterator it = mCache.find(key); if (it != mCache.end()) { - it->second = time(NULL); + it->second = upTime(); return false; } - mCache.insert(std::make_pair(key, time(NULL))); + mCache.insert(std::make_pair(key, upTime())); return true; } void sweep() { // Remove stale entries from the cache - time_t now = time(NULL); + int now = upTime(); boost::mutex::scoped_lock sl(mNCLock); - time_t target; + int target; if ((mTargetSize == 0) || (mCache.size() <= mTargetSize)) target = now - mTargetAge; else diff --git a/src/cpp/ripple/LedgerAcquire.cpp b/src/cpp/ripple/LedgerAcquire.cpp index 75a2e42436..f24c6fe463 100644 --- a/src/cpp/ripple/LedgerAcquire.cpp +++ b/src/cpp/ripple/LedgerAcquire.cpp @@ -22,7 +22,7 @@ DECLARE_INSTANCE(LedgerAcquire); PeerSet::PeerSet(const uint256& hash, int interval) : mHash(hash), mTimerInterval(interval), mTimeouts(0), mComplete(false), mFailed(false), mProgress(true), mAggressive(true), mTimer(theApp->getIOService()) { - mLastAction = time(NULL); + mLastAction = upTime(); assert((mTimerInterval > 10) && (mTimerInterval < 30000)); } @@ -890,7 +890,7 @@ void LedgerAcquireMaster::sweep() { mRecentFailures.sweep(); - time_t now = time(NULL); + int now = upTime(); boost::mutex::scoped_lock sl(mLock); std::map::iterator it = mLedgers.begin(); diff --git a/src/cpp/ripple/LedgerAcquire.h b/src/cpp/ripple/LedgerAcquire.h index 0f2c6abd26..b6d60f0f37 100644 --- a/src/cpp/ripple/LedgerAcquire.h +++ b/src/cpp/ripple/LedgerAcquire.h @@ -32,7 +32,7 @@ protected: uint256 mHash; int mTimerInterval, mTimeouts; bool mComplete, mFailed, mProgress, mAggressive; - time_t mLastAction; + int mLastAction; boost::recursive_mutex mLock; boost::asio::deadline_timer mTimer; @@ -53,8 +53,8 @@ public: bool isActive(); void progress() { mProgress = true; mAggressive = false; } bool isProgress() { return mProgress; } - void touch() { mLastAction = time(NULL); } - time_t getLastAction() { return mLastAction; } + void touch() { mLastAction = upTime(); } + int getLastAction() { return mLastAction; } void peerHas(Peer::ref); void badPeer(Peer::ref); diff --git a/src/cpp/ripple/LoadManager.cpp b/src/cpp/ripple/LoadManager.cpp index 013c7f2af6..79e7eb952e 100644 --- a/src/cpp/ripple/LoadManager.cpp +++ b/src/cpp/ripple/LoadManager.cpp @@ -17,7 +17,7 @@ int upTime() static time_t firstCall = time(NULL); if (uptimePtr != NULL) return *uptimePtr; - cLog(lsWARNING) << "slow uptime"; + cLog(lsTRACE) << "Slow uptime in use"; return static_cast(time(NULL) - firstCall); } @@ -117,7 +117,7 @@ void LoadManager::setDebitLimit(int r) mDebitLimit = r; } -void LoadManager::canonicalize(LoadSource& source, const time_t now) const +void LoadManager::canonicalize(LoadSource& source, int now) const { if (source.mLastUpdate != now) { @@ -133,9 +133,9 @@ void LoadManager::canonicalize(LoadSource& source, const time_t now) const bool LoadManager::shouldWarn(LoadSource& source) const { - time_t now = time(NULL); boost::mutex::scoped_lock sl(mLock); + int now = upTime(); canonicalize(source, now); if (source.isPrivileged() || (source.mBalance < mDebitWarn) || (source.mLastWarning == now)) return false; @@ -146,9 +146,9 @@ bool LoadManager::shouldWarn(LoadSource& source) const bool LoadManager::shouldCutoff(LoadSource& source) const { - time_t now = time(NULL); boost::mutex::scoped_lock sl(mLock); + int now = upTime(); canonicalize(source, now); return !source.isPrivileged() && (source.mBalance < mDebitLimit); } @@ -161,10 +161,10 @@ bool LoadManager::adjust(LoadSource& source, LoadType t) const bool LoadManager::adjust(LoadSource& source, int credits) const { // return: true = need to warn/cutoff - time_t now = time(NULL); boost::mutex::scoped_lock sl(mLock); // We do it this way in case we want to add exponential decay later + int now = upTime(); canonicalize(source, now); source.mBalance += credits; if (source.mBalance > mCreditLimit) diff --git a/src/cpp/ripple/LoadManager.h b/src/cpp/ripple/LoadManager.h index dea9c6c0b4..b64394298f 100644 --- a/src/cpp/ripple/LoadManager.h +++ b/src/cpp/ripple/LoadManager.h @@ -63,12 +63,12 @@ public: protected: int mBalance; int mFlags; - time_t mLastUpdate; - time_t mLastWarning; + int mLastUpdate; + int mLastWarning; public: LoadSource() : mBalance(0), mFlags(0), mLastWarning(0) - { mLastUpdate = time(NULL); } + { mLastUpdate = upTime(); } bool isPrivileged() const { return (mFlags & lsfPrivileged) != 0; } void setPrivileged() { mFlags |= lsfPrivileged; } @@ -89,11 +89,14 @@ protected: int mDebitLimit; // when a source drops below this, we cut it off (should be negative) bool mShutdown; + + int mSpace1[4]; // We want mUptime to have its own cache line int mUptime; + int mSpace2[4]; mutable boost::mutex mLock; - void canonicalize(LoadSource&, const time_t now) const; + void canonicalize(LoadSource&, int upTime) const; std::vector mCosts; diff --git a/src/cpp/ripple/LoadMonitor.cpp b/src/cpp/ripple/LoadMonitor.cpp index 312de87a72..567d08c948 100644 --- a/src/cpp/ripple/LoadMonitor.cpp +++ b/src/cpp/ripple/LoadMonitor.cpp @@ -2,7 +2,7 @@ void LoadMonitor::update() { // call with the mutex - time_t now = time(NULL); + int now = upTime(); if (now == mLastUpdate) // current return; diff --git a/src/cpp/ripple/LoadMonitor.h b/src/cpp/ripple/LoadMonitor.h index efda49b53b..18cbb228dd 100644 --- a/src/cpp/ripple/LoadMonitor.h +++ b/src/cpp/ripple/LoadMonitor.h @@ -7,6 +7,7 @@ #include #include "types.h" +extern int upTime(); // Monitors load levels and response times @@ -19,7 +20,7 @@ protected: uint64 mLatencyMSPeak; uint64 mTargetLatencyAvg; uint64 mTargetLatencyPk; - time_t mLastUpdate; + int mLastUpdate; boost::mutex mLock; void update(); @@ -27,7 +28,7 @@ protected: public: LoadMonitor() : mCounts(0), mLatencyEvents(0), mLatencyMSAvg(0), mLatencyMSPeak(0), mTargetLatencyAvg(0), mTargetLatencyPk(0) - { mLastUpdate = time(NULL); } + { mLastUpdate = upTime(); } void addCount(int counts); void addLatency(int latency); diff --git a/src/cpp/ripple/Suppression.cpp b/src/cpp/ripple/Suppression.cpp index 1bd594d40b..b168b9120f 100644 --- a/src/cpp/ripple/Suppression.cpp +++ b/src/cpp/ripple/Suppression.cpp @@ -4,6 +4,8 @@ DECLARE_INSTANCE(Suppression); +extern int upTime(); + Suppression& SuppressionTable::findCreateEntry(const uint256& index, bool& created) { boost::unordered_map::iterator fit = mSuppressionMap.find(index); @@ -15,11 +17,11 @@ Suppression& SuppressionTable::findCreateEntry(const uint256& index, bool& creat } created = true; - time_t now = time(NULL); - time_t expireTime = now - mHoldTime; + int now = upTime(); + int expireTime = now - mHoldTime; // See if any supressions need to be expired - std::map< time_t, std::list >::iterator it = mSuppressionTimes.begin(); + std::map< int, std::list >::iterator it = mSuppressionTimes.begin(); if ((it != mSuppressionTimes.end()) && (it->first <= expireTime)) { BOOST_FOREACH(const uint256& lit, it->second) diff --git a/src/cpp/ripple/Suppression.h b/src/cpp/ripple/Suppression.h index 4cd9db074f..d401a8f412 100644 --- a/src/cpp/ripple/Suppression.h +++ b/src/cpp/ripple/Suppression.h @@ -50,7 +50,7 @@ protected: boost::unordered_map mSuppressionMap; // Stores all expiration times and the hashes indexed for them - std::map< time_t, std::list > mSuppressionTimes; + std::map< int, std::list > mSuppressionTimes; int mHoldTime; diff --git a/src/cpp/ripple/TaggedCache.h b/src/cpp/ripple/TaggedCache.h index f8cb5d4992..ad6bea2d74 100644 --- a/src/cpp/ripple/TaggedCache.h +++ b/src/cpp/ripple/TaggedCache.h @@ -11,6 +11,7 @@ #include "Log.h" extern LogPartition TaggedCachePartition; +extern int upTime(); // This class implements a cache and a map. The cache keeps objects alive // in the map. The map allows multiple code paths that reference objects @@ -36,15 +37,15 @@ protected: class cache_entry { public: - time_t last_use; + int last_use; data_ptr ptr; weak_data_ptr weak_ptr; - cache_entry(time_t l, const data_ptr& d) : last_use(l), ptr(d), weak_ptr(d) { ; } + cache_entry(int l, const data_ptr& d) : last_use(l), ptr(d), weak_ptr(d) { ; } bool isCached() { return !!ptr; } bool isExpired() { return weak_ptr.expired(); } data_ptr lock() { return weak_ptr.lock(); } - void touch() { last_use = time(NULL); } + void touch() { last_use = upTime(); } }; typedef std::pair cache_pair; @@ -59,11 +60,11 @@ protected: int mCacheCount; // Number of items cached cache_type mCache; // Hold strong reference to recent objects - time_t mLastSweep; + int mLastSweep; public: TaggedCache(const char *name, int size, int age) - : mName(name), mTargetSize(size), mTargetAge(age), mCacheCount(0), mLastSweep(time(NULL)) { ; } + : mName(name), mTargetSize(size), mTargetAge(age), mCacheCount(0), mLastSweep(upTime()) { ; } int getTargetSize() const; int getTargetAge() const; @@ -128,8 +129,8 @@ template void TaggedCache::sweep { boost::recursive_mutex::scoped_lock sl(mLock); - time_t mLastSweep = time(NULL); - time_t target = mLastSweep - mTargetAge; + int mLastSweep = upTime(); + int target = mLastSweep - mTargetAge; int cacheRemovals = 0, mapRemovals = 0, cc = 0; if ((mTargetSize != 0) && (mCache.size() > mTargetSize)) @@ -243,7 +244,7 @@ bool TaggedCache::canonicalize(const key_type& key, boost::shared cache_iterator cit = mCache.find(key); if (cit == mCache.end()) { - mCache.insert(cache_pair(key, cache_entry(time(NULL), data))); + mCache.insert(cache_pair(key, cache_entry(upTime(), data))); ++mCacheCount; return false; } From 4f400420902acb0e175294a2114c5780006e1f27 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 6 Feb 2013 02:20:54 -0800 Subject: [PATCH 5/5] Remove an extraneous cast. --- src/cpp/ripple/NetworkOPs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp/ripple/NetworkOPs.cpp b/src/cpp/ripple/NetworkOPs.cpp index 4816d3622a..a8b6d01cd1 100644 --- a/src/cpp/ripple/NetworkOPs.cpp +++ b/src/cpp/ripple/NetworkOPs.cpp @@ -1178,7 +1178,7 @@ Json::Value NetworkOPs::getServerInfo(bool human, bool admin) } else { - l["base_fee_xrp"] = static_cast(Json::UInt(baseFee)) / SYSTEM_CURRENCY_PARTS; + l["base_fee_xrp"] = static_cast(baseFee) / SYSTEM_CURRENCY_PARTS; l["reserve_base_xrp"] = static_cast(Json::UInt(lpClosed->getReserve(0) * baseFee / baseRef)) / SYSTEM_CURRENCY_PARTS; l["reserve_inc_xrp"] =