listunspent running slowly (and also balance and transaction building) #6573

issue AdvancedStyle openend this issue on August 19, 2015
  1. AdvancedStyle commented at 10:38 am on August 19, 2015: none

    Currently using bitcoind 0.11 headless on Debian (although had the same issue with all previously bitcoind versions).

    The wallet info: Wallet.dat size: 160MB Number of addresses: ~16,000 Unspent outputs: (varies but around: 20-40)

    Load on the server seems fairly low, and CPU usage is very low. Memory: 4GB load average: 0.39, 0.43, 0.35 Drive is SSD

    “listunspent” function is extremely slow; and by extension this seems to affect getbalance and sendmany/sendtoaddress functions.

    Here are some specific examples of this sluggishness:

    0$ time /path/to/my/bitcoin/bitcoin-cli getbalance "" 3
    1real    0m3.398s
    2user    0m0.008s
    3sys     0m0.004s
    4
    5$ time /path/to/my/bitcoin/bitcoin-cli listunspent
    6real    0m4.213s
    7user    0m0.008s
    8sys     0m0.004s
    

    The times are consistently 3-4 seconds every time

    But then some commands are much quicker:

    0$ time /path/to/my/bitcoin/bitcoin-cli getinfo
    1real    0m0.039s
    2user    0m0.004s
    3sys     0m0.004s
    
  2. jonasschnelli commented at 7:29 am on August 20, 2015: contributor
    @AdvancedStyle: balance calculation is pretty unoptimized in the current wallet. You could try compiling your own bitcoin-core with #6550 on top. In theory this should be faster (but still lacks of other optimizations). I think it’s mostly slow because of multiply calls to CMerkleTx::GetDepthInMainChain().
  3. AdvancedStyle commented at 9:15 am on August 20, 2015: none

    @jonasschnelli I compiled bitcoin-core master with the #6550 patch applied, but it makes no difference to the load times of listunspent or getbalance CLI calls.

    listunspent just took 6 seconds to run.

  4. sipa commented at 2:35 pm on August 20, 2015: member
    The running time of those RPCs depends on the number of transactions in the wallet, not the number of unspent outputs. We should add an index for that…
  5. AdvancedStyle commented at 2:47 pm on August 20, 2015: none

    @sipa the work-around we have right now is to externally cache the listunspent in our own software (after sending or receiving anything) and then build the transactions manually and sign via bitcoin-core (which cuts total time to send down to milliseconds). It would be very useful if some kind of caching or indexing of the unspend was built into bitcoin-core though.

    Sorry I do not have C++ skills so cannot create any suggested patch.

  6. laanwj added the label Wallet on Aug 24, 2015
  7. laanwj added the label Resource usage on Feb 16, 2016
  8. MarcoFalke commented at 6:11 pm on May 8, 2020: member
    Is this still an issue with a recent version of Bitcoin Core? If yes, what are the steps to reproduce?
  9. MarcoFalke closed this on May 8, 2020

  10. DrahtBot locked this on Feb 15, 2022

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: 2024-10-05 01:12 UTC

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