mininode: add an optimistic write and disable nagle #11323

pull theuni wants to merge 1 commits into bitcoin:master from theuni:optimistic-mininode changing 1 files +9 −1
  1. theuni commented at 5:37 PM on September 13, 2017: member

    Disclaimer: I'm not familiar with asyncore, so I'm unclear how safe this is. It works for me (tm).

    Because the poll/select loop may pause for 100msec before actually doing a send, and we have no way to force the loop awake, try sending from the calling thread if the queue is empty.

    Also, disable nagle as all sends should be either full messages or unfinished sends.

    This shaves an average of ~1 minute or so off of my accumulated runtime, and 10-15 seconds off of actual runtime.

  2. mininode: add an optimistic write and disable nagle
    Because the poll/select loop may pause for 100msec before actually doing a
    send, and we have no way to force the loop awake, try sending from the calling
    thread if the queue is empty.
    
    Also, disable nagle as all sends should be either full messages or unfinished
    sends.
    
    This shaves an average of ~1 minute or so off of my accumulated runtime, and
    10-15 seconds off of actual runtime.
    1817398b39
  3. jnewbery commented at 8:05 PM on September 13, 2017: member

    Mega concept ACK!

    Tested ACK 1817398b397afebcc857c40a16d201c84878cb89. I've run the extended test suite over this locally and it passes. It makes any test using the p2p interface much faster.

    Travis has intermittent timing issues, so we'd need to make sure this is well tested in that environment before merging.

  4. fanquake added the label Tests on Sep 13, 2017
  5. in test/functional/test_framework/mininode.py:1796 in 1817398b39
    1792 | @@ -1792,7 +1793,14 @@ def send_message(self, message, pushbuf=False):
    1793 |              tmsg += h[:4]
    1794 |          tmsg += data
    1795 |          with mininode_lock:
    1796 | -            self.sendbuf += tmsg
    1797 | +            if (len(self.sendbuf) == 0 and not pushbuf):
    


    jimpo commented at 5:16 AM on September 14, 2017:

    nit: if not self.sendbuf and not pushbuf:. From PEP8: "For sequences, (strings, lists, tuples), use the fact that empty sequences are false."


    MarcoFalke commented at 12:06 AM on September 16, 2017:

    No need to fix this "style nit". len(some_list)==0 is stricter than just casting any object/primitive type to boolean. Also it is more clear to read, imo.


    sipa commented at 12:15 AM on September 16, 2017:

    @MarcoFalke I believe that for values of the list type if len(some_list)==0 is actually identical to if not some_list, and in general I'd argue for following things like PEP8.


    jnewbery commented at 6:42 PM on September 16, 2017:

    ACK with or without this nit change. I have a slight preference for being pythonic and following PEP8. Leaving the longer form (if (len(self.sendbuf) ==0 would catch any bugs where someone set self.sendbuf to something other than a list, but I don't think that's a good justification.


    meshcollider commented at 12:05 AM on September 17, 2017:

    Either way I think the brackets should at least be removed


    MarcoFalke commented at 2:54 PM on September 17, 2017:

    @sipa, it is identical. Though, in the case that some_list is False or None or 0 or anything else that casts to False, len(some_list) will fail appropriately. I don't think it is a downside to fail in the test framework when a parameter has the wrong type.


    jnewbery commented at 1:48 PM on September 18, 2017:

    I think to be hyper pedantic, if len(self.sendbuf) == 0 is equivalent to:

    if not hasattr(self.sendbuf, '__len__'):
        raise TypeError
    else if not self.sendbuf:
        # do stuff
    

    ie, it basically has an implicit assert that the type of self.sendbuf has a length property.

    In general we don't litter the Python code with type checks, even though it's not a type safe language and someone could call into functions with the wrong typed parameters.


    promag commented at 3:33 PM on September 18, 2017:

    👍 on @jimpo and @MeshCollider suggestions.

  6. jnewbery commented at 6:55 PM on September 15, 2017: member

    Cory is being modest as usual. Let's run this over just the tests that use the p2p network thread.

    master:

    → ./test_runner.py $(grep -l NetworkThread *py | tr '\n' ' ')
    Temporary test directory at /tmp/user/1000/bitcoin_test_runner_20170915_153854
    .............
    TEST                       | STATUS    | DURATION
    
    assumevalid.py             | ✓ Passed  | 12 s
    bip65-cltv-p2p.py          | ✓ Passed  | 7 s
    bip68-112-113-p2p.py       | ✓ Passed  | 21 s
    bip9-softforks.py          | ✓ Passed  | 49 s
    bipdersig-p2p.py           | ✓ Passed  | 6 s
    example_test.py            | ✓ Passed  | 3 s
    invalidblockrequest.py     | ✓ Passed  | 4 s
    invalidtxrequest.py        | ✓ Passed  | 3 s
    maxuploadtarget.py         | ✓ Passed  | 149 s
    nulldummy.py               | ✓ Passed  | 3 s
    p2p-acceptblock.py         | ✓ Passed  | 6 s
    p2p-compactblocks.py       | ✓ Passed  | 29 s
    p2p-feefilter.py           | ✓ Passed  | 32 s
    p2p-fullblocktest.py       | ✓ Passed  | 108 s
    p2p-leaktests.py           | ✓ Passed  | 8 s
    p2p-mempool.py             | ✓ Passed  | 3 s
    p2p-segwit.py              | ✓ Passed  | 67 s
    p2p-timeouts.py            | ✓ Passed  | 65 s
    p2p-versionbits-warning.py | ✓ Passed  | 8 s
    sendheaders.py             | ✓ Passed  | 24 s
    
    ALL                        | ✓ Passed  | 607 s (accumulated) 
    Runtime: 166 s
    

    this branch:

    TEST                       | STATUS    | DURATION
    
    assumevalid.py             | ✓ Passed  | 12 s
    bip65-cltv-p2p.py          | ✓ Passed  | 7 s
    bip68-112-113-p2p.py       | ✓ Passed  | 13 s
    bip9-softforks.py          | ✓ Passed  | 52 s
    bipdersig-p2p.py           | ✓ Passed  | 6 s
    example_test.py            | ✓ Passed  | 3 s
    invalidblockrequest.py     | ✓ Passed  | 3 s
    invalidtxrequest.py        | ✓ Passed  | 3 s
    maxuploadtarget.py         | ✓ Passed  | 64 s
    nulldummy.py               | ✓ Passed  | 3 s
    p2p-acceptblock.py         | ✓ Passed  | 6 s
    p2p-compactblocks.py       | ✓ Passed  | 20 s
    p2p-feefilter.py           | ✓ Passed  | 21 s
    p2p-fullblocktest.py       | ✓ Passed  | 99 s
    p2p-leaktests.py           | ✓ Passed  | 8 s
    p2p-mempool.py             | ✓ Passed  | 3 s
    p2p-segwit.py              | ✓ Passed  | 51 s
    p2p-timeouts.py            | ✓ Passed  | 64 s
    p2p-versionbits-warning.py | ✓ Passed  | 8 s
    sendheaders.py             | ✓ Passed  | 14 s
    
    ALL                        | ✓ Passed  | 460 s (accumulated) 
    
    Runtime: 139 s
    

    That's a ~25% reduction in cumulative test time, with particularly impressive reduction in maxuploadtarget.py

  7. TheBlueMatt commented at 9:59 PM on September 15, 2017: member

    utACK 1817398b397afebcc857c40a16d201c84878cb89, wanna fix @jimpo's style nit?

  8. sipa commented at 11:21 PM on September 15, 2017: member

    utACK

  9. MarcoFalke commented at 12:07 AM on September 16, 2017: member

    Nice, Concept ACK

  10. theuni commented at 4:47 PM on September 16, 2017: member

    I'll defer on the style nit, I'm not familiar enough with python to have a preference.

  11. jonasschnelli commented at 4:08 AM on September 17, 2017: contributor

    Nice! utACK 1817398b397afebcc857c40a16d201c84878cb89

  12. gmaxwell approved
  13. gmaxwell commented at 9:22 AM on September 18, 2017: contributor

    Concept ACK

  14. MarcoFalke commented at 7:09 PM on September 18, 2017: member

    utACK 1817398b397afebcc857c40a16d201c84878cb89. Not going to hold this up on style nits, as there are other places where this is "wrong" and we don't enforce any style in the python code as of now.

  15. MarcoFalke merged this on Sep 18, 2017
  16. MarcoFalke closed this on Sep 18, 2017

  17. MarcoFalke referenced this in commit 4ce2f3d0d3 on Sep 18, 2017
  18. PastaPastaPasta referenced this in commit 57b0da0528 on Dec 22, 2019
  19. PastaPastaPasta referenced this in commit d0d14089cf on Jan 2, 2020
  20. PastaPastaPasta referenced this in commit d095fa6b6b on Jan 4, 2020
  21. PastaPastaPasta referenced this in commit dd57e97e1e on Jan 12, 2020
  22. PastaPastaPasta referenced this in commit 2961b1016a on Jan 12, 2020
  23. PastaPastaPasta referenced this in commit f7a1c12d32 on Jan 12, 2020
  24. PastaPastaPasta referenced this in commit dac2112dd0 on Jan 12, 2020
  25. ckti referenced this in commit 40a0ea7d48 on Mar 28, 2021
  26. gades referenced this in commit e01192b1ff on Jun 30, 2021
  27. 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-18 15:15 UTC

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