Skip to content

Commit ef2a7d3

Browse files
committed
Benchmark message reading/processing time per endpoint
1 parent 92a4f45 commit ef2a7d3

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

lib/remote/endpoint.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "remote/i2-remote.hpp"
77
#include "remote/endpoint-ti.hpp"
8+
#include "base/benchmark.hpp"
89
#include "base/ringbuffer.hpp"
910
#include <set>
1011

@@ -43,6 +44,13 @@ class Endpoint final : public ObjectImpl<Endpoint>
4344
void AddMessageSent(int bytes);
4445
void AddMessageReceived(int bytes);
4546

47+
template<class R, class P>
48+
void AddInputTimes(const R& readTime, const P& processTime)
49+
{
50+
m_InputReadTime += readTime;
51+
m_InputProcessTime += processTime;
52+
}
53+
4654
double GetMessagesSentPerSecond() const override;
4755
double GetMessagesReceivedPerSecond() const override;
4856

@@ -61,6 +69,9 @@ class Endpoint final : public ObjectImpl<Endpoint>
6169
mutable RingBuffer m_MessagesReceived{60};
6270
mutable RingBuffer m_BytesSent{60};
6371
mutable RingBuffer m_BytesReceived{60};
72+
73+
Benchmark m_InputReadTime;
74+
Benchmark m_InputProcessTime;
6475
};
6576

6677
}

lib/remote/jsonrpcconnection.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "remote/jsonrpcconnection.hpp"
44
#include "remote/apilistener.hpp"
55
#include "remote/apifunction.hpp"
6+
#include "base/benchmark.hpp"
67
#include "remote/jsonrpc.hpp"
78
#include "base/defer.hpp"
89
#include "base/configtype.hpp"
@@ -66,11 +67,17 @@ void JsonRpcConnection::HandleIncomingMessages(boost::asio::yield_context yc)
6667
return ch::duration_cast<ch::milliseconds>(d).count();
6768
});
6869

70+
Benchmark::Clock::time_point readStarted, readFinished, processingStarted;
71+
6972
m_Stream->next_layer().SetSeen(&m_Seen);
7073

7174
while (!m_ShuttingDown) {
7275
String jsonString;
7376

77+
if (m_Endpoint) {
78+
readStarted = Benchmark::Clock::now();
79+
}
80+
7481
try {
7582
jsonString = JsonRpc::ReadMessage(m_Stream, yc, m_Endpoint ? -1 : 1024 * 1024);
7683
} catch (const std::exception& ex) {
@@ -81,6 +88,10 @@ void JsonRpcConnection::HandleIncomingMessages(boost::asio::yield_context yc)
8188
break;
8289
}
8390

91+
if (m_Endpoint) {
92+
readFinished = Benchmark::Clock::now();
93+
}
94+
8495
m_Seen = Utility::GetTime();
8596
if (m_Endpoint) {
8697
m_Endpoint->AddMessageReceived(jsonString.GetLength());
@@ -96,13 +107,21 @@ void JsonRpcConnection::HandleIncomingMessages(boost::asio::yield_context yc)
96107
// Cache the elapsed time to acquire a CPU semaphore used to detect extremely heavy workloads.
97108
cpuBoundDuration = ch::steady_clock::now() - start;
98109

110+
if (m_Endpoint) {
111+
processingStarted = Benchmark::Clock::now();
112+
}
113+
99114
Dictionary::Ptr message = JsonRpc::DecodeMessage(jsonString);
100115
if (String method = message->Get("method"); !method.IsEmpty()) {
101116
rpcMethod = std::move(method);
102117
}
103118

104119
MessageHandler(message);
105120

121+
if (m_Endpoint) {
122+
m_Endpoint->AddInputTimes(readFinished - readStarted, processingStarted);
123+
}
124+
106125
l_TaskStats.InsertValue(Utility::GetTime(), 1);
107126

108127
auto total = ch::steady_clock::now() - start;

0 commit comments

Comments
 (0)