aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralexvru <alexvru@ydb.tech>2023-05-12 09:44:31 +0300
committeralexvru <alexvru@ydb.tech>2023-05-12 09:44:31 +0300
commitaa95211fddb9867731b60e56b78ac75f05f42243 (patch)
tree789056bf407d4fd4b4bc614782212b47e6752191
parent16eb6cf01a4e163392c32921b8f84b2e3a8d1837 (diff)
downloadydb-aa95211fddb9867731b60e56b78ac75f05f42243.tar.gz
Fix IC counters performance
-rw-r--r--library/cpp/actors/interconnect/interconnect_counters.cpp42
-rw-r--r--library/cpp/actors/interconnect/interconnect_tcp_input_session.cpp19
-rw-r--r--library/cpp/actors/interconnect/interconnect_tcp_session.h2
3 files changed, 43 insertions, 20 deletions
diff --git a/library/cpp/actors/interconnect/interconnect_counters.cpp b/library/cpp/actors/interconnect/interconnect_counters.cpp
index 0a1a725570..3278160aef 100644
--- a/library/cpp/actors/interconnect/interconnect_counters.cpp
+++ b/library/cpp/actors/interconnect/interconnect_counters.cpp
@@ -215,20 +215,22 @@ namespace {
}
void UpdateOutputChannelTraffic(ui16 channel, ui64 value) override {
- if (GetOutputChannel(channel).OutgoingTraffic) {
- *(GetOutputChannel(channel).OutgoingTraffic) += value;
+ auto& ch = GetOutputChannel(channel);
+ if (ch.OutgoingTraffic) {
+ *ch.OutgoingTraffic += value;
}
- if (GetOutputChannel(channel).Traffic) {
- *(GetOutputChannel(channel).Traffic) += value;
+ if (ch.Traffic) {
+ *ch.Traffic += value;
}
}
void UpdateOutputChannelEvents(ui16 channel) override {
- if (GetOutputChannel(channel).OutgoingEvents) {
- ++*(GetOutputChannel(channel).OutgoingEvents);
+ auto& ch = GetOutputChannel(channel);
+ if (ch.OutgoingEvents) {
+ ++*ch.OutgoingEvents;
}
- if (GetOutputChannel(channel).Events) {
- ++*(GetOutputChannel(channel).Events);
+ if (ch.Events) {
+ ++*ch.Events;
}
}
@@ -309,7 +311,7 @@ namespace {
Initialized = true;
}
- TOutputChannel GetOutputChannel(ui16 index) const {
+ const TOutputChannel& GetOutputChannel(ui16 index) const {
Y_VERIFY(Initialized);
const auto it = OutputChannels.find(index);
return it != OutputChannels.end() ? it->second : OtherOutputChannel;
@@ -532,20 +534,22 @@ namespace {
}
void UpdateOutputChannelTraffic(ui16 channel, ui64 value) override {
- if (GetOutputChannel(channel).OutgoingTraffic) {
- GetOutputChannel(channel).OutgoingTraffic->Add(value);
+ auto& ch = GetOutputChannel(channel);
+ if (ch.OutgoingTraffic) {
+ ch.OutgoingTraffic->Add(value);
}
- if (GetOutputChannel(channel).Traffic) {
- GetOutputChannel(channel).Traffic->Add(value);
+ if (ch.Traffic) {
+ ch.Traffic->Add(value);
}
}
void UpdateOutputChannelEvents(ui16 channel) override {
- if (GetOutputChannel(channel).OutgoingEvents) {
- GetOutputChannel(channel).OutgoingEvents->Inc();
+ auto& ch = GetOutputChannel(channel);
+ if (ch.OutgoingEvents) {
+ ch.OutgoingEvents->Inc();
}
- if (GetOutputChannel(channel).Events) {
- GetOutputChannel(channel).Events->Inc();
+ if (ch.Events) {
+ ch.Events->Inc();
}
}
@@ -637,7 +641,7 @@ namespace {
Initialized_ = true;
}
- TOutputChannel GetOutputChannel(ui16 index) const {
+ const TOutputChannel& GetOutputChannel(ui16 index) const {
Y_VERIFY(Initialized_);
const auto it = OutputChannels_.find(index);
return it != OutputChannels_.end() ? it->second : OtherOutputChannel_;
@@ -676,7 +680,7 @@ namespace {
NMonitoring::IHistogram* PingTimeHistogram_;
- std::unordered_map<ui16, TOutputChannel> OutputChannels_;
+ THashMap<ui16, TOutputChannel> OutputChannels_;
TOutputChannel OtherOutputChannel_;
TInputChannels InputChannels_;
diff --git a/library/cpp/actors/interconnect/interconnect_tcp_input_session.cpp b/library/cpp/actors/interconnect/interconnect_tcp_input_session.cpp
index 03377a5ea6..94043c7ef1 100644
--- a/library/cpp/actors/interconnect/interconnect_tcp_input_session.cpp
+++ b/library/cpp/actors/interconnect/interconnect_tcp_input_session.cpp
@@ -131,6 +131,7 @@ namespace NActors {
}
UsageHisto.fill(0);
+ InputTrafficArray.fill(0);
XXH3_64bits_reset(&XxhashXdcState);
}
@@ -311,6 +312,17 @@ namespace NActors {
break;
}
}
+
+ for (size_t channel = 0; channel < InputTrafficArray.size(); ++channel) {
+ if (auto& value = InputTrafficArray[channel]) {
+ Metrics->AddInputChannelsIncomingTraffic(channel, std::exchange(value, 0));
+ }
+ }
+ for (auto& [channel, value] : std::exchange(InputTrafficMap, {})) {
+ if (value) {
+ Metrics->AddInputChannelsIncomingTraffic(channel, std::exchange(value, 0));
+ }
+ }
}
void TInputSessionTCP::ProcessHeader() {
@@ -466,7 +478,12 @@ namespace NActors {
ProcessEvents(context);
}
- Metrics->AddInputChannelsIncomingTraffic(channel, sizeof(part) + part.Size);
+ const ui32 traffic = sizeof(part) + part.Size;
+ if (channel < InputTrafficArray.size()) {
+ InputTrafficArray[channel] += traffic;
+ } else {
+ InputTrafficMap[channel] += traffic;
+ }
}
// mark packet as processed
diff --git a/library/cpp/actors/interconnect/interconnect_tcp_session.h b/library/cpp/actors/interconnect/interconnect_tcp_session.h
index 5722ddb627..db245847c4 100644
--- a/library/cpp/actors/interconnect/interconnect_tcp_session.h
+++ b/library/cpp/actors/interconnect/interconnect_tcp_session.h
@@ -295,6 +295,8 @@ namespace NActors {
ui64 ConfirmedByInput;
std::shared_ptr<IInterconnectMetrics> Metrics;
+ std::array<ui32, 16> InputTrafficArray;
+ THashMap<ui16, ui32> InputTrafficMap;
bool CloseInputSessionRequested = false;