New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move cs_vSend into SocketSendData and resolve RecordBytesSent lock inconsistency #19673
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -747,8 +747,9 @@ void V1TransportSerializer::prepareForTransport(CSerializedNetMsg& msg, std::vec | |||||
CVectorWriter{SER_NETWORK, INIT_PROTO_VERSION, header, 0, hdr}; | ||||||
} | ||||||
|
||||||
size_t CConnman::SocketSendData(CNode *pnode) const EXCLUSIVE_LOCKS_REQUIRED(pnode->cs_vSend) | ||||||
size_t CConnman::SocketSendData(CNode *pnode) const | ||||||
{ | ||||||
LOCK(pnode->cs_vSend); | ||||||
auto it = pnode->vSendMsg.begin(); | ||||||
size_t nSentSize = 0; | ||||||
|
||||||
|
@@ -1445,11 +1446,8 @@ void CConnman::SocketHandler() | |||||
// | ||||||
if (sendSet) | ||||||
{ | ||||||
Comment on lines
1447
to
1448
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 9d47d6d, nit:
|
||||||
LOCK(pnode->cs_vSend); | ||||||
size_t nBytes = SocketSendData(pnode); | ||||||
if (nBytes) { | ||||||
RecordBytesSent(nBytes); | ||||||
} | ||||||
const size_t bytes_sent{SocketSendData(pnode)}; | ||||||
if (bytes_sent) RecordBytesSent(bytes_sent); | ||||||
} | ||||||
|
||||||
InactivityCheck(pnode); | ||||||
|
@@ -2821,10 +2819,10 @@ void CConnman::PushMessage(CNode* pnode, CSerializedNetMsg&& msg) | |||||
pnode->m_serializer->prepareForTransport(msg, serialized_header); | ||||||
const size_t total_size{message_size + serialized_header.size()}; | ||||||
|
||||||
size_t bytes_sent{0}; | ||||||
bool optimistic_send{false}; | ||||||
{ | ||||||
LOCK(pnode->cs_vSend); | ||||||
bool optimistic_send{pnode->vSendMsg.empty()}; | ||||||
optimistic_send = pnode->vSendMsg.empty(); | ||||||
|
||||||
//log total amount of bytes per message type | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you retouch the branch, you may as well touch every line in this function:
Suggested change
|
||||||
pnode->mapSendBytesPerMsgCmd[msg.m_type] += total_size; | ||||||
|
@@ -2837,13 +2835,12 @@ void CConnman::PushMessage(CNode* pnode, CSerializedNetMsg&& msg) | |||||
if (message_size) { | ||||||
pnode->vSendMsg.push_back(std::move(msg.data)); | ||||||
} | ||||||
|
||||||
// If write queue empty, attempt "optimistic write" | ||||||
if (optimistic_send) { | ||||||
bytes_sent = SocketSendData(pnode); | ||||||
} | ||||||
} | ||||||
if (bytes_sent) RecordBytesSent(bytes_sent); | ||||||
// If write queue was empty, attempt "optimistic write" | ||||||
if (optimistic_send) { | ||||||
const size_t bytes_sent{SocketSendData(pnode)}; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this change needed? Previously we'd optimistically write only one message, now we might write more than one message when other messages have been pushed by other threads. |
||||||
if (bytes_sent) RecordBytesSent(bytes_sent); | ||||||
} | ||||||
} | ||||||
|
||||||
bool CConnman::ForNode(NodeId id, std::function<bool(CNode* pnode)> func) | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
9d47d6d
nit, clang-format suggests: