From 688f8c5f3f6410f85002962b46234b804a514b26 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Mon, 11 May 2015 18:50:24 -0700 Subject: [PATCH] Add historical ledger fetches per minute to get_counts --- src/ripple/app/ledger/InboundLedger.cpp | 2 +- src/ripple/app/ledger/InboundLedgers.cpp | 25 ++++++++++++++++++++++++ src/ripple/app/ledger/InboundLedgers.h | 6 ++++++ src/ripple/protocol/JsonFields.h | 1 + src/ripple/rpc/handlers/GetCounts.cpp | 3 +++ 5 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/ripple/app/ledger/InboundLedger.cpp b/src/ripple/app/ledger/InboundLedger.cpp index 5dfc4d7768..a9c2b7fa37 100644 --- a/src/ripple/app/ledger/InboundLedger.cpp +++ b/src/ripple/app/ledger/InboundLedger.cpp @@ -353,9 +353,9 @@ void InboundLedger::done () { mLedger->setClosed (); mLedger->setImmutable (); - if (mReason != fcHISTORY) getApp().getLedgerMaster ().storeLedger (mLedger); + getApp().getInboundLedgers().onLedgerFetched(mReason); } else getApp().getInboundLedgers ().logFailure (mHash); diff --git a/src/ripple/app/ledger/InboundLedgers.cpp b/src/ripple/app/ledger/InboundLedgers.cpp index 1db464f4c5..ea80c100b6 100644 --- a/src/ripple/app/ledger/InboundLedgers.cpp +++ b/src/ripple/app/ledger/InboundLedgers.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include // @@ -32,6 +33,11 @@ class InboundLedgersImp : public InboundLedgers , public beast::Stoppable { +private: + std::mutex fetchRateMutex_; + // measures ledgers per second, constants are important + DecayWindow<30, clock_type> fetchRate_; + public: typedef std::pair u256_acq_pair; // How long before we try again to acquire the same ledger @@ -40,6 +46,7 @@ public: InboundLedgersImp (clock_type& clock, Stoppable& parent, beast::insight::Collector::ptr const& collector) : Stoppable ("InboundLedgers", parent) + , fetchRate_(clock.now()) , m_clock (clock) , mRecentFailures ("LedgerAcquireRecentFailures", clock, 0, kReacquireIntervalSeconds) @@ -250,6 +257,24 @@ public: mLedgers.clear(); } + std::size_t fetchRate() + { + std::lock_guard< + std::mutex> lock(fetchRateMutex_); + return 60 * fetchRate_.value( + m_clock.now()); + } + + void onLedgerFetched ( + InboundLedger::fcReason why) + { + if (why != InboundLedger::fcHISTORY) + return; + std::lock_guard< + std::mutex> lock(fetchRateMutex_); + fetchRate_.add(1, m_clock.now()); + } + Json::Value getInfo() { Json::Value ret(Json::objectValue); diff --git a/src/ripple/app/ledger/InboundLedgers.h b/src/ripple/app/ledger/InboundLedgers.h index 726a31dde7..b7734611f9 100644 --- a/src/ripple/app/ledger/InboundLedgers.h +++ b/src/ripple/app/ledger/InboundLedgers.h @@ -71,6 +71,12 @@ public: virtual Json::Value getInfo() = 0; + /** Returns the rate of historical ledger fetches per minute. */ + virtual std::size_t fetchRate() = 0; + + /** Called when a complete ledger is obtained. */ + virtual void onLedgerFetched (InboundLedger::fcReason why) = 0; + virtual void gotFetchPack (Job&) = 0; virtual void sweep () = 0; diff --git a/src/ripple/protocol/JsonFields.h b/src/ripple/protocol/JsonFields.h index b237ab8b03..67468e7dc2 100644 --- a/src/ripple/protocol/JsonFields.h +++ b/src/ripple/protocol/JsonFields.h @@ -43,6 +43,7 @@ JSS ( Invalid ); // out: app/misc/AccountState JSS ( LimitAmount ); // field. JSS ( OfferSequence ); // field. JSS ( Paths ); // in/out: TransactionSign +JSS ( historical_perminute ); // historical_perminute JSS ( SLE_hit_rate ); // out: GetCounts JSS ( SendMax ); // in: TransactionSign JSS ( Sequence ); // in/out: TransactionSign; field. diff --git a/src/ripple/rpc/handlers/GetCounts.cpp b/src/ripple/rpc/handlers/GetCounts.cpp index 5be73ecdc4..9484810853 100644 --- a/src/ripple/rpc/handlers/GetCounts.cpp +++ b/src/ripple/rpc/handlers/GetCounts.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -69,6 +70,8 @@ Json::Value doGetCounts (RPC::Context& context) ret[jss::write_load] = app.getNodeStore ().getWriteLoad (); + ret[jss::historical_perminute] = static_cast( + app.getInboundLedgers().fetchRate()); ret[jss::SLE_hit_rate] = app.getSLECache ().getHitRate (); ret[jss::node_hit_rate] = app.getNodeStore ().getCacheHitRate (); ret[jss::ledger_hit_rate] = app.getLedgerMaster ().getCacheHitRate ();