public inbox for bitcoindev@googlegroups.com
 help / color / mirror / Atom feed
From: John Smith <witchspace81@gmail•com>
To: jan@uos•de
Cc: Bitcoin Dev <bitcoin-development@lists•sourceforge.net>
Subject: Re: [Bitcoin-development] Speeding up "getbalance <account>" calls
Date: Fri, 24 Jun 2011 05:30:54 +0000	[thread overview]
Message-ID: <BANLkTi=eSgC0T_mKn660dZv1h+g-Z9TU+g@mail.gmail.com> (raw)
In-Reply-To: <20110623215143.GA3351@dax.lan.local>

[-- Attachment #1: Type: text/plain, Size: 1249 bytes --]

Jan,

On Thu, Jun 23, 2011 at 9:51 PM, <jan@uos•de> wrote:

> Hi there!
>
> Instawallet has enjoyed steady growth and I'm running into a bottleneck
> now with "getbalance <someaccounthere>" taking quite some time to
> complete. My understanding is, that this is because bitcoind runs
> through all relevant transactions each time anew to compute the balance.
> I was hoping the list could give me some pointers/ideas on how I can
> improve this.
>

I think the easiest way to speed this up would be to scan the wallet every
time a block comes in or something else changes in the block chain (or, if
you prefer, some pre-set interval of N minutes). Then go over the entire
wallet and the accumulate balances for all accounts. This could be done in
amortized linear time using a hash_map.

1) This reduces the time the API takes to return the balance for an account
to a predictable, very short time. Just the time to look up the balance in
the hash table (and return 0 on miss). The number crunching happens in the
network thread, not while you're waiting on the API.

2) Less bug-prone than "incremental caching" as you propose, and doesn't
require determining which accounts are influenced by a new block

3) Block chain reorgs are no problem.

JS

[-- Attachment #2: Type: text/html, Size: 1596 bytes --]

  reply	other threads:[~2011-06-24  5:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-23 21:51 jan
2011-06-24  5:30 ` John Smith [this message]
2011-07-03 16:29   ` Jan Vornberger
     [not found]   ` <20431_1309711872_p63GpBTM023936_48918.130.226.56.2.1309710545.squirrel@webmail.uni-osnabrueck.de>
2011-07-04 11:40     ` jan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='BANLkTi=eSgC0T_mKn660dZv1h+g-Z9TU+g@mail.gmail.com' \
    --to=witchspace81@gmail$(echo .)com \
    --cc=bitcoin-development@lists$(echo .)sourceforge.net \
    --cc=jan@uos$(echo .)de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox