From e3ee07b5a0f19a35b7d947027d2a65aa0820068d Mon Sep 17 00:00:00 2001 From: Julian Brost Date: Mon, 8 Sep 2025 17:52:18 +0200 Subject: [PATCH] Measure and store message processing time per endpoint Co-authored-by: Alexander A. Klimov --- lib/remote/endpoint.cpp | 5 +++++ lib/remote/endpoint.hpp | 3 +++ lib/remote/jsonrpcconnection.cpp | 3 +++ 3 files changed, 11 insertions(+) diff --git a/lib/remote/endpoint.cpp b/lib/remote/endpoint.cpp index 42a5a5af1..c13d4f7d2 100644 --- a/lib/remote/endpoint.cpp +++ b/lib/remote/endpoint.cpp @@ -130,6 +130,11 @@ void Endpoint::AddMessageReceived(const intrusive_ptr& method) m_MessageCounters.at(method).fetch_add(1, std::memory_order_relaxed); } +void Endpoint::AddMessageProcessed(const AtomicDuration::Clock::duration& duration) +{ + m_InputProcessingTime += duration; +} + double Endpoint::GetMessagesSentPerSecond() const { return m_MessagesSent.CalculateRate(Utility::GetTime(), 60); diff --git a/lib/remote/endpoint.hpp b/lib/remote/endpoint.hpp index 09ad8a4fd..5d80f26de 100644 --- a/lib/remote/endpoint.hpp +++ b/lib/remote/endpoint.hpp @@ -49,6 +49,7 @@ public: void AddMessageSent(int bytes); void AddMessageReceived(int bytes); void AddMessageReceived(const intrusive_ptr& method); + void AddMessageProcessed(const AtomicDuration::Clock::duration& duration); double GetMessagesSentPerSecond() const override; double GetMessagesReceivedPerSecond() const override; @@ -71,6 +72,8 @@ private: mutable RingBuffer m_MessagesReceived{60}; mutable RingBuffer m_BytesSent{60}; mutable RingBuffer m_BytesReceived{60}; + + AtomicDuration m_InputProcessingTime; }; } diff --git a/lib/remote/jsonrpcconnection.cpp b/lib/remote/jsonrpcconnection.cpp index b85944867..0dab1ed5f 100644 --- a/lib/remote/jsonrpcconnection.cpp +++ b/lib/remote/jsonrpcconnection.cpp @@ -106,6 +106,9 @@ void JsonRpcConnection::HandleIncomingMessages(boost::asio::yield_context yc) l_TaskStats.InsertValue(Utility::GetTime(), 1); auto total = ch::steady_clock::now() - start; + if (m_Endpoint) { + m_Endpoint->AddMessageProcessed(total); + } Log msg(total >= ch::seconds(5) ? LogWarning : LogDebug, "JsonRpcConnection"); msg << "Processed JSON-RPC '" << rpcMethod << "' message for identity '" << m_Identity