Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1QZyyr-0002Hy-09 for bitcoin-development@lists.sourceforge.net; Fri, 24 Jun 2011 05:31:01 +0000 Received-SPF: pass (sog-mx-2.v43.ch3.sourceforge.com: domain of gmail.com designates 209.85.218.47 as permitted sender) client-ip=209.85.218.47; envelope-from=witchspace81@gmail.com; helo=mail-yi0-f47.google.com; Received: from mail-yi0-f47.google.com ([209.85.218.47]) by sog-mx-2.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-MD5:128) (Exim 4.76) id 1QZyyp-0006rg-Om for bitcoin-development@lists.sourceforge.net; Fri, 24 Jun 2011 05:31:00 +0000 Received: by yib18 with SMTP id 18so1333312yib.34 for ; Thu, 23 Jun 2011 22:30:54 -0700 (PDT) MIME-Version: 1.0 Received: by 10.150.145.12 with SMTP id s12mr3114356ybd.20.1308893454256; Thu, 23 Jun 2011 22:30:54 -0700 (PDT) Received: by 10.151.50.21 with HTTP; Thu, 23 Jun 2011 22:30:54 -0700 (PDT) In-Reply-To: <20110623215143.GA3351@dax.lan.local> References: <20110623215143.GA3351@dax.lan.local> Date: Fri, 24 Jun 2011 05:30:54 +0000 Message-ID: From: John Smith To: jan@uos.de Content-Type: multipart/alternative; boundary=000e0cd47ea463c9e004a66e8137 X-Spam-Score: 1.6 (+) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain 0.0 FREEMAIL_FROM Sender email is freemail (witchspace81[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record 2.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (witchspace81[at]gmail.com) 1.0 HTML_MESSAGE BODY: HTML included in message -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 RFC_ABUSE_POST Both abuse and postmaster missing on sender domain 0.0 T_TO_NO_BRKTS_FREEMAIL T_TO_NO_BRKTS_FREEMAIL X-Headers-End: 1QZyyp-0006rg-Om Cc: Bitcoin Dev Subject: Re: [Bitcoin-development] Speeding up "getbalance " calls X-BeenThere: bitcoin-development@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Jun 2011 05:31:01 -0000 --000e0cd47ea463c9e004a66e8137 Content-Type: text/plain; charset=ISO-8859-1 Jan, On Thu, Jun 23, 2011 at 9:51 PM, wrote: > Hi there! > > Instawallet has enjoyed steady growth and I'm running into a bottleneck > now with "getbalance " 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 --000e0cd47ea463c9e004a66e8137 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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 t= ime 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 thi= s up would be to scan the wallet=20 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=20 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= =20 doesn't require determining which accounts are influenced by a new bloc= k

3) Block chain reorgs are no problem.

JS

--000e0cd47ea463c9e004a66e8137--