CreateNewBlock performance improvements #2677

pull sipa wants to merge 1 commits into bitcoin:master from sipa:fastcreate changing 2 files +10 −20
  1. sipa commented at 1:54 AM on May 21, 2013: member

    Remove some unnecessary copying and coins view cache layers in CreateNewBlock.

    This results in a >10x speedup for GBT for me, with a large mempool (poolsz >5000).

  2. CreateNewBlock performance improvements 2ec349bc42
  3. sipa commented at 2:18 AM on May 21, 2013: member

    test conditions: on my VPS, a bitcoind patched to ignore the dust filtering and free relay limiting, and sending a "mempool" to every peer at connect time, waited until poolsz >5000, then measure getblocktemplate RPC latency. Result: 10-20s without this patch, 0.5-0.7s with this patch.

    EDIT: up to 1.0-1.5s after running for several hours (poolsz still ~5000).

  4. BitcoinPullTester commented at 2:30 AM on May 21, 2013: none

    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/2ec349bc420d7f4541bf91acf8b830377a1421f3 for binaries and test log. This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/ Contact BlueMatt on freenode if something looks broken.

  5. gyver commented at 9:26 PM on May 21, 2013: none

    I'm not familiar enough with the code and the template structure to know what is possible so please bear with my uneducated suggestion.

    Would it make sense to have part of the template being computed asynchronously? Have a thread wake up regularly and build a base structure with a snapshot of the tx available. When a call to getblocktemplate or other RPC functions scaling in o(nb_tx) or worse is done, use the precomputed structure instead of the available tx. When a new block is known update the structure right away and/or swap with a temporary "quick to compute/0 tx" one until the thread can catch up and build one with available tx. I see params of getblocktemplate that obviously won't allow using this optimization (passing the transactions for the most obvious) but my lack of knowledge of the actual template format and build process makes me wonder what other params could prevent this kind of optimization to be useful. At least it seems to me that with no params the optimization should work and allow for o(1) scaling for getblocktemplate. In the end my suggestion only makes sense if most pools could benefit from it and aren't forced to use params that prevent it from being useful.

  6. gmaxwell commented at 9:29 PM on May 21, 2013: contributor

    @gyver Thats what miner software should and (some) does do. .. but at some point you need to compute the data... and it's good if it's not a slow and expensive operation.

  7. jgarzik commented at 9:42 PM on May 21, 2013: contributor

    ACK

  8. gyver commented at 9:43 PM on May 21, 2013: none

    @gmaxwell of course I agree speeding up the actual computation is desirable.

    I was wondering if it wouldn't make sense to implement this async technique in bitcoind itself. For example I suspect (again: uninformed guess) that slow calls to getmininginfo and getblocktemplate use the same access pattern to an internal tx structure and could benefit from the same optimization (at least they became slow on my node when the number of tx started to grow). At some point when multiple tools all implement the same algorithm on top of another tool the question of integrating this algorithm in the common tool becomes valid (the answer isn't always obvious though). It could become more obvious when the heavy client only makes sense for pool owners/miners (and most end-users have migrated to lightweight clients).

    It's just an idea to test the waters (mainly to avoid wasting time with it if the template build process intrinsically can't benefit from this approach), it's far from a feature request.

    I'm more and more interested by the node's source code and how I could play with it but I just scraped the surface...

  9. gyver commented at 10:11 PM on May 21, 2013: none

    @gmaxwell still thinking about your suggestion and focusing on how miner software can optimize their latency when a new block is accepted by the local node. The miner doesn't want to use an old cached template to avoid wasting work but can't simply call getblocktemplate naively if it wants a fast reply (event after a new block there can be and often is a lot of transactions to include in a template). It can receive a notification from the node (there are already interfaces for that). I assume that to minimize latency it can call getblocktemplate with an emplty tx list to get a fast reply and immediately call it again without specifying the list to include txs as soon as possible. As many pools have closed source software I'm not sure if they really implement this kind of behaviour. Latency issues may be solved by simply publishing recommendations for miner software instead of modifying bitcoind itself. As p2pool is probably the most likely to benefit from this, I'll link this post in the p2pool bitcointalk.org thread and continue there to avoid deviating even more from the subject here.

  10. gmaxwell commented at 10:18 PM on May 21, 2013: contributor

    @gyver Eloipool is free software an implements the optimizations you appear to be describing there. (precomputed empty templates and such).

  11. gyver commented at 10:26 PM on May 21, 2013: none

    @gmaxwell thanks for the pointer. Was already in my large bag of source code to read but moved near the top of the pile :)

  12. gavinandresen referenced this in commit 6b99cfae3c on May 22, 2013
  13. gavinandresen merged this on May 22, 2013
  14. gavinandresen closed this on May 22, 2013

  15. laudney referenced this in commit 64e0ff7688 on Mar 19, 2014
  16. DrahtBot locked this on Sep 8, 2021

Milestone
v0.8.2


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 09:15 UTC

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