Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: MrJoshua on August 06, 2011, 02:04:05 AM



Title: Multiple bitcoind on one machine
Post by: MrJoshua on August 06, 2011, 02:04:05 AM
Is is possible to run multiple bitcoind instances on a single machine?  

I'm trying to develop some web services.  One of those services needs the ability to process unique wallet files / private keys for each user.  Currently this is impractical because the amount of time it takes to flush and relaunch bitcoind with rescan to load unique wallets.  Even though this takes time, it could be somewhat manageable if I can run a bitcoind for every active user session.  I can use multiple servers, but I'd like to be able run more then one bitcoind per server instance to make more effective use of each server's resources.

I suspect dynamic wallet switching directly in bitcoind is still a bit far off right?

Thanks,
j


Title: Re: Multiple bitcoind on one machine
Post by: 2112 on August 06, 2011, 02:19:01 AM
Is is possible to run multiple bitcoind instances on a single machine?  
Yes. Each one has to be under a different account and use "-rpcport" (documented) and "-port" (undocumented) or "-nolisten". The overhead can be stupendous though.


Title: Re: Multiple bitcoind on one machine
Post by: Furyan on August 06, 2011, 10:12:38 AM
Is is possible to run multiple bitcoind instances on a single machine?  
Yes. Each one has to be under a different account and use "-rpcport" (documented) and "-port" (undocumented) or "-nolisten". The overhead can be stupendous though.

Instead of "-port" you can use -connectnode and have it connect to an already-running bitcoin to do the peer communication.

And you don't have to run them on a different account, you can just use the -datadir flag to point the second instance to a different folder. It will rebuild its own block chain, or you can copy over the existing one to that data dir.  They'll have separate wallets though.

See Gavin Andresen's instructions here:

https://bitcointalk.org/index.php?topic=589.0


Title: Re: Multiple bitcoind on one machine
Post by: payb.tc on August 06, 2011, 01:07:24 PM
The overhead can be stupendous though.

You mean as in ram usage or are you talking about something else?

i was able to get 2 running successfully for a while on a test server.

I wonder what the record is for the most amount of bitcoind instances running together successfully... anyone running 3 or more?


Title: Re: Multiple bitcoind on one machine
Post by: Furyan on August 06, 2011, 01:26:40 PM
The overhead can be stupendous though.

You mean as in ram usage or are you talking about something else?

i was able to get 2 running successfully for a while on a test server.

I wonder what the record is for the most amount of bitcoind instances running together successfully... anyone running 3 or more?


I heard of someone running 8. I never did hear how that worked out :)


Title: Re: Multiple bitcoind on one machine
Post by: 2112 on August 06, 2011, 01:59:08 PM
You mean as in ram usage or are you talking about something else?
RAM doesn't seem to be a problem. The worst are: disk access queues and disk space usage. Then there's a CPU use spikes and network traffic spikes during operation when separate daemons duplicate their work. Last but not least is the outgoing network connectivity which gets close to launching a non-distributed DoS on the servers when your multi-bitcoind machine restarts after maintenance.

Overall it isn't pretty and it would be hard to maintain and troubleshoot.


Title: Re: Multiple bitcoind on one machine
Post by: payb.tc on August 06, 2011, 02:06:05 PM
so i guess the solution is to modify bitcoind so that it can perform the functions of multiple bitcoind instances?

run several wallets at the same time, separately, all from the one binary and one set of ports.


Title: Re: Multiple bitcoind on one machine
Post by: 2112 on August 06, 2011, 02:45:33 PM
so i guess the solution is to modify bitcoind so that it can perform the functions of multiple bitcoind instances?
run several wallets at the same time, separately, all from the one binary and one set of ports.
I think I responded to you in the PHP thread. Your only hope is that libbitcoin development group delivers something useable. The core development team is actively working against this goal. What you have here is the essence of using obfuscated C++ code for the purpose of guerrilla warfare amongst the competing software development teams. Satoshi is/was a grand-master of it.


Title: Re: Multiple bitcoind on one machine
Post by: payb.tc on August 06, 2011, 03:05:09 PM
so i guess the solution is to modify bitcoind so that it can perform the functions of multiple bitcoind instances?
run several wallets at the same time, separately, all from the one binary and one set of ports.
I think I responded to you in the PHP thread. Your only hope is that libbitcoin development group delivers something useable. The core development team is actively working against this goal. What you have here is the essence of using obfuscated C++ code for the purpose of guerrilla warfare amongst the competing software development teams. Satoshi is/was a grand-master of it.

which goal? what's wrong with one instance of bitcoind managing multiple wallets?


Title: Re: Multiple bitcoind on one machine
Post by: markm on August 06, 2011, 04:41:18 PM
The overhead can be stupendous though.

You mean as in ram usage or are you talking about something else?

i was able to get 2 running successfully for a while on a test server.

I wonder what the record is for the most amount of bitcoind instances running together successfully... anyone running 3 or more?


Even my quite old machines are not having any problems running multiple *coind instances all at once and all on the same user account. (bitcoind  botcoind  britcoind  cdnbitcoind  czbitcoind  devcoind  gmcbitcoind  grfbitcoind  groupcoind  multicoind  namecoind  unbitcoind ...)

-MarkM-




Title: Re: Multiple bitcoind on one machine
Post by: Furyan on August 06, 2011, 08:46:16 PM
so i guess the solution is to modify bitcoind so that it can perform the functions of multiple bitcoind instances?
run several wallets at the same time, separately, all from the one binary and one set of ports.
I think I responded to you in the PHP thread. Your only hope is that libbitcoin development group delivers something useable. The core development team is actively working against this goal. What you have here is the essence of using obfuscated C++ code for the purpose of guerrilla warfare amongst the competing software development teams. Satoshi is/was a grand-master of it.

which goal? what's wrong with one instance of bitcoind managing multiple wallets?


I, too, am curious what motivated that comment.

I would think if the core devs were going to work against a goal, it would be mining pools.  Mining pools were NEVER what Satoshi had in mind and de-democratize the mining process.  They also concentrate computing power in attackable entities, and if a large pool goes down even for a few hours it takes a huge chunk of the available computing power with it (unless a large portion of the miners have fallback settings, but it doesn't appear to be widely used).

The GetWork function was intended for testing, but is the single method by which mining pools are even possible.  If they wanted to work against a goal - mining pools - they'd need only to disable that single function.

They haven't done so.  I tend to think the project is far beyond working against specific goals at this point and only working toward very focused ones.


Title: Re: Multiple bitcoind on one machine
Post by: 2112 on August 06, 2011, 10:22:26 PM
which goal?
The goal of having multiple compatible implementations of the same protocol. The longer they have an effective control over the whole network in the hands of about 6 people the more time they have to monetize their investment of time into this project.

It is quite amazing to watch an open source project that had successfully prevented any competing groups from developing a compatible implementation despite the source being in the open. Subtle changes in protocol, using corner cases of exception handling to prevent running the Linux client on the majority of commercial Linux distributions, reintroducing exact bugs fixed in earlier patches, etc. The whole arsenal of tricks of hardcore purveyors of job safety.

I have to say that watching this project is a great learning experience for me.


Title: Re: Multiple bitcoind on one machine
Post by: payb.tc on August 07, 2011, 12:41:27 AM
which goal?
The goal of having multiple compatible implementations of the same protocol.

okay so you said all that because i used the phrase 'modify bitcoind'. i didn't mean fork the project, i meant it would be good if that functionality became part of the default client.


Title: Re: Multiple bitcoind on one machine
Post by: 2112 on August 07, 2011, 01:39:30 AM
They haven't done so.  I tend to think the project is far beyond working against specific goals at this point and only working toward very focused ones.
Well, I probably cannot change your thinking. In my opinion the great part of the effective obfuscation is to appear constructive. I'll give you an example: Bitcoin protocol is a train-wreck of endianness and alignment problems. Yet while it was being developed some "core team" members were using MacOS X {Tiger,Leopard,Snow Leopard} which makes it almost trivial to locate and fix those problems.

Consider the code:
Code:
#include <stdio.h>
union {
        char b[4];
        int w;
} t = { 0x11, 0x22, 0x33, 0x44 };
int main()
{
        return printf("%08x,%i\n",t.w,(int)sizeof(void*));
}
and its compilation and invocation:
Code:
$ gcc -arch ppc -arch i386 -arch x86_64 bo.c
$ ./a.out
44332211,8
$ arch -i386 ./a.out
44332211,4
$ arch -ppc ./a.out
11223344,4
Now go search the history of this forum for discussion about the byte-order issues. Watch the mental gymnastics expended (especially by Jeff Garzik) to quash any work or discussion about this goal.

I'll bet this will be very instructive to you, even if you disagree with me overall.


Title: Re: Multiple bitcoind on one machine
Post by: error on August 07, 2011, 02:41:32 AM
They haven't done so.  I tend to think the project is far beyond working against specific goals at this point and only working toward very focused ones.
Well, I probably cannot change your thinking. In my opinion the great part of the effective obfuscation is to appear constructive. I'll give you an example: Bitcoin protocol is a train-wreck of endianness and alignment problems. Yet while it was being developed some "core team" members were using MacOS X {Tiger,Leopard,Snow Leopard} which makes it almost trivial to locate and fix those problems.

Consider the code:
Code:
#include <stdio.h>
union {
        char b[4];
        int w;
} t = { 0x11, 0x22, 0x33, 0x44 };
int main()
{
        return printf("%08x,%i\n",t.w,(int)sizeof(void*));
}
and its compilation and invocation:
Code:
$ gcc -arch ppc -arch i386 -arch x86_64 bo.c
$ ./a.out
44332211,8
$ arch -i386 ./a.out
44332211,4
$ arch -ppc ./a.out
11223344,4
Now go search the history of this forum for discussion about the byte-order issues. Watch the mental gymnastics expended (especially by Jeff Garzik) to quash any work or discussion about this goal.

I'll bet this will be very instructive to you, even if you disagree with me overall.

Completely agree in every respect. The endianness problem is Bitcoin's biggest design flaw, and IMO warrants bumping the protocol version. Of course it's going to be a lot more work to clean this up than it would have been to do it right the first time, so it's going to be very hard to find anyone who wants to do it.


Title: Re: Multiple bitcoind on one machine
Post by: Steve on August 07, 2011, 12:51:11 PM
The overhead can be stupendous though.

You mean as in ram usage or are you talking about something else?

i was able to get 2 running successfully for a while on a test server.

I wonder what the record is for the most amount of bitcoind instances running together successfully... anyone running 3 or more?


I've run as many as 6 on a machine...two that are on a private local testnet...one that is on a prive testnet between several machines, one on the public test net and another couple on the real net.  Works fine, albeit the machine can get a little sluggish.  I do typically run 2 to 4 (2 on a private local testnet, one no a shared private testnet, and one on the real net).


Title: mining pools
Post by: doldgigger on August 07, 2011, 07:20:08 PM
I would think if the core devs were going to work against a goal, it would be mining pools.  Mining pools were NEVER what Satoshi had in mind and de-democratize the mining process.  They also concentrate computing power in attackable entities, and if a large pool goes down even for a few hours it takes a huge chunk of the available computing power with it (unless a large portion of the miners have fallback settings, but it doesn't appear to be widely used).
This is not the responsibility of the core devs, it is the responsibility of every bitcoin user. However, they are probably a natural effect of bitcoin's evolution - in other areas of P2P computing, you will also notice that evolution towards efficiency often leads to some kind of hub nodes. For bitcoin, I could imagine even more areas beyond mining where this might happen in the future.

But mining pools are not necessarily dangerous if we regulate them well. I have already started discussing about revitalizing the transaction fee market in presence of mining pools some time ago (see http://bitcointalk.org/index.php?topic=28309.0). I'd be glad to discuss further possibilities.


Title: Re: Multiple bitcoind on one machine
Post by: c_k on August 08, 2011, 10:02:39 AM
OP: what is wrong with the existing functionality of Accounts in wallets?

https://en.bitcoin.it/wiki/Accounts_explained


Title: Re: Multiple bitcoind on one machine
Post by: payb.tc on August 08, 2011, 10:15:30 AM
OP: what is wrong with the existing functionality of Accounts in wallets?

https://en.bitcoin.it/wiki/Accounts_explained

how about a lack of sub-accounts and sub-sub-accounts?

just one reason of many, i'd say.


Title: Re: Multiple bitcoind on one machine
Post by: c_k on August 08, 2011, 10:34:20 AM
just one reason of many, i'd say.

Do share the other reasons as they come to you.

I don't see how what you've said so far is a problem.

Don't take me the wrong way, I am genuinely interested in where the existing functionality fails to suffice :)


Title: Re: Multiple bitcoind on one machine
Post by: wumpus on August 08, 2011, 10:42:32 AM
The core development team is actively working against this goal
That's simply not true. The recent WalletDB refactoring made it possible to run multiple wallets in one process with only a few changes.


Title: Re: Multiple bitcoind on one machine
Post by: payb.tc on August 08, 2011, 01:01:08 PM
just one reason of many, i'd say.

Do share the other reasons as they come to you.

I don't see how what you've said so far is a problem.

Don't take me the wrong way, I am genuinely interested in where the existing functionality fails to suffice :)

okay well here's one more reason i can think of... let's say there are TWO types of ways a site can use bitcoin:

1) the kind of site where new temporary addresses are constantly being generated for incoming payments, eg. btcflip.com
2) the kind of site where there is only ever 1 permanent address generated per customer (I think tradehill might be starting to do this).

for a site in category 1, it's wallet.dat is going to be constantly growing day by day, hour by hour, and will probably need to be replaced with a fresh one periodically, so that the site isn't running off a 100mb wallet file. These are just 'temporary' payment addresses, 99% of which might not have ever even had payments sent to them.

the site in category 2 might have 1000 customers, but it's wallet.dat could have as little as 1000 addresses and not need periodically replacing. Indeed for this kind of site replacing the wallet would be a bad thing, as each customer has been given his 'personal' address for that site.

now you tell me, what would be the best way to run these two types of sites on the same server?


Title: Re: Multiple bitcoind on one machine
Post by: payb.tc on August 08, 2011, 01:07:57 PM
I don't see how what you've said so far is a problem.

no sub-accounts?

the documentation basically recommends that accounts should be used to organise customers, say alice and bob.

so under normal circumstances your wallet file might have:

[alice]=>0.5
[bob]=>1.3

but let's say you have a second website which has customers alice and jane, but the catch is, it's NOT THE SAME ALICE :)

[alice]=>5000
[jane]=>20

so the only way to get around this is to add prefices to account names to designate what site they're customers of:

[a-alice]=>0.5
[a-bob]=>1.3
[b-alice]=>5000
[b-jane]=>20

would be much better organised with sub accounts:

[site a]=>1.8,
(
   [alice]=>0.5
   [bob]=>1.3
)
[site b]=>5020,
(
   [alice]=>5000
   [jane]=>20
)


actually, even if it was the same alice, you wouldn't want her to log in to site a or b and see her balance as 5000.5  ...those balances should remain separate.


Title: Re: Multiple bitcoind on one machine
Post by: jfreak53 on August 17, 2011, 03:35:55 PM
We run 12 to 15 per server depending on the load of each.  Not so much for Ram, each one takes about 150MB of ram total per user, but we have it limited also.  But more for the IO, it really uses a lot and more just seems to bog down the server we have noticed.

We used the same basic technique in the second reply to this thread.


Title: Re: Multiple bitcoind on one machine
Post by: 2112 on August 17, 2011, 06:05:15 PM
But more for the IO, it really uses a lot and more just seems to bog down the server we have noticed.
If you know how to recompile you can try disabling memory mapping in the calls to db->open. The flag is DB_NOMMAP. It could slightly improve the disk cache hit ratio and it will greatly improve TLB hit ratio, especially on the virtualized servers.


Title: Re: Multiple bitcoind on one machine
Post by: jfreak53 on August 18, 2011, 02:05:02 AM
We will give that a try since we compile our own anyways, I will shoot that over and see if it helps some, thanks.

Since we're on the subject, any idea where to look to lower memory consumption off the top of your head?


Title: Re: Multiple bitcoind on one machine
Post by: 2112 on August 18, 2011, 03:21:10 AM
Since we're on the subject, any idea where to look to lower memory consumption off the top of your head?
For the managed hosting environment (multiple bitcoind each with its own wallet, but reasonably good security) I would work as follows:

1) create a separate DBENV for the blkindex.dat
2) convert stdio.h access to blkNNNN.dat into DB access to additional named databases inside blkindex.dat, which already supports multiple databases, take care that block insertion is idempotent
3) convert the new environment from (1) from direct calls into RPC calls
4) run berkeley_db_svc RPC server serving a single copy of blockchain inside blkindex.dat for all the client bitcoin-daemons, each of which is only managing its own wallet in a separate (original) DBENV

This modification will give you best bang for your development buck in the reasonably secure managed hosting environment.


Title: Re: Multiple bitcoind on one machine
Post by: jfreak53 on August 20, 2011, 03:02:31 PM
Very nice idea 2112, I'll have our Devs look into it for integration.


Title: Re: Multiple bitcoind on one machine
Post by: tolazy on December 18, 2015, 09:46:38 PM
The overhead can be stupendous though.

You mean as in ram usage or are you talking about something else?

i was able to get 2 running successfully for a while on a test server.

I wonder what the record is for the most amount of bitcoind instances running together successfully... anyone running 3 or more?


how did you manage to do that?
can you give me the startup command line/config pls.


Title: Re: Multiple bitcoind on one machine
Post by: 2112 on December 19, 2015, 12:13:02 AM
how did you manage to do that?
can you give me the startup command line/config pls.
This thread is only of historical relevance. It pertains to the old version that used BerkelyDB for everything. Current version uses a mixture of BerkeleyDB and LevelDB, so it doesn't apply.