Bitcoin Forum
May 03, 2024, 09:28:32 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1] 2 »  All
  Print  
Author Topic: Bitcoind SLOOOOW  (Read 1713 times)
Kazu (OP)
Full Member
***
Offline Offline

Activity: 168
Merit: 100


View Profile
July 22, 2013, 06:00:40 AM
 #1

My Bitcoind is really slow. I'm trying to to start a service using it a bit (by a bit, I mean really not that much) and for some reason its using up 40%+ of my CPU all the time. I suspect it is slowing down my page loads as they are really quite slow. Has anybody else ran into this problem, and if so, do they have any workarounds/alternate software (I still need account management & all other bitcoind features but mining)/other fixes?

Thanks tons!

CoinLenders - Bitcoin Bank Script / Demo
1v.io/kazu - 15ccW7m6RxDFWEKc3P1NdwWpX1N1pU7gZ8
TalkImg was created especially for hosting images on bitcointalk.org: try it next time you want to post an image
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714771712
Hero Member
*
Offline Offline

Posts: 1714771712

View Profile Personal Message (Offline)

Ignore
1714771712
Reply with quote  #2

1714771712
Report to moderator
1714771712
Hero Member
*
Offline Offline

Posts: 1714771712

View Profile Personal Message (Offline)

Ignore
1714771712
Reply with quote  #2

1714771712
Report to moderator
1714771712
Hero Member
*
Offline Offline

Posts: 1714771712

View Profile Personal Message (Offline)

Ignore
1714771712
Reply with quote  #2

1714771712
Report to moderator
Kazu (OP)
Full Member
***
Offline Offline

Activity: 168
Merit: 100


View Profile
July 22, 2013, 06:35:07 AM
 #2

I have no problem with having the first starting time being slow - I can wait. The part that is annoying is that functions that must be repeated on nearly every pageload, like getbalance, seem to be absurdly slow. Is there any way of speeding those up?

CoinLenders - Bitcoin Bank Script / Demo
1v.io/kazu - 15ccW7m6RxDFWEKc3P1NdwWpX1N1pU7gZ8
btcsql
Sr. Member
****
Offline Offline

Activity: 292
Merit: 250


View Profile
July 22, 2013, 07:28:11 AM
 #3

The solution is simple: don't run Bitcoind on the same server as your webserver. It's much faster to have it dedicated, and simply connect/issue commands/grab data via API format.
niko
Hero Member
*****
Offline Offline

Activity: 756
Merit: 501


There is more to Bitcoin than bitcoins.


View Profile
July 22, 2013, 07:38:30 AM
 #4

The solution is simple: don't run Bitcoind on the same server as your webserver. It's much faster to have it dedicated, and simply connect/issue commands/grab data via API format.

This should provide for more security, too. Sorry, I know these are not answers to your question, it's a workaround. However, it's a good workaround.

They're there, in their room.
Your mining rig is on fire, yet you're very calm.
Belkaar
Full Member
***
Offline Offline

Activity: 177
Merit: 100


View Profile WWW
July 22, 2013, 08:34:49 AM
 #5

You should also consider getting the needed info via a cron job an saving it to a database that the frontend uses. This decouples page loading times from API-processing.

bitcoinCodes.com: Get XBox live, PSN and WoW game time codes fast and anonymously
Android RPC client: Bitcoiner
Bitmessage: BM-GtcxVju35PGuD6es9vrF1SXtCVxScbjB
Kazu (OP)
Full Member
***
Offline Offline

Activity: 168
Merit: 100


View Profile
July 22, 2013, 05:40:30 PM
 #6

I sort of need the pageload connected with the API because the balance can't be on a delay for what I'm doing. Thanks for the idea, though.

I'm considering running bitcoind on a dedicated server, however that seems like a pretty big waste of resources. Is there any way of viewing what Bitcoind is doing all this time, like viewing some sort of output? I just want to see why its taking so incredibly long.

CoinLenders - Bitcoin Bank Script / Demo
1v.io/kazu - 15ccW7m6RxDFWEKc3P1NdwWpX1N1pU7gZ8
Kazu (OP)
Full Member
***
Offline Offline

Activity: 168
Merit: 100


View Profile
July 22, 2013, 07:02:22 PM
 #7

So I tried using a  microtime() difference to calculate the time it takes to execute a bitcoind getbalance on an account with a couple hundred transactions. I have tried two methds:

php system() to call bitcoind
Bitcoind JSON rpc connection

And...

EXEC: 222.71010398865
EXEC: 12.618118047714
EXEC: 3.6932117938995
EXEC: 1.6202571392059
EXEC: 1.7495849132538
EXEC: 3.5270199775696
EXEC: 3.0422019958496
EXEC: 2.6602010726929
EXEC: 1.5538840293884
EXEC: 0.58772110939026
EXEC: 0.97496891021729
EXEC: 0.99640703201294
EXEC: 2.7791039943695
EXEC: 1.8489720821381
EXEC: 0.82930707931519
EXEC: 0.25357699394226
EXEC: 0.62351679801941
EXEC: 1.3590130805969
EXEC: 4.4388699531555
EXEC: 0.70736193656921
EXEC: 1.473837852478
EXEC: 0.8196861743927
EXEC: 0.49087500572205
EXEC: 0.31272411346436
EXEC: 0.3066029548645
EXEC: 0.93807220458984
EXEC: 2.9650371074677
EXEC: 4.9273610115051
EXEC: 2.4882531166077
EXEC: 1.2758350372314
EXEC: 0.81832599639893
EXEC: 1.2282900810242

JSON: 0.70425081253052
JSON: 0.31246995925903
JSON: 6.2438280582428
JSON: 0.75746512413025
JSON: 4.1969089508057
JSON: 0.15843486785889
JSON: 1.0560338497162
JSON: 4.0856080055237
JSON: 0.34556603431702
JSON: 9.2187669277191

I've heard of inefficient processing but this is just ridiculous. I've got to be doing something wrong, there is no way this can be normal.

Here is my PHP:

JSON:
require_once 'jsonRPCClient.php';
$bitcoin = new jsonRPCClient('http://bitcoinrpc:reallylongrpcpassword@127.0.0.1:8332/');
echo $bitcoin->getbalance($_REQUEST['user'], 4);

EXEC:
echo system('sudo -H -u ubuntu bitcoind getbalance ' . $_REQUEST['user'] . '');

CoinLenders - Bitcoin Bank Script / Demo
1v.io/kazu - 15ccW7m6RxDFWEKc3P1NdwWpX1N1pU7gZ8
gmaxwell
Moderator
Legendary
*
expert
Offline Offline

Activity: 4158
Merit: 8382



View Profile WWW
July 22, 2013, 07:08:33 PM
 #8

what the heck are you doing that for?  It's a JSON rpc specifically so you can talk to it via JSON!   Using bitcoind via system gives you huge forking overhead for a big library heavy binary (not to mention the easy of getting yourself exploited of system()...).
Kazu (OP)
Full Member
***
Offline Offline

Activity: 168
Merit: 100


View Profile
July 22, 2013, 07:10:02 PM
 #9

I tried both, just to see if my json thing got messed up. Look at the JSON api, its still screwed up. It was just for testing purposes.

CoinLenders - Bitcoin Bank Script / Demo
1v.io/kazu - 15ccW7m6RxDFWEKc3P1NdwWpX1N1pU7gZ8
btc4ever
Sr. Member
****
Offline Offline

Activity: 321
Merit: 250


View Profile
July 22, 2013, 07:20:59 PM
 #10

I have noticed slowness and high CPU usage also.

1) bitcoind CPU usage is sometimes as high as 99% over a 3 second period (top) when bitcoind is fully caught up with blockchain and just sitting there with no local transactions or JSON requests.  This is on testnet.  It is consistently high enough usage that stopping bitcoind means the difference between choppy and smooth video playback on my older laptop.

2) sometimes jsonrpc requests block for quite a while.  many seconds.  For this reason (and others), I do almost all bitcoind calls in an offline process that syncs to my DB.  Still the blocking concerns me, especially for readonly calls like getinfo() or getbalance().  



Psst!!  Wanna make bitcoin unstoppable? Why the Only Real Way to Buy Bitcoins Is on the Streets. Avoid banks and centralized exchanges.   Buy/Sell coins locally.  Meet other bitcoiners and develop your network.   Try localbitcoins.com or find or start a buttonwood / satoshi square in your area.  Pass it on!
btc4ever
Sr. Member
****
Offline Offline

Activity: 321
Merit: 250


View Profile
July 22, 2013, 07:23:13 PM
 #11

Look at the JSON times.   Does 9 seconds seem right to you?

Or do you think that system() accounts for 222 seconds of overhead?  12 seconds?    3 seconds?

miss the point much?

what the heck are you doing that for?  It's a JSON rpc specifically so you can talk to it via JSON!   Using bitcoind via system gives you huge forking overhead for a big library heavy binary (not to mention the easy of getting yourself exploited of system()...).


Psst!!  Wanna make bitcoin unstoppable? Why the Only Real Way to Buy Bitcoins Is on the Streets. Avoid banks and centralized exchanges.   Buy/Sell coins locally.  Meet other bitcoiners and develop your network.   Try localbitcoins.com or find or start a buttonwood / satoshi square in your area.  Pass it on!
Kazu (OP)
Full Member
***
Offline Offline

Activity: 168
Merit: 100


View Profile
July 22, 2013, 07:31:41 PM
 #12

It seems dubious and boring to have to do all the transactions in a DB. That is very sad. Are you sure there is no other way of doing this? At that point I may as well store them in a $_SESSION variable or something (just for balance & transaction history etc... read only things that are displayed to the user and that there would be no reason to manipulate), at least then you only have to check for users that are logged in.

CoinLenders - Bitcoin Bank Script / Demo
1v.io/kazu - 15ccW7m6RxDFWEKc3P1NdwWpX1N1pU7gZ8
Kazu (OP)
Full Member
***
Offline Offline

Activity: 168
Merit: 100


View Profile
July 22, 2013, 08:09:43 PM
 #13

A bit more information: Bitcoind is nowhere near as slow when doing it through shell? WTF?

Script started on Mon 22 Jul 2013 08:06:52 PM UTC
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.376s
user   0m0.004s
sys   0m0.012s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.226s
user   0m0.000s
sys   0m0.012s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.198s
user   0m0.016s
sys   0m0.004s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.041s
user   0m0.004s
sys   0m0.008s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.073s
user   0m0.000s
sys   0m0.012s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.042s
user   0m0.000s
sys   0m0.012s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.041s
user   0m0.008s
sys   0m0.004s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.045s
user   0m0.000s
sys   0m0.012s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.039s
user   0m0.004s
sys   0m0.008s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.038s
user   0m0.008s
sys   0m0.004s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.038s
user   0m0.004s
sys   0m0.008s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.037s
user   0m0.000s
sys   0m0.012s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.038s
user   0m0.004s
sys   0m0.008s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.037s
user   0m0.004s
sys   0m0.012s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.037s
user   0m0.008s
sys   0m0.004s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.038s
user   0m0.004s
sys   0m0.012s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.050s
user   0m0.008s
sys   0m0.004s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.038s
user   0m0.008s
sys   0m0.008s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.049s
user   0m0.000s
sys   0m0.012s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.038s
user   0m0.004s
sys   0m0.012s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.061s
user   0m0.000s
sys   0m0.012s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
^[[A-101115.00029185

real   0m0.600s
user   0m0.004s
sys   0m0.008s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.060s
user   0m0.008s
sys   0m0.004s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.037s
user   0m0.000s
sys   0m0.012s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.037s
user   0m0.008s
sys   0m0.004s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.044s
user   0m0.012s
sys   0m0.000s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.039s
user   0m0.008s
sys   0m0.008s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.037s
user   0m0.004s
sys   0m0.008s
]0;ubuntu: ~ubuntu:~$
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.036s
user   0m0.008s
sys   0m0.008s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.037s
user   0m0.000s
sys   0m0.012s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.047s
user   0m0.004s
sys   0m0.012s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.037s
user   0m0.000s
sys   0m0.012s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.036s
user   0m0.004s
sys   0m0.008s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.037s
user   0m0.008s
sys   0m0.004s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.037s
user   0m0.004s
sys   0m0.008s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.040s
user   0m0.000s
sys   0m0.012s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.038s
user   0m0.008s
sys   0m0.004s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.037s
user   0m0.008s
sys   0m0.004s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.037s
user   0m0.008s
sys   0m0.004s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.037s
user   0m0.008s
sys   0m0.004s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.036s
user   0m0.004s
sys   0m0.008s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.037s
user   0m0.008s
sys   0m0.008s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.036s
user   0m0.004s
sys   0m0.008s
]0;ubuntu: ~ubuntu:~$ time bitcoind getbalance ""
-101115.00029185

real   0m0.037s
user   0m0.008s
sys   0m0.004s
]0;ubuntu: ~ubuntu:~$ exit
exit

Script done on Mon 22 Jul 2013 08:07:48 PM UTC

Any logical reason why this is like this???

Maybe it would be way faster to just use a shell script to write it somewhere, then read it from there whenever I need it?

CoinLenders - Bitcoin Bank Script / Demo
1v.io/kazu - 15ccW7m6RxDFWEKc3P1NdwWpX1N1pU7gZ8
btc4ever
Sr. Member
****
Offline Offline

Activity: 321
Merit: 250


View Profile
July 22, 2013, 08:31:59 PM
 #14

as I understand it, "bitcoind getbalance" is just calling the daemon with jsonrpc.  It shouldn't be significantly different from your php script calling it with jsonrpc.

I have noticed that sometimes it is slower responding when downloading the blockchain.  Were you fully up-to-date in both instances?

What happens if you test from your php script and bitcoind getbalance back-to-back?   The idea being to test them both at nearly the same moment in time, in case something on the network was slowing bitcoind previously.


Psst!!  Wanna make bitcoin unstoppable? Why the Only Real Way to Buy Bitcoins Is on the Streets. Avoid banks and centralized exchanges.   Buy/Sell coins locally.  Meet other bitcoiners and develop your network.   Try localbitcoins.com or find or start a buttonwood / satoshi square in your area.  Pass it on!
jgarzik
Legendary
*
qt
Offline Offline

Activity: 1596
Merit: 1091


View Profile
July 22, 2013, 08:38:51 PM
 #15

A bit more information: Bitcoind is nowhere near as slow when doing it through shell? WTF?

Not sure I understand what this means.

as I understand it, "bitcoind getbalance" is just calling the daemon with jsonrpc.  It shouldn't be significantly different from your php script calling it with jsonrpc.

That is correct.  "bitcoind getbalance" executes a new copy of bitcoind, which connects via TCP to an existing bitcoind, sends and receives JSON-RPC, then disconnects and exits.  Not much different than using PHP or cURL to make JSON-RPC calls.


Jeff Garzik, Bloq CEO, former bitcoin core dev team; opinions are my own.
Visit bloq.com / metronome.io
Donations / tip jar: 1BrufViLKnSWtuWGkryPsKsxonV2NQ7Tcj
Kazu (OP)
Full Member
***
Offline Offline

Activity: 168
Merit: 100


View Profile
July 22, 2013, 08:46:02 PM
 #16

Quote
Not sure I understand what this means
When I ssh into the same server, go bitcoind getbalance "", I get the balance many times faster than when I go to that same server, make a php file, include the JSON library, and go all $bitcoin->getbalance("");

Now look at this:

$time = microtime(true);
$bitcoin = new jsonRPCClient('http://bitcoinrpc:hugepassword@127.0.0.1:8332/');
$write = microtime(true) - $time;
file_put_contents('log.txt', '<br>inittime: ' . $write, FILE_APPEND);

And guess what the output is? (There are lines of code before and after this, but those shouldn't matter... right?)

inittime: 1.7881393432617E-5
inittime: 1.6927719116211E-5
inittime: 1.9073486328125E-5
inittime: 1.8119812011719E-5
inittime: 2.0980834960938E-5
inittime: 2.1934509277344E-5
inittime: 2.0027160644531E-5
inittime: 1.8119812011719E-5
inittime: 1.5974044799805E-5
inittime: 4.0054321289062E-5
inittime: 1.6927719116211E-5
inittime: 1.1920928955078E-5
inittime: 1.8119812011719E-5
inittime: 1.7166137695312E-5
inittime: 1.8119812011719E-5
inittime: 3.9100646972656E-5

So?? This means that the actual act of getbalance() is taking a long time or something?

CoinLenders - Bitcoin Bank Script / Demo
1v.io/kazu - 15ccW7m6RxDFWEKc3P1NdwWpX1N1pU7gZ8
gmaxwell
Moderator
Legendary
*
expert
Offline Offline

Activity: 4158
Merit: 8382



View Profile WWW
July 23, 2013, 01:11:23 AM
 #17

Are you actually checking the result?  Perhaps you're getting an authentication error or a failure connecting, your example has 127.0.0.1 which should work, though if your real test doesn't have that: bitcoind listens only on localhost for rpc by default.
jgarzik
Legendary
*
qt
Offline Offline

Activity: 1596
Merit: 1091


View Profile
July 23, 2013, 01:34:15 AM
 #18

So?? This means that the actual act of getbalance() is taking a long time or something?

They are doing the same thing under the hood: making a TCP connection to bitcoind, sending/receiving JSON-RPC data.


Jeff Garzik, Bloq CEO, former bitcoin core dev team; opinions are my own.
Visit bloq.com / metronome.io
Donations / tip jar: 1BrufViLKnSWtuWGkryPsKsxonV2NQ7Tcj
Kazu (OP)
Full Member
***
Offline Offline

Activity: 168
Merit: 100


View Profile
July 23, 2013, 05:30:23 AM
 #19

Okay I think I found the issue, and it also explains why I havent' been having this problem till now.

Transaction history. Through the process of debugging my site, I completed several thousand transactions (no, I didnt sit there clicking all day, its a micropayment gaming website so there are tons of automatic move() commands going on when I set my debugger going). Apparently, in order to get the balance of any individual account, it has to manually calculate out ALL of the transactions. You'd think they'd save each account's balance in some place and keep a separate transaction history but nooooo, they had to do it the random and inexplicably difficult way.

Is there any easy way of getting around this? As far as I can see I must either:

A) Constantly flush the transaction history occasionally, then re-load each account with what they had with a single move() command to each account, which is not only annoying but also means that people can't view their transaction history after a while.
B) Every once and a while re-load each account on a single address associated with that account, then flush transaction history.
OR
C) Not use Bitcoind's accounts at all, keep a single wallet and then have a database and store things in there including the transaction. Which is majorly re-inventing the wheel.

Is there any simpler way you can think of to do this? This seems like it basically renders bitcoind's account management ultra-inefficient and sorta is a major buzzkill with regard to my release schedule.

CoinLenders - Bitcoin Bank Script / Demo
1v.io/kazu - 15ccW7m6RxDFWEKc3P1NdwWpX1N1pU7gZ8
grue
Legendary
*
Offline Offline

Activity: 2058
Merit: 1431



View Profile
July 23, 2013, 10:36:39 PM
 #20

use walletnotify instead of polling for transactions.

It is pitch black. You are likely to be eaten by a grue.

Adblock for annoying signature ads | Enhanced Merit UI
Pages: [1] 2 »  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!