aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
authorlaanwj <126646+laanwj@users.noreply.github.com>2024-10-27 09:05:20 +0100
committerlaanwj <126646+laanwj@users.noreply.github.com>2024-11-04 18:46:40 +0100
commitd22a234ed270286b483aec2db1e2f716b9756231 (patch)
treebaed189cd1b8315b2598c591cd2c128327bdd1ef /src/net.cpp
parent047b5e2af1f03549d85926aa02fed0dfa00d449f (diff)
net: Use actual memory size in receive buffer accounting
Add a method CNetMessage::GetMemoryUsage and use this for accounting of the size of the process receive queue instead of the raw message size. This ensures that allocation and deserialization overhead is taken into account.
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 3e936b5f3d..f1ac681b99 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -124,6 +124,11 @@ size_t CSerializedNetMsg::GetMemoryUsage() const noexcept
return sizeof(*this) + memusage::DynamicUsage(m_type) + memusage::DynamicUsage(data);
}
+size_t CNetMessage::GetMemoryUsage() const noexcept
+{
+ return sizeof(*this) + memusage::DynamicUsage(m_type) + m_recv.GetMemoryUsage();
+}
+
void CConnman::AddAddrFetch(const std::string& strDest)
{
LOCK(m_addr_fetches_mutex);
@@ -3769,7 +3774,7 @@ void CNode::MarkReceivedMsgsForProcessing()
for (const auto& msg : vRecvMsg) {
// vRecvMsg contains only completed CNetMessage
// the single possible partially deserialized message are held by TransportDeserializer
- nSizeAdded += msg.m_raw_message_size;
+ nSizeAdded += msg.GetMemoryUsage();
}
LOCK(m_msg_process_queue_mutex);
@@ -3786,7 +3791,7 @@ std::optional<std::pair<CNetMessage, bool>> CNode::PollMessage()
std::list<CNetMessage> msgs;
// Just take one message
msgs.splice(msgs.begin(), m_msg_process_queue, m_msg_process_queue.begin());
- m_msg_process_queue_size -= msgs.front().m_raw_message_size;
+ m_msg_process_queue_size -= msgs.front().GetMemoryUsage();
fPauseRecv = m_msg_process_queue_size > m_recv_flood_size;
return std::make_pair(std::move(msgs.front()), !m_msg_process_queue.empty());