Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: Realpra on March 27, 2012, 08:05:05 AM



Title: Getting the chain faster - more than 8 outbound connections
Post by: Realpra on March 27, 2012, 08:05:05 AM
Hey,

would it be possible to edit the source code so that more than 8 outbound connections were allowed?

(See this thread: https://bitcointalk.org/index.php?topic=41726.msg507980#msg507980)

Could anyone point me to the part of the source code I need to edit?

I think this should be standard, at least until you have the block chain - this will decrease the annoyance experienced by new users.
(or people like me with multiple computers)

I don't want to trust an online wallet.

Is there any selfish thin clients out yet? Something I could easily put on new computers?


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: Revalin on March 27, 2012, 08:16:39 AM
The blockchain download speed is mostly limited by the time it takes the database to commit to the disk.  Extra connections won't help.


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: Realpra on March 27, 2012, 08:25:32 AM
The blockchain download speed is mostly limited by the time it takes the database to commit to the disk.  Extra connections won't help.

That is blatantly false, the size was what 500 mb in 2011 and now maybe its double that - I could copy that from disk to disk in a few minutes.

I have been waiting days with the client running - its crazy.

The 8 connections only is the problem.


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: JoelKatz on March 27, 2012, 08:28:22 AM
The blockchain download speed is mostly limited by the time it takes the database to commit to the disk.  Extra connections won't help.

That is blatantly false, the size was what 500 mb in 2011 and now maybe its double that - I could copy that from disk to disk in a few minutes.
Copying != committing. Committing takes about three spins of the drive per object committed.

Quote
I have been waiting days with the client running - its crazy.

The 8 connections only is the problem.
It's more likely the time it take to commit each block and transaction to disk and verify all the transactions in it. How many blocks per minute are you getting? What's your CPU load look like? What CPU do you have?


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: Revalin on March 27, 2012, 08:42:33 AM
To maintain database integrity it writes out a journal of the transaction to be peformed, syncs the disk, writes the transaction, syncs again, then deletes the journal.  This hits the disk much harder than a simple copy and it has to be done millions of times.

If you want more connections you can open the inbound port and people will connect to you.  If you want to force more connections you can edit MAX_OUTBOUND_CONNECTIONS in net.cpp.

If you actually want it to go faster, try the beta.  The database settings have been adjusted for better performance: https://bitcointalk.org/index.php?topic=74214.0

If you want to skip the download process you can download a blockchain from here:  http://eu1.bitcoincharts.com/blockchain/ (http://eu1.bitcoincharts.com/blockchain/)


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: Realpra on March 27, 2012, 08:48:32 AM
Copying != committing. Committing takes about three spins of the drive per object committed.
Even so this seems to be taking too long unless the database commits are being done in horrendous manor...

Quote
It's more likely the time it take to commit each block and transaction to disk and verify all the transactions in it. How many blocks per minute are you getting? What's your CPU load look like? What CPU do you have?
I get about 50 a minute, thats about 41 kb/s.

My load is around 5-10% average. Memory usage is a bit high right now since I doing programming in visual studio, but I have plenty to spare.

CPU is AMD64 dual core 5400+ 2.81 GHz. I run most heavy games though not at full graphics anymore.

I'm in Scandinavia so I don't know how good the node coverage is here.


I have modified the source code now, there was a constant in the top of file src/Net.cpp with MAX_OUTBOUND or something. Was 8 and I changed it to 80.

Program didn't seem to recompile though.


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: Realpra on March 27, 2012, 08:50:50 AM
If you want more connections you can open the inbound port and people will connect to you.  If you want to force more connections you can edit MAX_OUTBOUND_CONNECTIONS in net.cpp.

Yeah did that before, how do I make it recompile? (I still get 8 connections only)


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: Revalin on March 27, 2012, 08:56:14 AM
Have you read src/doc/build-msw.txt ?

It should build under mingw.  I don't know if VS works.


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: Realpra on March 27, 2012, 08:59:51 AM
Have you read src/doc/build-msw.txt ?

It should build under mingw.  I don't know if VS works.
Hmm I don't see that folder in src.

I'm not building with VS thats just homework :)

I kinda thought the bitcoin client was built each time you ran it - hence why the source files where there...


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: Revalin on March 27, 2012, 09:01:34 AM
Nope.  The source is there to encourage people to look at it.


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: theymos on March 27, 2012, 09:02:36 AM
Bitcoin only downloads the chain from one of your peers at a time, so connecting to more will only increase your chances of connecting to a fast one. You could get the same effect by "-connect"ing to a node you know is fast.

(As others have mentioned, network speed isn't usually the limiting factor, anyway.)


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: JoelKatz on March 27, 2012, 10:12:13 AM
I get about 50 a minute, thats about 41 kb/s.

My load is around 5-10% average. Memory usage is a bit high right now since I doing programming in visual studio, but I have plenty to spare.
To clarify, you are seeing CPU load of around 5-10% while you are getting blocks at about 50 a minute. Is that correct?


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: Pieter Wuille on March 27, 2012, 11:31:09 AM
As I've said before in another thread, the initial synchronisation process consists of three steps:
  • Downloading the data: limited by your and your peer's network speed
  • Maintaining the database: mostly limited by disk latency
  • Verifying the chain: limited by CPU speed

Before 0.6.0, maintaining the database almost always outweighed the other two. With 0.6.0rc5 the caching settings have been tweaked, resulting in a remarkable speedup for the database. This means that now the downloading time may indeed become significant, and it may be worth looking at improving the download process, for example downloading from several peers at once.

Increasing the number of outgoing connections will not help you get the chain faster: even when you use 0.6.0rc5, the chain is still downloaded from a single peer, and frequently still not the slowest step. In fact, increasing this number is a bad idea for the network, as peers with open incoming ports are not too abundant.


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: Realpra on March 27, 2012, 12:43:09 PM
I get about 50 a minute, thats about 41 kb/s.

My load is around 5-10% average. Memory usage is a bit high right now since I doing programming in visual studio, but I have plenty to spare.
To clarify, you are seeing CPU load of around 5-10% while you are getting blocks at about 50 a minute. Is that correct?

Yes:

50 blocks/minute
Estimated datatransfer speed 41 kb/s (with each block = 50 kb)
5-10% average CPU load
1.5 gb of 2 gb ram allocated (windows 7... seems to load a lot of things - no slowdowns though)

EDIT: My client is the one from bitcoin.org, version 0.5.2


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: wabber on March 27, 2012, 02:48:09 PM
The number of connections really doesn't matter. I've downloaded the chain at pretty much the same speed with 120 connections.
If you don't believe us forward the bitcoin port to your pc in your router. It doesn't matter if the additional connections are incoming or outgoing but it's better for the network health to have incoming connections and you wont have to recompile your client.

The limiting factor is almost always the harddisk and it has been improved in the new beta release AFAIK. Again if you don't believe us create a ramdisk and download the blockchain there. You should see a significant speed up since the RAM is much faster than your harddisk.


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: Mushoz on March 27, 2012, 03:22:20 PM
As I've said before in another thread, the initial synchronisation process consists of three steps:
  • Downloading the data: limited by your and your peer's network speed
  • Maintaining the database: mostly limited by disk latency
  • Verifying the chain: limited by CPU speed

Before 0.6.0, maintaining the database almost always outweighed the other two. With 0.6.0rc5 the caching settings have been tweaked, resulting in a remarkable speedup for the database. This means that now the downloading time may indeed become significant, and it may be worth looking at improving the download process, for example downloading from several peers at once.

Increasing the number of outgoing connections will not help you get the chain faster: even when you use 0.6.0rc5, the chain is still downloaded from a single peer, and frequently still not the slowest step. In fact, increasing this number is a bad idea for the network, as peers with open incoming ports are not too abundant.

Thank you very much for tweaking the caching settings! Tremendous improvement in synchronize speed! I too believe downloading from multiple peers at once is going to be the next logical step in speeding the initial download up. Do you happen to know how hard this would be to implement? It's not as necessary as improving the caching was, but it would most definitely help and would be very welcome :)


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: Diapolo on March 27, 2012, 04:13:28 PM
If you can, put your datadir on a SSD :D!

Dia


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: dooglus on March 27, 2012, 10:29:15 PM
I timed the initial blockchain download with v0.6.0rc4 and rc5.  rc5 is faster, but still gets very slow after a while.  Notice both charts have a flat point at around 93k blocks, and the shapes are otherwise very similar.

The graph shows blocks downloaded against time hh:mm

http://i43.tinypic.com/wmh3l1.png


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: JoelKatz on March 27, 2012, 11:33:01 PM
That's probably because the average block starts to contain transactions that require looking at more blocks that are, on average, further back. Also, the average block contains more transactions.


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: dooglus on March 28, 2012, 01:47:27 AM
I tried again, this time having ~/.bitcoin/ be a ram disk.

Code:
$ mv .bitcoin .bitcoin.real
$ mkdir .bitcoin
$ sudo mount -t tmpfs -o size=1600M tmpfs .bitcoin

I thought 1600 megabytes would be big enough, but forgot to take the database logfiles into account, and it ran out of space after about downloading 136k blocks in 26 minutes.  The shape of the curve is still the same.  The CPU very rarely was flat out during the download, and so I'm thinking the limit now is how quickly the blocks are coming over the network.  The blocks get bigger with time, so take longer to transmit.

http://i43.tinypic.com/2qj8th5.png


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: dooglus on March 28, 2012, 02:00:07 AM
Trying a 4th time with a bigger ram disk is getting speeds somewhere between rc4 and rc5 writing to disk.  So in this case it seems that the speed of the peers I'm connected to does make a big difference.  It could be the major contributing factor to the difference in slope of the lines in the above graph in fact - it just so happened that the first time I used a ram disk I connected to a very fast peer.


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: finway on March 28, 2012, 02:34:42 AM
As I've said before in another thread, the initial synchronisation process consists of three steps:
  • Downloading the data: limited by your and your peer's network speed
  • Maintaining the database: mostly limited by disk latency
  • Verifying the chain: limited by CPU speed

Before 0.6.0, maintaining the database almost always outweighed the other two. With 0.6.0rc5 the caching settings have been tweaked, resulting in a remarkable speedup for the database. This means that now the downloading time may indeed become significant, and it may be worth looking at improving the download process, for example downloading from several peers at once.

Increasing the number of outgoing connections will not help you get the chain faster: even when you use 0.6.0rc5, the chain is still downloaded from a single peer, and frequently still not the slowest step. In fact, increasing this number is a bad idea for the network, as peers with open incoming ports are not too abundant.

Yes, the networking now is the bottleneck! 


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: ohforf on March 28, 2012, 06:04:36 AM
I wonder if its possible to distribute a Blockchain File thats almost up to date, using Bittorrent Technology ?
This would help new Users to get up and running as fast as technically possible.
Of course, the BT client should be part of the Bticoin Client to make it easy to use.


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: Revalin on March 28, 2012, 06:13:47 AM
Yes, though your node still needs to either a) verify all the transactions or b) trust the md5sum of the downloaded data.  Doing A is still going to take a while; B violates the ideal of decentralization.

The existing protocol can easily stream data fast enough for A.  If the current bottleneck is the network, the client just needs to download blocks with simultaneous streams from multiple peers.


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: dooglus on March 28, 2012, 07:31:22 AM
Yes, the networking now is the bottleneck! 

I ran the test again, only this time I set the client to connect to a machine on the LAN which has the whole blockchain already.  I got the same shaped graph again, but faster again.  The bandwidth used was around 500 to 700kB/s constantly, which is about a 20th of what's available.  The CPU wasn't maxed out on either machine, and neither was the disk access.  So I've no idea what the bottleneck is now.

Once it got to block 168000 the CPU on the local computer started getting maxed out, and the download slowed considerably, because at that point it runs out of known checkpoints, and starts actually validating the signatures in every new transaction.

I also found that while downloading the blockchain, my client never flushes its database logs, and so using a ram disk as the data directory doesn't work unless the ram disk is huge.  When the qt client runs out of disk space, it sometimes crashes, and always shuts down.  I made an emergency bug report here https://github.com/bitcoin/bitcoin/issues/999

Instead of plotting blocks against time, I tried plotting blk00001.dat size against time, and got pretty much a straight line.  It's slow to get started (lots of tiny blocks) and slows down a lot once we hit block 168000 at around 32 minutes, where we run out of checkpoints and have to start checking signatures:

http://i39.tinypic.com/33xv76x.png


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: finway on March 28, 2012, 08:16:24 AM
Yes, the networking now is the bottleneck! 

I ran the test again, only this time I set the client to connect to a machine on the LAN which has the whole blockchain already.  I got the same shaped graph again, but faster again.  The bandwidth used was around 500 to 700kB/s constantly, which is about a 20th of what's available.  The CPU wasn't maxed out on either machine, and neither was the disk access.  So I've no idea what the bottleneck is now.

Once it got to block 168000 the CPU on the local computer started getting maxed out, and the download slowed considerably, because at that point it runs out of known checkpoints, and starts actually validating the signatures in every new transaction.

I also found that while downloading the blockchain, my client never flushes its database logs, and so using a ram disk as the data directory doesn't work unless the ram disk is huge.  When the qt client runs out of disk space, it sometimes crashes, and always shuts down.  I made an emergency bug report here https://github.com/bitcoin/bitcoin/issues/999

Instead of plotting blocks against time, I tried plotting blk00001.dat size against time, and got pretty much a straight line.  It's slow to get started (lots of tiny blocks) and slows down a lot once we hit block 168000 at around 32 minutes, where we run out of checkpoints and have to start checking signatures:

http://i39.tinypic.com/33xv76x.png

Seems there are still a lot space of improvement.


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: dooglus on March 28, 2012, 08:40:28 AM
Seems there are still a lot space of improvement.

Yes, but where?  If no network, CPU, or hard drive is the bottleneck, what is?


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: Diapolo on March 28, 2012, 10:47:11 AM
Seems there are still a lot space of improvement.

Yes, but where?  If no network, CPU, or hard drive is the bottleneck, what is?

Perhaps Parallelisation in the DB commits and for the Block downloads, cache tuning ... I thought of a DB "defrag" or reorganisation. Perhaps the whole space for the full block download can be reserverd at the start of a chain sync, so that it's alligned on the drive. Only thoughts, without any knowledge of the DB internals ...

Dia


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: dooglus on March 28, 2012, 03:36:34 PM
I think maybe it's an issue of network latency.  I send a request for a block, it takes a while to reach the server, the server sends the block, it takes a while to reach me.  Everything's spending lots of short amounts of time waiting for things to go through the network.

I say this because I see about half the download speed when connecting to the LAN wirelessly than I do when using an ethernet cable, even though in neither case is the network connection anywhere near saturated.  Maybe it's a question of ping time.


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: JoelKatz on March 28, 2012, 07:24:05 PM
I think maybe it's an issue of network latency.  I send a request for a block, it takes a while to reach the server, the server sends the block, it takes a while to reach me.  Everything's spending lots of short amounts of time waiting for things to go through the network.

I say this because I see about half the download speed when connecting to the LAN wirelessly than I do when using an ethernet cable, even though in neither case is the network connection anywhere near saturated.  Maybe it's a question of ping time.
I think you're probably right. I wonder if it would help for the client to request a few blocks at a time. Is its current logic really just to request a single block and then not even request the next block until it has committed the previous?


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: Pieter Wuille on March 28, 2012, 07:53:30 PM
I think maybe it's an issue of network latency.  I send a request for a block, it takes a while to reach the server, the server sends the block, it takes a while to reach me.  Everything's spending lots of short amounts of time waiting for things to go through the network.

I say this because I see about half the download speed when connecting to the LAN wirelessly than I do when using an ethernet cable, even though in neither case is the network connection anywhere near saturated.  Maybe it's a question of ping time.
I think you're probably right. I wonder if it would help for the client to request a few blocks at a time. Is its current logic really just to request a single block and then not even request the next block until it has committed the previous?

It requests blocks in bulk with a getblock. The result is a large inv announcement of up to a few hundred blocks (corresponding to at most 5 MB at a time). The client responds with a getdata for all unknown blocks, which are sent one by one using block.

The data is really requested in groups of several blocks at a time, but only downloaded and processed one by one. There are several improvements possible here still, though.


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: dooglus on March 28, 2012, 10:45:03 PM
I see it sending 500 requests for blocks at a time, and then receiving 500 blocks back, very quickly:

Code:
askfor block 00000000839a8e6886ab   0
[498 lines deleted]
askfor block 000000004ff664bfa7d2   0
sending getdata: block 00000000839a8e6886ab
[498 lines deleted]
sending getdata: block 000000004ff664bfa7d2
received block 00000000839a8e6886ab
SetBestChain: new best=00000000839a8e6886ab  height=1  work=8590065666
ProcessBlock: ACCEPTED
[1494 lines deleted]
received block 000000004ff664bfa7d2
SetBestChain: new best=000000004ff664bfa7d2  height=500  work=2151811449333
ProcessBlock: ACCEPTED


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: flatfly on March 30, 2012, 12:39:46 PM

Is there any selfish thin clients out yet? Something I could easily put on new computers?

For Windows XP & 7, I would strongly suggest to try my portable Electrum builds (latest release, 0.42). :)
See here: https://bitcointalk.org/index.php?topic=73651.0 (https://bitcointalk.org/index.php?topic=73651.0)
 


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: phr33 on March 31, 2012, 09:59:43 AM
I tried again, this time having ~/.bitcoin/ be a ram disk.

Code:
$ mv .bitcoin .bitcoin.real
$ mkdir .bitcoin
$ sudo mount -t tmpfs -o size=1600M tmpfs .bitcoin

I thought 1600 megabytes would be big enough, but forgot to take the database logfiles into account, and it ran out of space after about downloading 136k blocks in 26 minutes.  The shape of the curve is still the same.  The CPU very rarely was flat out during the download, and so I'm thinking the limit now is how quickly the blocks are coming over the network.  The blocks get bigger with time, so take longer to transmit.

http://i43.tinypic.com/2qj8th5.png

Nice graphs. Thanks!

Just out of curiosity, you don't happen to have data for a pre-v0.6.0 client to add ?


Title: Re: Getting the chain faster - more than 8 outbound connections
Post by: deepceleron on March 31, 2012, 05:58:52 PM
I tried again, this time having ~/.bitcoin/ be a ram disk.

Code:
$ mv .bitcoin .bitcoin.real
$ mkdir .bitcoin
$ sudo mount -t tmpfs -o size=1600M tmpfs .bitcoin

I thought 1600 megabytes would be big enough, but forgot to take the database logfiles into account, and it ran out of space after about downloading 136k blocks in 26 minutes.  The shape of the curve is still the same.  The CPU very rarely was flat out during the download, and so I'm thinking the limit now is how quickly the blocks are coming over the network.  The blocks get bigger with time, so take longer to transmit.
If you want to try something for giggles, set up another Bitcoin "server" machine on your local 1gig+ Ethernet network using PCIe network cards (or verifying the onboard MAC is PCIe), with the blockchain on a RAM disk on that machine too. Then instead of hitting the Internet to connect to a mystery peer, you can use the connect=192.168.0.xxx:8333 option in your bitcoin.conf to connect to only that machine (this is the best way to run multiple Bitcoins behind NAT, BTW.) Have that server be the faster machine, so you know the disk/cpu/ram latency limitations are on the machine downloading the blockchain.

You will probably be able to copy the blockchain files between the machines' ramdisks in about 20 seconds.

You will find that with the network limitation clearly removed, it still takes a few orders of magnitude longer than the network speed.

If the Bitcoin client cached the whole block index in memory, this might save a few disk read operations per blockchain transaction.