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.
This commit is contained in:
Alexander Block 2019-02-15 14:08:49 +01:00
parent bedfc262e2
commit cf29320988
2 changed files with 3 additions and 3 deletions

View File

@ -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;

View File

@ -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<typename Condition, typename Callable>
bool ForEachNodeContinueIf(const Condition& cond, Callable&& func)