Add historical ledger fetches per minute to get_counts

This commit is contained in:
Vinnie Falco
2015-05-11 18:50:24 -07:00
parent dde5ccf7fa
commit 688f8c5f3f
5 changed files with 36 additions and 1 deletions

View File

@@ -353,9 +353,9 @@ void InboundLedger::done ()
{ {
mLedger->setClosed (); mLedger->setClosed ();
mLedger->setImmutable (); mLedger->setImmutable ();
if (mReason != fcHISTORY) if (mReason != fcHISTORY)
getApp().getLedgerMaster ().storeLedger (mLedger); getApp().getLedgerMaster ().storeLedger (mLedger);
getApp().getInboundLedgers().onLedgerFetched(mReason);
} }
else else
getApp().getInboundLedgers ().logFailure (mHash); getApp().getInboundLedgers ().logFailure (mHash);

View File

@@ -21,6 +21,7 @@
#include <ripple/app/ledger/InboundLedgers.h> #include <ripple/app/ledger/InboundLedgers.h>
#include <ripple/app/main/Application.h> #include <ripple/app/main/Application.h>
#include <ripple/app/misc/NetworkOPs.h> #include <ripple/app/misc/NetworkOPs.h>
#include <ripple/basics/DecayingSample.h>
#include <ripple/basics/Log.h> #include <ripple/basics/Log.h>
#include <ripple/core/JobQueue.h> #include <ripple/core/JobQueue.h>
#include <beast/cxx14/memory.h> // <memory> #include <beast/cxx14/memory.h> // <memory>
@@ -32,6 +33,11 @@ class InboundLedgersImp
: public InboundLedgers : public InboundLedgers
, public beast::Stoppable , public beast::Stoppable
{ {
private:
std::mutex fetchRateMutex_;
// measures ledgers per second, constants are important
DecayWindow<30, clock_type> fetchRate_;
public: public:
typedef std::pair<uint256, InboundLedger::pointer> u256_acq_pair; typedef std::pair<uint256, InboundLedger::pointer> u256_acq_pair;
// How long before we try again to acquire the same ledger // How long before we try again to acquire the same ledger
@@ -40,6 +46,7 @@ public:
InboundLedgersImp (clock_type& clock, Stoppable& parent, InboundLedgersImp (clock_type& clock, Stoppable& parent,
beast::insight::Collector::ptr const& collector) beast::insight::Collector::ptr const& collector)
: Stoppable ("InboundLedgers", parent) : Stoppable ("InboundLedgers", parent)
, fetchRate_(clock.now())
, m_clock (clock) , m_clock (clock)
, mRecentFailures ("LedgerAcquireRecentFailures", , mRecentFailures ("LedgerAcquireRecentFailures",
clock, 0, kReacquireIntervalSeconds) clock, 0, kReacquireIntervalSeconds)
@@ -250,6 +257,24 @@ public:
mLedgers.clear(); 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 getInfo()
{ {
Json::Value ret(Json::objectValue); Json::Value ret(Json::objectValue);

View File

@@ -71,6 +71,12 @@ public:
virtual Json::Value getInfo() = 0; 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 gotFetchPack (Job&) = 0;
virtual void sweep () = 0; virtual void sweep () = 0;

View File

@@ -43,6 +43,7 @@ JSS ( Invalid ); // out: app/misc/AccountState
JSS ( LimitAmount ); // field. JSS ( LimitAmount ); // field.
JSS ( OfferSequence ); // field. JSS ( OfferSequence ); // field.
JSS ( Paths ); // in/out: TransactionSign JSS ( Paths ); // in/out: TransactionSign
JSS ( historical_perminute ); // historical_perminute
JSS ( SLE_hit_rate ); // out: GetCounts JSS ( SLE_hit_rate ); // out: GetCounts
JSS ( SendMax ); // in: TransactionSign JSS ( SendMax ); // in: TransactionSign
JSS ( Sequence ); // in/out: TransactionSign; field. JSS ( Sequence ); // in/out: TransactionSign; field.

View File

@@ -20,6 +20,7 @@
#include <BeastConfig.h> #include <BeastConfig.h>
#include <ripple/app/data/DatabaseCon.h> #include <ripple/app/data/DatabaseCon.h>
#include <ripple/app/ledger/AcceptedLedger.h> #include <ripple/app/ledger/AcceptedLedger.h>
#include <ripple/app/ledger/InboundLedgers.h>
#include <ripple/basics/UptimeTimer.h> #include <ripple/basics/UptimeTimer.h>
#include <ripple/nodestore/Database.h> #include <ripple/nodestore/Database.h>
@@ -69,6 +70,8 @@ Json::Value doGetCounts (RPC::Context& context)
ret[jss::write_load] = app.getNodeStore ().getWriteLoad (); ret[jss::write_load] = app.getNodeStore ().getWriteLoad ();
ret[jss::historical_perminute] = static_cast<int>(
app.getInboundLedgers().fetchRate());
ret[jss::SLE_hit_rate] = app.getSLECache ().getHitRate (); ret[jss::SLE_hit_rate] = app.getSLECache ().getHitRate ();
ret[jss::node_hit_rate] = app.getNodeStore ().getCacheHitRate (); ret[jss::node_hit_rate] = app.getNodeStore ().getCacheHitRate ();
ret[jss::ledger_hit_rate] = app.getLedgerMaster ().getCacheHitRate (); ret[jss::ledger_hit_rate] = app.getLedgerMaster ().getCacheHitRate ();