P2P: improve RX/TX flow control #2017

pull jgarzik wants to merge 2 commits into bitcoin:master from jgarzik:tx-full changing 2 files +40 −28
  1. jgarzik commented at 11:27 PM on November 15, 2012: contributor
    • "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.

  2. P2P, cosmetic: break out buffer send(2) code into separate function fca5b98528
  3. 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.
    4e4e6d1fec
  4. in src/net.cpp:None in 4e4e6d1fec
     789 |                  {
     790 |                      TRY_LOCK(pnode->cs_vSend, lockSend);
     791 | -                    if (lockSend && !pnode->vSend.empty())
     792 | -                        FD_SET(pnode->hSocket, &fdsetSend);
     793 | +                    if (lockSend) {
     794 | +                        // do not read, if draining write queue
    


    laanwj commented at 12:30 PM on November 17, 2012:

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


    jgarzik commented at 6:17 PM on November 17, 2012:

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


    mikehearn commented at 11:07 AM on November 21, 2012:

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

  5. BitcoinPullTester commented at 6:42 PM on January 24, 2013: none

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

  6. sipa commented at 2:12 PM on February 24, 2013: member

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

  7. jgarzik commented at 4:29 PM on March 24, 2013: contributor

    Superceded by #2409

  8. jgarzik closed this on Mar 24, 2013

  9. jgarzik deleted the branch on Aug 24, 2014
  10. KolbyML referenced this in commit 0fe1242ee6 on Dec 5, 2020
  11. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-19 12:16 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me