Skip to content

Commit

Permalink
Merge pull request #2161 from graydon/stop-looking-up-metrics-on-ever…
Browse files Browse the repository at this point in the history
…y-packet

overlay: cache metrics so we don't keep looking them up.

Reviewed-by: MonsieurNicolas
  • Loading branch information
latobarita authored Jun 20, 2019
2 parents 1247f64 + 1ee554d commit 52f1a03
Show file tree
Hide file tree
Showing 13 changed files with 259 additions and 185 deletions.
2 changes: 2 additions & 0 deletions Builds/VisualStudio/stellar-core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ exit /b 0
<ClCompile Include="..\..\src\overlay\ItemFetcher.cpp" />
<ClCompile Include="..\..\src\overlay\LoadManager.cpp" />
<ClCompile Include="..\..\src\overlay\OverlayManagerImpl.cpp" />
<ClCompile Include="..\..\src\overlay\OverlayMetrics.cpp" />
<ClCompile Include="..\..\src\overlay\Peer.cpp" />
<ClCompile Include="..\..\src\overlay\PeerAuth.cpp" />
<ClCompile Include="..\..\src\overlay\PeerBareAddress.cpp" />
Expand Down Expand Up @@ -692,6 +693,7 @@ exit /b 0
<ClInclude Include="..\..\src\overlay\LoadManager.h" />
<ClInclude Include="..\..\src\overlay\OverlayManager.h" />
<ClInclude Include="..\..\src\overlay\OverlayManagerImpl.h" />
<ClInclude Include="..\..\src\overlay\OverlayMetrics.h" />
<ClInclude Include="..\..\src\overlay\Peer.h" />
<ClInclude Include="..\..\src\overlay\PeerAuth.h" />
<ClInclude Include="..\..\src\overlay\PeerBareAddress.h" />
Expand Down
6 changes: 6 additions & 0 deletions Builds/VisualStudio/stellar-core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,9 @@
<ClCompile Include="..\..\src\overlay\OverlayManagerImpl.cpp">
<Filter>overlay</Filter>
</ClCompile>
<ClCompile Include="..\..\src\overlay\OverlayMetrics.cpp">
<Filter>overlay</Filter>
</ClCompile>
<ClCompile Include="..\..\src\overlay\Peer.cpp">
<Filter>overlay</Filter>
</ClCompile>
Expand Down Expand Up @@ -1577,6 +1580,9 @@
<ClInclude Include="..\..\src\overlay\OverlayManagerImpl.h">
<Filter>overlay</Filter>
</ClInclude>
<ClInclude Include="..\..\src\overlay\OverlayMetrics.h">
<Filter>overlay</Filter>
</ClInclude>
<ClInclude Include="..\..\src\overlay\Peer.h">
<Filter>overlay</Filter>
</ClInclude>
Expand Down
15 changes: 11 additions & 4 deletions src/overlay/LoadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "main/Application.h"
#include "main/Config.h"
#include "overlay/OverlayManager.h"
#include "overlay/OverlayMetrics.h"
#include "util/Logging.h"
#include "util/XDROperators.h"
#include "util/types.h"
Expand Down Expand Up @@ -171,8 +172,10 @@ LoadManager::PeerContext::PeerContext(Application& app, NodeID const& node)
: mApp(app)
, mNode(node)
, mWorkStart(app.getClock().now())
, mBytesSendStart(Peer::getByteWriteMeter(app).count())
, mBytesRecvStart(Peer::getByteReadMeter(app).count())
, mBytesSendStart(
app.getOverlayManager().getOverlayMetrics().mByteWrite.count())
, mBytesRecvStart(
app.getOverlayManager().getOverlayMetrics().mByteRead.count())
, mSQLQueriesStart(app.getDatabase().getQueryMeter().count())
{
}
Expand All @@ -184,8 +187,12 @@ LoadManager::PeerContext::~PeerContext()
auto pc = mApp.getOverlayManager().getLoadManager().getPeerCosts(mNode);
auto time = std::chrono::duration_cast<std::chrono::nanoseconds>(
mApp.getClock().now() - mWorkStart);
auto send = Peer::getByteWriteMeter(mApp).count() - mBytesSendStart;
auto recv = Peer::getByteReadMeter(mApp).count() - mBytesRecvStart;
auto send =
mApp.getOverlayManager().getOverlayMetrics().mByteWrite.count() -
mBytesSendStart;
auto recv =
mApp.getOverlayManager().getOverlayMetrics().mByteRead.count() -
mBytesRecvStart;
auto query =
(mApp.getDatabase().getQueryMeter().count() - mSQLQueriesStart);
if (Logging::logTrace("Overlay"))
Expand Down
2 changes: 1 addition & 1 deletion src/overlay/LoadManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class LoadManager
class PeerContext
{
Application& mApp;
NodeID mNode;
NodeID const& mNode;

VirtualClock::time_point mWorkStart;
std::uint64_t mBytesSendStart;
Expand Down
3 changes: 3 additions & 0 deletions src/overlay/OverlayManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ class OverlayManager
// returns the list of peers that sent us the item with hash `h`
virtual std::set<Peer::pointer> getPeersKnows(Hash const& h) = 0;

// Return the persistent overlay metrics structure.
virtual OverlayMetrics& getOverlayMetrics() = 0;

// Return the persistent p2p authentication-key cache.
virtual PeerAuth& getPeerAuth() = 0;

Expand Down
21 changes: 12 additions & 9 deletions src/overlay/OverlayManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "main/Application.h"
#include "main/Config.h"
#include "main/ErrorMessages.h"
#include "overlay/OverlayMetrics.h"
#include "overlay/PeerBareAddress.h"
#include "overlay/PeerManager.h"
#include "overlay/RandomPeerSource.h"
Expand Down Expand Up @@ -239,12 +240,7 @@ OverlayManagerImpl::OverlayManagerImpl(Application& app)
, mDoor(mApp)
, mAuth(mApp)
, mShuttingDown(false)
, mMessagesBroadcast(app.getMetrics().NewMeter(
{"overlay", "message", "broadcast"}, "message"))
, mPendingPeersSize(
app.getMetrics().NewCounter({"overlay", "connection", "pending"}))
, mAuthenticatedPeersSize(app.getMetrics().NewCounter(
{"overlay", "connection", "authenticated"}))
, mOverlayMetrics(app)
, mTimer(app)
, mPeerIPTimer(app)
, mFloodGate(app)
Expand Down Expand Up @@ -589,8 +585,9 @@ OverlayManagerImpl::ledgerClosed(uint32_t lastClosedledgerSeq)
void
OverlayManagerImpl::updateSizeCounters()
{
mPendingPeersSize.set_count(getPendingPeersCount());
mAuthenticatedPeersSize.set_count(getAuthenticatedPeersCount());
mOverlayMetrics.mPendingPeersSize.set_count(getPendingPeersCount());
mOverlayMetrics.mAuthenticatedPeersSize.set_count(
getAuthenticatedPeersCount());
}

void
Expand Down Expand Up @@ -816,7 +813,7 @@ OverlayManagerImpl::recvFloodedMsg(StellarMessage const& msg,
void
OverlayManagerImpl::broadcastMessage(StellarMessage const& msg, bool force)
{
mMessagesBroadcast.Mark();
mOverlayMetrics.mMessagesBroadcast.Mark();
mFloodGate.broadcast(msg, force);
}

Expand All @@ -832,6 +829,12 @@ OverlayManagerImpl::getPeersKnows(Hash const& h)
return mFloodGate.getPeersKnows(h);
}

OverlayMetrics&
OverlayManagerImpl::getOverlayMetrics()
{
return mOverlayMetrics;
}

PeerAuth&
OverlayManagerImpl::getPeerAuth()
{
Expand Down
6 changes: 3 additions & 3 deletions src/overlay/OverlayManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "overlay/Floodgate.h"
#include "overlay/ItemFetcher.h"
#include "overlay/OverlayManager.h"
#include "overlay/OverlayMetrics.h"
#include "overlay/StellarXDR.h"
#include "util/Timer.h"

Expand Down Expand Up @@ -76,9 +77,7 @@ class OverlayManagerImpl : public OverlayManager
LoadManager mLoad;
bool mShuttingDown;

medida::Meter& mMessagesBroadcast;
medida::Counter& mPendingPeersSize;
medida::Counter& mAuthenticatedPeersSize;
OverlayMetrics mOverlayMetrics;

void tick();
VirtualTimer mTimer;
Expand Down Expand Up @@ -124,6 +123,7 @@ class OverlayManagerImpl : public OverlayManager

std::set<Peer::pointer> getPeersKnows(Hash const& h) override;

OverlayMetrics& getOverlayMetrics() override;
PeerAuth& getPeerAuth() override;

LoadManager& getLoadManager() override;
Expand Down
93 changes: 93 additions & 0 deletions src/overlay/OverlayMetrics.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#include "overlay/OverlayMetrics.h"
#include "main/Application.h"

#include "medida/meter.h"
#include "medida/metrics_registry.h"
#include "medida/timer.h"

namespace stellar
{

OverlayMetrics::OverlayMetrics(Application& app)
: mMessageRead(
app.getMetrics().NewMeter({"overlay", "message", "read"}, "message"))
, mMessageWrite(
app.getMetrics().NewMeter({"overlay", "message", "write"}, "message"))
, mByteRead(app.getMetrics().NewMeter({"overlay", "byte", "read"}, "byte"))
, mByteWrite(
app.getMetrics().NewMeter({"overlay", "byte", "write"}, "byte"))
, mErrorRead(
app.getMetrics().NewMeter({"overlay", "error", "read"}, "error"))
, mErrorWrite(
app.getMetrics().NewMeter({"overlay", "error", "write"}, "error"))
, mTimeoutIdle(
app.getMetrics().NewMeter({"overlay", "timeout", "idle"}, "timeout"))
, mTimeoutStraggler(app.getMetrics().NewMeter(
{"overlay", "timeout", "straggler"}, "timeout"))

, mRecvErrorTimer(app.getMetrics().NewTimer({"overlay", "recv", "error"}))
, mRecvHelloTimer(app.getMetrics().NewTimer({"overlay", "recv", "hello"}))
, mRecvAuthTimer(app.getMetrics().NewTimer({"overlay", "recv", "auth"}))
, mRecvDontHaveTimer(
app.getMetrics().NewTimer({"overlay", "recv", "dont-have"}))
, mRecvGetPeersTimer(
app.getMetrics().NewTimer({"overlay", "recv", "get-peers"}))
, mRecvPeersTimer(app.getMetrics().NewTimer({"overlay", "recv", "peers"}))
, mRecvGetTxSetTimer(
app.getMetrics().NewTimer({"overlay", "recv", "get-txset"}))
, mRecvTxSetTimer(app.getMetrics().NewTimer({"overlay", "recv", "txset"}))
, mRecvTransactionTimer(
app.getMetrics().NewTimer({"overlay", "recv", "transaction"}))
, mRecvGetSCPQuorumSetTimer(
app.getMetrics().NewTimer({"overlay", "recv", "get-scp-qset"}))
, mRecvSCPQuorumSetTimer(
app.getMetrics().NewTimer({"overlay", "recv", "scp-qset"}))
, mRecvSCPMessageTimer(
app.getMetrics().NewTimer({"overlay", "recv", "scp-message"}))
, mRecvGetSCPStateTimer(
app.getMetrics().NewTimer({"overlay", "recv", "get-scp-state"}))

, mRecvSCPPrepareTimer(
app.getMetrics().NewTimer({"overlay", "recv", "scp-prepare"}))
, mRecvSCPConfirmTimer(
app.getMetrics().NewTimer({"overlay", "recv", "scp-confirm"}))
, mRecvSCPNominateTimer(
app.getMetrics().NewTimer({"overlay", "recv", "scp-nominate"}))
, mRecvSCPExternalizeTimer(
app.getMetrics().NewTimer({"overlay", "recv", "scp-externalize"}))

, mSendErrorMeter(
app.getMetrics().NewMeter({"overlay", "send", "error"}, "message"))
, mSendHelloMeter(
app.getMetrics().NewMeter({"overlay", "send", "hello"}, "message"))
, mSendAuthMeter(
app.getMetrics().NewMeter({"overlay", "send", "auth"}, "message"))
, mSendDontHaveMeter(app.getMetrics().NewMeter(
{"overlay", "send", "dont-have"}, "message"))
, mSendGetPeersMeter(app.getMetrics().NewMeter(
{"overlay", "send", "get-peers"}, "message"))
, mSendPeersMeter(
app.getMetrics().NewMeter({"overlay", "send", "peers"}, "message"))
, mSendGetTxSetMeter(app.getMetrics().NewMeter(
{"overlay", "send", "get-txset"}, "message"))
, mSendTransactionMeter(app.getMetrics().NewMeter(
{"overlay", "send", "transaction"}, "message"))
, mSendTxSetMeter(
app.getMetrics().NewMeter({"overlay", "send", "txset"}, "message"))
, mSendGetSCPQuorumSetMeter(app.getMetrics().NewMeter(
{"overlay", "send", "get-scp-qset"}, "message"))
, mSendSCPQuorumSetMeter(
app.getMetrics().NewMeter({"overlay", "send", "scp-qset"}, "message"))
, mSendSCPMessageSetMeter(app.getMetrics().NewMeter(
{"overlay", "send", "scp-message"}, "message"))
, mSendGetSCPStateMeter(app.getMetrics().NewMeter(
{"overlay", "send", "get-scp-state"}, "message"))
, mMessagesBroadcast(app.getMetrics().NewMeter(
{"overlay", "message", "broadcast"}, "message"))
, mPendingPeersSize(
app.getMetrics().NewCounter({"overlay", "connection", "pending"}))
, mAuthenticatedPeersSize(app.getMetrics().NewCounter(
{"overlay", "connection", "authenticated"}))
{
}
}
73 changes: 73 additions & 0 deletions src/overlay/OverlayMetrics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#pragma once

// Copyright 2019 Stellar Development Foundation and contributors. Licensed
// under the Apache License, Version 2.0. See the COPYING file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0

// This structure just exists to cache frequently-accessed, overlay-wide
// (non-peer-specific) metrics. Some of these metrics are subsequently
// tabulated at a per-peer level for purposes of identifying and
// disconnecting overloading peers, see LoadManager for details.

namespace medida
{
class Timer;
class Meter;
class Counter;
}

namespace stellar
{

class Application;

struct OverlayMetrics
{
OverlayMetrics(Application& app);
medida::Meter& mMessageRead;
medida::Meter& mMessageWrite;
medida::Meter& mByteRead;
medida::Meter& mByteWrite;
medida::Meter& mErrorRead;
medida::Meter& mErrorWrite;
medida::Meter& mTimeoutIdle;
medida::Meter& mTimeoutStraggler;

medida::Timer& mRecvErrorTimer;
medida::Timer& mRecvHelloTimer;
medida::Timer& mRecvAuthTimer;
medida::Timer& mRecvDontHaveTimer;
medida::Timer& mRecvGetPeersTimer;
medida::Timer& mRecvPeersTimer;
medida::Timer& mRecvGetTxSetTimer;
medida::Timer& mRecvTxSetTimer;
medida::Timer& mRecvTransactionTimer;
medida::Timer& mRecvGetSCPQuorumSetTimer;
medida::Timer& mRecvSCPQuorumSetTimer;
medida::Timer& mRecvSCPMessageTimer;
medida::Timer& mRecvGetSCPStateTimer;

medida::Timer& mRecvSCPPrepareTimer;
medida::Timer& mRecvSCPConfirmTimer;
medida::Timer& mRecvSCPNominateTimer;
medida::Timer& mRecvSCPExternalizeTimer;

medida::Meter& mSendErrorMeter;
medida::Meter& mSendHelloMeter;
medida::Meter& mSendAuthMeter;
medida::Meter& mSendDontHaveMeter;
medida::Meter& mSendGetPeersMeter;
medida::Meter& mSendPeersMeter;
medida::Meter& mSendGetTxSetMeter;
medida::Meter& mSendTransactionMeter;
medida::Meter& mSendTxSetMeter;
medida::Meter& mSendGetSCPQuorumSetMeter;
medida::Meter& mSendSCPQuorumSetMeter;
medida::Meter& mSendSCPMessageSetMeter;
medida::Meter& mSendGetSCPStateMeter;

medida::Meter& mMessagesBroadcast;
medida::Counter& mPendingPeersSize;
medida::Counter& mAuthenticatedPeersSize;
};
}
Loading

0 comments on commit 52f1a03

Please sign in to comment.