From cf2932098827c775063fe6c38e4283293af81e2f Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Fri, 15 Feb 2019 14:08:49 +0100 Subject: [PATCH] Allow to disable optimistic send in PushMessage() Profiling has shown that optimistic send causes measurable slowdowns when many messages are pushed, even if the sockets are non-blocking. Better to allow disabling of optimistic sending in such cases and let the network thread do the actual socket calls. --- src/net.cpp | 4 ++-- src/net.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 3c7a6ce9b..0a351af74 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -3054,7 +3054,7 @@ bool CConnman::NodeFullyConnected(const CNode* pnode) return pnode && pnode->fSuccessfullyConnected && !pnode->fDisconnect; } -void CConnman::PushMessage(CNode* pnode, CSerializedNetMsg&& msg) +void CConnman::PushMessage(CNode* pnode, CSerializedNetMsg&& msg, bool allowOptimisticSend) { size_t nMessageSize = msg.data.size(); size_t nTotalSize = nMessageSize + CMessageHeader::HEADER_SIZE; @@ -3071,7 +3071,7 @@ void CConnman::PushMessage(CNode* pnode, CSerializedNetMsg&& msg) size_t nBytesSent = 0; { LOCK(pnode->cs_vSend); - bool optimisticSend(pnode->vSendMsg.empty()); + bool optimisticSend(allowOptimisticSend && pnode->vSendMsg.empty()); //log total amount of bytes per command pnode->mapSendBytesPerMsgCmd[msg.command] += nTotalSize; diff --git a/src/net.h b/src/net.h index 9516e3478..cfd5fa932 100644 --- a/src/net.h +++ b/src/net.h @@ -201,7 +201,7 @@ public: bool IsMasternodeOrDisconnectRequested(const CService& addr); - void PushMessage(CNode* pnode, CSerializedNetMsg&& msg); + void PushMessage(CNode* pnode, CSerializedNetMsg&& msg, bool allowOptimisticSend = true); template bool ForEachNodeContinueIf(const Condition& cond, Callable&& func)