P2P: improve RX/TX flow control #2017

Closed
wants to merge 2 commits into
from

Projects

None yet

5 participants

@jgarzik
Member
jgarzik commented Nov 15, 2012
  • "optimistic write": Push each message to kernel socket buffer immediately
  • If there is write data at select time, that implies send() blocked during optimistic write. Drain write queue, before receiving any more messages.

This avoids needlessly queueing received data, if the remote peer is not themselves receiving data.

Result: write buffer (and thus memory usage) is kept small, DoS potential is slightly lower, and TCP flow control signalling is properly utilized.

The kernel will queue data into the socket buffer, then signal the remote peer to stop sending data, until we resume reading again.

Jeff Garzik added some commits Nov 15, 2012
Jeff Garzik P2P, cosmetic: break out buffer send(2) code into separate function fca5b98
Jeff Garzik P2P: improve RX/TX flow control
1) "optimistic write": Push each message to kernel socket buffer immediately.

2) If there is write data at select time, that implies send() blocked
   during optimistic write.  Drain write queue, before receiving
   any more messages.

This avoids needlessly queueing received data, if the remote peer
is not themselves receiving data.

Result: write buffer (and thus memory usage) is kept small, DoS
potential is slightly lower, and TCP flow control signalling is
properly utilized.

The kernel will queue data into the socket buffer, then signal the
remote peer to stop sending data, until we resume reading again.
4e4e6d1
@laanwj laanwj commented on the diff Nov 17, 2012
src/net.cpp
{
TRY_LOCK(pnode->cs_vSend, lockSend);
- if (lockSend && !pnode->vSend.empty())
- FD_SET(pnode->hSocket, &fdsetSend);
+ if (lockSend) {
+ // do not read, if draining write queue
laanwj
laanwj Nov 17, 2012 Owner

I don't understand this part. Why make fdsetRecv depend on the state of the write queue?

jgarzik
jgarzik Nov 17, 2012 Member

@laanwj That is explained in the commit message / pull request message.

mikehearn
mikehearn Nov 21, 2012 Contributor

But future readers of the code won't see your commit message. They need comments to understand what's going on.

Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/4e4e6d1feca92c346389d4221d022db8f8cd3e78 for binaries and test log.

Owner
sipa commented Feb 24, 2013

@jgarzik @gavinandresen I'd like to see this in 0.8.1.

@sipa sipa referenced this pull request Mar 24, 2013
Merged

Network optimalizations #2409

Member
jgarzik commented Mar 24, 2013

Superceded by #2409

@jgarzik jgarzik closed this Mar 24, 2013
@jgarzik jgarzik deleted the jgarzik:tx-full branch Aug 24, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment