How can I limit bandwidth usage in Bitcoin-qt client?

18

1

I've just finished the intial blockchain download/verify in my BitcoinQt client (17 hours..) and I now see that BitcoinQt is happily eating all of my upstream bandwidth. (About 110kByte/sec on my ADSL line.)

I'm going to be applying bandwidth limits to the app using Waterroof, which should probably work --

But shouldn't there be a built-in method for BitcoinQt to be more polite about its bandwidth consumption?

9

If your goal is just to get a stable Bitcoin node running, and not to contribute to the network, you can add listen=0 to your bitcoin.conf file. This generally (though not always) keeps your upload bandwidth in check.

If you want to contribute to the Bitcoin network without using up too much of your own bandwidth, however, there are ways of limiting your upload speed for Bitcoin Core (Bitcoin-qt) only. Instructions depend on your OS, so what follows is a breakdown on what to do with each OS.

IMPORTANT NOTE: If you limit the bandwidth of Bitcoin Core far below your actual upload speed, it can actually harm the Bitcoin network instead of helping it. To be a responsible maintainer of the Bitcoin network, you should test your upload speed and then set your outgoing bandwidth limit to be as close to your actual speed as possible (e.g. 90%). This guide is intended solely for people whose internet connections go unresponsive due to Bitcoin Core completely saturating their upload bandwidth.

The following instructions are abridged from this article I wrote recently: https://www.maxlaumeister.com/blog/how-to-limit-bandwidth-of-bitcoin-core-on-windows-mac-os-and-linux/

Limiting Bitcoin Bandwidth on Windows

1. Start Bitcoin Core if it isn’t already running.

2. Run NetBalancer.

3. Find “bitcoin-qt.exe” in the list of running applications in the NetBalancer dialog and double-click it to change its bandwidth rules.

4. Under “Upload Priority” choose “Limited”, set the maximum amount of bandwidth for Bitcoin Core to use, and confirm.

You’re done! NetBalancer will now sit in the background and make sure Bitcoin Core doesn’t use more bandwidth than you want it to.

Limiting Bandwidth on Mac OS X

OS X 10.10 Yosemite and later

For OS X 10.10 Yosemite and later, there is no easy way to limit the bandwidth of a particular application, but the overall system bandwidth can be limited as follows:

2. Search for “Hardware IO Tools for Xcode” and download the latest stable (non-beta) version.

3. Open the .dmg and double-click “Network Link Conditioner.prefpane” to install the prefpane. From now on, you can enable/disable Network Link Conditioner from System Preferences.

4. From the Network Link Conditioner pane in System Preferences, click “Manage Profiles”, then click the “+” button to add a new profile.

5. Edit the profile and add your desired maximum upload speed.

6. Save your edit, exit the profile manager, choose your new profile, and flip the big switch to enable the limiter.

Mac OS will place an icon in your notification tray so you remember that it’s on. Unlike the Windows/Linux solutions, this will limit the bandwidth for your entire system, so be sure to turn it off you’re not running Bitcoin Core.

OS X 10.9 Mavericks and earlier

For OS X 10.9 Mavericks you can use IceFloor to configure bandwidth rules. For 10.8 Mountain Lion and earlier, use Waterroof. Alternatively, if you want a simple way to control the overall system bandwidth limit instead of just Bitcoin Core, follow the instructions above for OS X 10.10 Yosemite and later.

Limiting Bandwidth on Linux

1. Make sure you have tc installed by typing tc at the command line. If you get “command not found”, install tc using your favorite package manager. If you're on a Debian-based distribution, the easiest way to install tc is by using apt-get:

sudo apt-get update

sudo apt-get install iproute2

2. Download the tc.sh script from the official Bitcoin Core repository using wget:

wget https://raw.githubusercontent.com/bitcoin/bitcoin/master/contrib/qos/tc.sh

3. Open the script in a text editor. Find the line that says IF="eth0" and change eth0 to reflect the network interface that your internet connection runs through. To get a list of your computer's network interfaces, use ifconfig on the command line. My computer is connected wirelessly through wlan1, so the IF line of my tc.sh looks like this:

IF="wlan1"

4. LINKCEIL should reflect the limit of the network interface, and most likely does not need to be changed.

LINKCEIL="1gbit"

5. Change LIMIT to be the maximum bandwidth you want Bitcoin Core to use (I chose 1mbit). If you don’t have any other Bitcoin Core nodes in your local network, you can delete the line that says LOCALNET. This line is there to make a bandwidth exception for port 8333 communications within your local network (i.e. not out to the internet).

LIMIT="1mbit"

Leave the rest of the commands in tc.sh alone unless you know what you're doing. The final top section of my tc.sh ended up looking like this:

#network interface on which to limit traffic
IF="wlan1"

#limit of the network interface in question

#limit outbound Bitcoin protocol traffic to this rate
LIMIT="1mbit"

6. Exit your editor and make the script executable with the following command:

chmod +x ./tc.sh

7. Run the script as superuser:

sudo ./tc.sh

Your Bitcoin Core bandwidth will be throttled until you reboot your computer!

Optionally, you can set the script to run every time you start your computer. Instructions for running scripts on boot will vary depending on your Linux distribution. On Ubuntu, one of the ways to run a script on boot is by adding the script to your /etc/rc.local file.

Conclusion

Hopefully this post was helpful in showing you how to limit the bandwidth of Bitcoin Core! For the full version, including images and extra information, check out the original article here.

I'm on a debian distribution and the tc package is not found. :( Halp. – Spencer Ruport – 2016-01-16T17:39:44.407

1@SpencerRuport Actually I did more research and I would try apt-get install iproute2 instead. I'm going to update my answer. – Maximillian Laumeister – 2016-01-16T19:08:06.537

@MaximillianLaumeister - Awesome thanks :) – Spencer Ruport – 2016-01-16T20:36:26.970

@MaximillianLaumeister - So I got it to work. Aptitude told me that iproute2 was already installed but the script was giving me an error: RTNETLINK answers: No such file or directory. I installed iproute and it worked. (Or at least, I didn't receive any errors.) – Spencer Ruport – 2016-01-16T20:42:23.380

@SpencerRuport Oh thank you! I don't have an extra debian box to test on, so it's much appreciated that you're helping me correct my answer. iproute it is :) – Maximillian Laumeister – 2016-01-16T20:44:31.000

@MaximillianLaumeister - No problem. Thanks for following up. Do you have any recommendations on how I could determine if the script is working? – Spencer Ruport – 2016-01-18T18:24:03.203

@SpencerRuport I might try a command-line tool called nethogs. More info in this serverfault question.

– Maximillian Laumeister – 2016-01-18T18:26:24.867

1

Does limiting the bandwidth when being a full node actually hurt the network more than not being a full node at all? Question asked here: https://bitcoin.stackexchange.com/questions/61629/as-a-full-node-does-limiting-bitcoind-bandwidth-hurt-the-network/61685#61685

– schulwitz – 2017-11-01T20:08:55.613

You were right before. It's iproute2, not iproute on debian. The RTNETLINK error appears the first time you run the script but not on subsequent times. /sbin/tc is in the iproute2 package and not in the iproute package. The iproute package is actually empty, and simply depends on iproute2. – Chris Moore – 2018-10-16T22:24:43.363

@ChrisMoore Thank you for that data point, I have updated the answer accordingly. – Maximillian Laumeister – 2018-10-17T00:55:26.380

1

listen=0


to your bitcoin.conf (which is in {User}\AppData\Roaming\Bitcoin).

This stops other nodes connecting to you to download the blockchain, hence stopping the large upstream bandwidth consumption

2Not really, since you still connect to a number of nodes in the network they might also ask for blocks and transactions that you saw, but they did not yet. You do however limit the number of connections. It's a really rough cap though. – cdecker – 2013-07-08T08:00:32.487

But what if you want to run a full node? – Geremia – 2015-11-26T18:04:58.590

1

If your bitcoin client is running on a dedicated linux machine you might want to try wondershaper. It allows you to limit the bandwith of your network adapter. For instance

sudo wondershaper eth0 1024 56


sudo wondershaper -c eth0

Is there a way to restrict wondershaper to a specific process (PID)? – Geremia – 2015-07-16T22:09:23.507