Skip to content

Commit cf29320

Browse files
committed
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.
1 parent bedfc26 commit cf29320

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/net.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -3054,7 +3054,7 @@ bool CConnman::NodeFullyConnected(const CNode* pnode)
30543054
return pnode && pnode->fSuccessfullyConnected && !pnode->fDisconnect;
30553055
}
30563056

3057-
void CConnman::PushMessage(CNode* pnode, CSerializedNetMsg&& msg)
3057+
void CConnman::PushMessage(CNode* pnode, CSerializedNetMsg&& msg, bool allowOptimisticSend)
30583058
{
30593059
size_t nMessageSize = msg.data.size();
30603060
size_t nTotalSize = nMessageSize + CMessageHeader::HEADER_SIZE;
@@ -3071,7 +3071,7 @@ void CConnman::PushMessage(CNode* pnode, CSerializedNetMsg&& msg)
30713071
size_t nBytesSent = 0;
30723072
{
30733073
LOCK(pnode->cs_vSend);
3074-
bool optimisticSend(pnode->vSendMsg.empty());
3074+
bool optimisticSend(allowOptimisticSend && pnode->vSendMsg.empty());
30753075

30763076
//log total amount of bytes per command
30773077
pnode->mapSendBytesPerMsgCmd[msg.command] += nTotalSize;

src/net.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class CConnman
201201

202202
bool IsMasternodeOrDisconnectRequested(const CService& addr);
203203

204-
void PushMessage(CNode* pnode, CSerializedNetMsg&& msg);
204+
void PushMessage(CNode* pnode, CSerializedNetMsg&& msg, bool allowOptimisticSend = true);
205205

206206
template<typename Condition, typename Callable>
207207
bool ForEachNodeContinueIf(const Condition& cond, Callable&& func)

0 commit comments

Comments
 (0)