Skip to content

Commit 397e1cb

Browse files
committed
Perflog peer info counts, and inbound traffic.
1 parent 8a6a60e commit 397e1cb

File tree

5 files changed

+124
-6
lines changed

5 files changed

+124
-6
lines changed

src/xrpld/overlay/Overlay.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,27 @@ class Overlay : public beast::PropertyStream::Source
219219
virtual std::uint64_t
220220
getPeerDisconnectCharges() const = 0;
221221

222+
virtual void
223+
incTotalPeerInbound() = 0;
224+
virtual std::uint64_t
225+
getTotalPeerInbound() const = 0;
226+
virtual void
227+
incTotalPeerInboundEarlyReturn() = 0;
228+
virtual std::uint64_t
229+
getTotalPeerInboundEarlyReturn() const = 0;
230+
virtual void
231+
addTotalPeerInboundBytes(std::uint64_t numBytes) = 0;
232+
virtual std::uint64_t
233+
getTotalPeerInboundBytes() const = 0;
234+
virtual void
235+
incTotalPeerInboundComplete() = 0;
236+
virtual std::uint64_t
237+
getTotalPeerInboundComplete() const = 0;
238+
virtual void
239+
incTotalPeerInboundPropose() = 0;
240+
virtual std::uint64_t
241+
getTotalPeerInboundPropose() const = 0;
242+
222243
/** Returns the ID of the network this server is configured for, if any.
223244
224245
The ID is just a numerical identifier, with the IDs 0, 1 and 2 used to

src/xrpld/overlay/detail/OverlayImpl.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ class OverlayImpl : public Overlay, public reduce_relay::SquelchHandler
119119
std::atomic<uint64_t> peerDisconnects_{0};
120120
std::atomic<uint64_t> peerDisconnectsCharges_{0};
121121

122+
std::atomic<uint64_t> totalPeerInbound_{0};
123+
std::atomic<uint64_t> totalPeerInboundEarlyReturn_{0};
124+
std::atomic<uint64_t> totalPeerInboundBytes_{0};
125+
std::atomic<uint64_t> totalPeerInboundComplete_{0};
126+
std::atomic<uint64_t> totalPeerInboundPropose_{0};
127+
128+
122129
reduce_relay::Slots<UptimeClock> slots_;
123130

124131
// Transaction reduce-relay metrics
@@ -380,6 +387,64 @@ class OverlayImpl : public Overlay, public reduce_relay::SquelchHandler
380387
return peerDisconnectsCharges_;
381388
}
382389

390+
void
391+
incTotalPeerInbound() override
392+
{
393+
++totalPeerInbound_;
394+
}
395+
396+
std::uint64_t
397+
getTotalPeerInbound() const override
398+
{
399+
return totalPeerInbound_;
400+
}
401+
402+
void
403+
incTotalPeerInboundEarlyReturn() override
404+
{
405+
++totalPeerInboundEarlyReturn_;
406+
}
407+
408+
std::uint64_t
409+
getTotalPeerInboundEarlyReturn() const override
410+
{
411+
return totalPeerInboundEarlyReturn_;
412+
}
413+
414+
void
415+
addTotalPeerInboundBytes(std::uint64_t numBytes) override {
416+
totalPeerInboundBytes_ += numBytes;
417+
}
418+
419+
std::uint64_t
420+
getTotalPeerInboundBytes() const override {
421+
return totalPeerInboundBytes_;
422+
}
423+
424+
std::uint64_t
425+
getTotalPeerInboundComplete() const override
426+
{
427+
return totalPeerInboundComplete_;
428+
}
429+
430+
void
431+
incTotalPeerInboundComplete() override
432+
{
433+
++totalPeerInboundComplete_;
434+
}
435+
436+
std::uint64_t
437+
getTotalPeerInboundPropose() const override
438+
{
439+
return totalPeerInboundPropose_;
440+
}
441+
442+
void
443+
incTotalPeerInboundPropose() override
444+
{
445+
++totalPeerInboundPropose_;
446+
}
447+
383448
std::optional<std::uint32_t>
384449
networkID() const override
385450
{

src/xrpld/overlay/detail/PeerImp.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -895,17 +895,25 @@ PeerImp::doProtocolStart()
895895
void
896896
PeerImp::onReadMessage(error_code ec, std::size_t bytes_transferred)
897897
{
898-
if (!socket_.is_open())
898+
app_.overlay().incTotalPeerInbound();
899+
if (!socket_.is_open()) {
900+
app_.overlay().incTotalPeerInboundEarlyReturn();
899901
return;
900-
if (ec == boost::asio::error::operation_aborted)
902+
}
903+
if (ec == boost::asio::error::operation_aborted) {
904+
app_.overlay().incTotalPeerInboundEarlyReturn();
901905
return;
906+
}
902907
if (ec == boost::asio::error::eof)
903908
{
904909
JLOG(journal_.info()) << "EOF";
910+
app_.overlay().incTotalPeerInboundEarlyReturn();
905911
return gracefulClose();
906912
}
907-
if (ec)
913+
if (ec) {
914+
app_.overlay().incTotalPeerInboundEarlyReturn();
908915
return fail("onReadMessage", ec);
916+
}
909917
if (auto stream = journal_.trace())
910918
{
911919
if (bytes_transferred > 0)
@@ -914,6 +922,8 @@ PeerImp::onReadMessage(error_code ec, std::size_t bytes_transferred)
914922
stream << "onReadMessage";
915923
}
916924

925+
app_.overlay().addTotalPeerInboundBytes(bytes_transferred);
926+
917927
metrics_.recv.add_message(bytes_transferred);
918928

919929
read_buffer_.commit(bytes_transferred);
@@ -927,7 +937,9 @@ PeerImp::onReadMessage(error_code ec, std::size_t bytes_transferred)
927937
using namespace std::chrono_literals;
928938
std::tie(bytes_consumed, ec) = perf::measureDurationAndLog(
929939
[&]() {
930-
return invokeProtocolMessage(read_buffer_.data(), *this, hint);
940+
return invokeProtocolMessage(read_buffer_.data(), *this, hint,
941+
[this]() { app_.overlay().incTotalPeerInboundComplete(); },
942+
[this]() { app_.overlay().incTotalPeerInboundPropose(); });
931943
},
932944
"invokeProtocolMessage",
933945
350ms,

src/xrpld/overlay/detail/ProtocolMessage.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,14 @@ invoke(MessageHeader const& header, Buffers const& buffers, Handler& handler)
331331
332332
@return The number of bytes consumed, or the error code if any.
333333
*/
334-
template <class Buffers, class Handler>
334+
template <class Buffers, class Handler, class Func, class Func2>
335335
std::pair<std::size_t, boost::system::error_code>
336336
invokeProtocolMessage(
337337
Buffers const& buffers,
338338
Handler& handler,
339-
std::size_t& hint)
339+
std::size_t& hint,
340+
Func incCompleteFunc,
341+
Func2 incProposeFunc)
340342
{
341343
std::pair<std::size_t, boost::system::error_code> result = {0, {}};
342344

@@ -384,6 +386,7 @@ invokeProtocolMessage(
384386

385387
bool success;
386388

389+
incCompleteFunc();
387390
switch (header->message_type)
388391
{
389392
case protocol::mtMANIFESTS:
@@ -417,6 +420,7 @@ invokeProtocolMessage(
417420
case protocol::mtPROPOSE_LEDGER:
418421
success = detail::invoke<protocol::TMProposeSet>(
419422
*header, buffers, handler);
423+
incProposeFunc();
420424
break;
421425
case protocol::mtSTATUS_CHANGE:
422426
success = detail::invoke<protocol::TMStatusChange>(

src/xrpld/perflog/detail/PerfLogImp.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#include <unordered_map>
3939
#include <utility>
4040

41+
#include "xrpld/overlay/Overlay.h"
42+
4143
namespace ripple {
4244
namespace perf {
4345

@@ -304,6 +306,20 @@ PerfLogImp::report()
304306
report[jss::nodestore] = Json::objectValue;
305307
app_.getNodeStore().getCountsJson(report[jss::nodestore]);
306308
report[jss::current_activities] = counters_.currentJson();
309+
310+
Json::Value peer = Json::objectValue;
311+
peer["total_inbound"] = std::to_string(app_.overlay().getTotalPeerInbound());
312+
peer["total_inbound_early_return"] = std::to_string(app_.overlay().getTotalPeerInboundEarlyReturn());
313+
peer["total_inbound_bytes"] = std::to_string(app_.overlay().getTotalPeerInboundBytes());
314+
peer["total_inbound_complete"] = std::to_string(app_.overlay().getTotalPeerInboundComplete());
315+
peer["total_inbound_propose"] = std::to_string(app_.overlay().getTotalPeerInboundPropose());
316+
peer[jss::peers] = Json::UInt(app_.overlay().size());
317+
peer[jss::peer_disconnects] =
318+
std::to_string(app_.overlay().getPeerDisconnect());
319+
peer[jss::peer_disconnects_resources] =
320+
std::to_string(app_.overlay().getPeerDisconnectCharges());
321+
report["peer"] = peer;
322+
307323
app_.getOPs().stateAccounting(report);
308324

309325
logFile_ << Json::Compact{std::move(report)} << std::endl;

0 commit comments

Comments
 (0)