Skip to content

Commit 5d9519f

Browse files
authored
Add IC queue time metric. EXT-1612 (#28184)
Add IC queue time metric. Time spend in the interconnect queue did not report in any existed counter, but it is important for performance analysis.
1 parent 97b61de commit 5d9519f

File tree

8 files changed

+45
-10
lines changed

8 files changed

+45
-10
lines changed

ydb/library/actors/interconnect/interconnect_channel.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ namespace NActors {
7171
switch (State) {
7272
case EState::INITIAL:
7373
event.InitChecksum();
74+
if (event.EnqueueTime) {
75+
TDuration duration = NActors::TlsActivationContext->Now() - event.EnqueueTime;
76+
Metrics->UpdateIcQueueTimeHistogram(duration.MicroSeconds());
77+
}
78+
event.Span && event.Span.Event("FeedBuf:INITIAL");
7479
if (event.Buffer) {
7580
State = EState::BODY;
7681
Iter = event.Buffer->GetBeginIter();

ydb/library/actors/interconnect/interconnect_channel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ namespace NActors {
7777
~TEventOutputChannel() {
7878
}
7979

80-
std::pair<ui32, TEventHolder*> Push(IEventHandle& ev, TEventHolderPool& pool) {
80+
std::pair<ui32, TEventHolder*> Push(IEventHandle& ev, TEventHolderPool& pool, TInstant now) {
8181
TEventHolder& event = pool.Allocate(Queue);
82-
const ui32 bytes = event.Fill(ev) + sizeof(TEventDescr2);
82+
const ui32 bytes = event.Fill(ev, now) + sizeof(TEventDescr2);
8383
OutputQueueSize += bytes;
8484
if (event.Span = NWilson::TSpan(15 /*max verbosity*/, NWilson::TTraceId(ev.TraceId), "Interconnect.Queue")) {
8585
event.Span

ydb/library/actors/interconnect/interconnect_counters.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ namespace {
236236
PingTimeHistogram->Collect(value);
237237
}
238238

239+
void UpdateIcQueueTimeHistogram(ui64 value) override {
240+
InterconnectQueueTimeHistogram->Collect(value);
241+
}
242+
239243
void UpdateOutputChannelTraffic(ui16 channel, ui64 value) override {
240244
auto& ch = GetOutputChannel(channel);
241245
if (ch.OutgoingTraffic) {
@@ -317,6 +321,8 @@ namespace {
317321

318322
PingTimeHistogram = AdaptiveCounters->GetHistogram(
319323
"PingTimeUs", NMonitoring::ExponentialHistogram(18, 2, 125));
324+
InterconnectQueueTimeHistogram = AdaptiveCounters->GetHistogram(
325+
"InterconnectQueueTimeHistogramUs", NMonitoring::ExplicitHistogram({500, 1000, 5000, 10000, 50000, 100000}));
320326
}
321327

322328
if (updateGlobal) {
@@ -379,6 +385,7 @@ namespace {
379385
NMonitoring::TDynamicCounters::TCounterPtr UsefulWriteWakeups;
380386
NMonitoring::TDynamicCounters::TCounterPtr SpuriousWriteWakeups;
381387
NMonitoring::THistogramPtr PingTimeHistogram;
388+
NMonitoring::THistogramPtr InterconnectQueueTimeHistogram;
382389

383390
std::unordered_map<ui16, TOutputChannel> OutputChannels;
384391
TOutputChannel OtherOutputChannel;
@@ -580,6 +587,10 @@ namespace {
580587
PingTimeHistogram_->Record(value);
581588
}
582589

590+
void UpdateIcQueueTimeHistogram(ui64 value) override {
591+
InterconnectQueueTimeHistogram_->Record(value);
592+
}
593+
583594
void UpdateOutputChannelTraffic(ui16 channel, ui64 value) override {
584595
auto& ch = GetOutputChannel(channel);
585596
if (ch.OutgoingTraffic) {
@@ -672,6 +683,8 @@ namespace {
672683
InflightDataAmount_ = createRate(AdaptiveMetrics_, "interconnect.inflight_data");
673684
PingTimeHistogram_ = AdaptiveMetrics_->HistogramRate(
674685
NMonitoring::MakeLabels({{"sensor", "interconnect.ping_time_us"}}), NMonitoring::ExponentialHistogram(18, 2, 125));
686+
InterconnectQueueTimeHistogram_ = AdaptiveMetrics_->HistogramRate(
687+
NMonitoring::MakeLabels({{"sensor", "interconnect.ic_queue_time_us"}}), NMonitoring::ExplicitHistogram({500, 1000, 5000, 10000, 50000, 100000}));
675688
}
676689

677690
if (updateGlobal) {
@@ -756,6 +769,7 @@ namespace {
756769
NMonitoring::IIntGauge* ClockSkewMicrosec_;
757770

758771
NMonitoring::IHistogram* PingTimeHistogram_;
772+
NMonitoring::IHistogram* InterconnectQueueTimeHistogram_;
759773

760774
THashMap<ui16, TOutputChannel> OutputChannels_;
761775
TOutputChannel OtherOutputChannel_;

ydb/library/actors/interconnect/interconnect_counters.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class IInterconnectMetrics {
4141
virtual void IncRecvSyscalls(ui64 ns) = 0;
4242
virtual void AddTotalBytesRead(ui64 value) = 0;
4343
virtual void UpdatePingTimeHistogram(ui64 value) = 0;
44+
virtual void UpdateIcQueueTimeHistogram(ui64 value) = 0;
4445
virtual void UpdateOutputChannelTraffic(ui16 channel, ui64 value) = 0;
4546
virtual void UpdateOutputChannelEvents(ui16 channel) = 0;
4647
virtual void SetUtilization(ui32 total, ui32 starvation) = 0;

ydb/library/actors/interconnect/interconnect_tcp_session.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ namespace NActors {
153153
auto& oChannel = ChannelScheduler->GetOutputChannel(evChannel);
154154
const bool wasWorking = oChannel.IsWorking();
155155

156-
const auto [dataSize, event] = oChannel.Push(*ev, *Pool);
156+
TInstant now = TlsActivationContext->Now();
157+
158+
const auto [dataSize, event] = oChannel.Push(*ev, *Pool, now);
157159
LWTRACK(ForwardEvent, event->Orbit, Proxy->PeerNodeId, event->Descr.Type, event->Descr.Flags, LWACTORID(event->Descr.Recipient), LWACTORID(event->Descr.Sender), event->Descr.Cookie, event->EventSerializedSize);
158160

159161
TotalOutputQueueSize += dataSize;

ydb/library/actors/interconnect/packet.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
#include "packet.h"
2+
#include "interconnect_counters.h"
23

34
#include <ydb/library/actors/core/probes.h>
45

56
#include <util/system/datetime.h>
67

78
LWTRACE_USING(ACTORLIB_PROVIDER);
89

10+
TTcpPacketOutTask::TTcpPacketOutTask(const TSessionParams& params, NInterconnect::TOutgoingStream& outgoingStream,
11+
NInterconnect::TOutgoingStream& xdcStream)
12+
: Params(params)
13+
, OutgoingStream(outgoingStream)
14+
, XdcStream(xdcStream)
15+
, HeaderBookmark(OutgoingStream.Bookmark(sizeof(TTcpPacketHeader_v2)))
16+
{}
17+
918
ui32 TEventHolder::Fill(IEventHandle& ev) {
1019
Serial = 0;
1120
Descr.Type = ev.Type;
@@ -31,3 +40,8 @@ ui32 TEventHolder::Fill(IEventHandle& ev) {
3140

3241
return EventSerializedSize;
3342
}
43+
44+
ui32 TEventHolder::Fill(IEventHandle& ev, TInstant now) {
45+
EnqueueTime = now;
46+
return Fill(ev);
47+
}

ydb/library/actors/interconnect/packet.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ struct TEventHolder : TNonCopyable {
100100
mutable NLWTrace::TOrbit Orbit;
101101
NWilson::TSpan Span;
102102
ui32 ZcTransferId; //id of zero copy transfer. In case of RDMA it is a place where some internal handle can be stored to identify events
103+
TInstant EnqueueTime;
103104

104105
ui32 Fill(IEventHandle& ev);
106+
ui32 Fill(IEventHandle& ev, TInstant now);
105107

106108
void InitChecksum() {
107109
Descr.Checksum = 0;
@@ -135,13 +137,15 @@ struct TEventHolder : TNonCopyable {
135137

136138
namespace NActors {
137139
class TEventOutputChannel;
140+
class IInterconnectMetrics;
138141
}
139142

140143
struct TTcpPacketOutTask : TNonCopyable {
141144
const TSessionParams& Params;
142145
NInterconnect::TOutgoingStream& OutgoingStream;
143146
NInterconnect::TOutgoingStream& XdcStream;
144147
NInterconnect::TOutgoingStream::TBookmark HeaderBookmark;
148+
145149
ui32 InternalSize = 0;
146150
ui32 ExternalSize = 0;
147151

@@ -153,12 +157,7 @@ struct TTcpPacketOutTask : TNonCopyable {
153157
ui32 ExternalChecksum = 0;
154158

155159
TTcpPacketOutTask(const TSessionParams& params, NInterconnect::TOutgoingStream& outgoingStream,
156-
NInterconnect::TOutgoingStream& xdcStream)
157-
: Params(params)
158-
, OutgoingStream(outgoingStream)
159-
, XdcStream(xdcStream)
160-
, HeaderBookmark(OutgoingStream.Bookmark(sizeof(TTcpPacketHeader_v2)))
161-
{}
160+
NInterconnect::TOutgoingStream& xdcStream);
162161

163162
// Preallocate some space to fill it later.
164163
NInterconnect::TOutgoingStream::TBookmark Bookmark(size_t len) {

ydb/library/actors/interconnect/ut/channel_scheduler_ut.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Y_UNIT_TEST_SUITE(ChannelScheduler) {
2323
auto ev = MakeHolder<IEventHandle>(1, 0, TActorId(), TActorId(), MakeIntrusive<TEventSerializedData>(payload, TEventSerializationInfo{}), 0);
2424
auto& ch = scheduler.GetOutputChannel(channel);
2525
const bool wasWorking = ch.IsWorking();
26-
ch.Push(*ev, pool);
26+
ch.Push(*ev, pool, TInstant::Zero()/*Do not account time outside AS*/);
2727
if (!wasWorking) {
2828
scheduler.AddToHeap(ch, 0);
2929
}

0 commit comments

Comments
 (0)