Black Magic: Throttling uploads to Amazon Cloud Drive, Google Drive, and iCloud on Mac OS X El Capitan

One really frustrating thing about uploading your entire photo / video / music collection to one of the cloud services (Amazon Cloud Drive, iCloud, Google Photos, Google Music) is that it can easily saturate your Internet ISP connection, rendering it completely unusable for anyone in your household. From what I’ve seen, the services mostly tend to be greedy– they sop up all available upload bandwidth and make even simple browsing unbearable.

The best answer I’ve seen to this was hidden deep in a serverfault post about traffic shaping on Mac OS X 10.10 with pfctl and dnctl. These replace the ipfw commands in earlier versions of Mac OS X– dnctl is used for traffic shaping and pfctl is used for packed filtering. Note, this should work for both 10.10 (Yosemite) and 10.11 (El Capitan).

Without going into detail as to exactly how the following works, here’s a simple cookbook for how to do it. It’s complicated enough that suffice it to say that it’s just black magic, but the steps are very simple and it does work.

So: create two shell files. Call the first throttle_on.sh and paste the following contents into it:

#!/bin/bash

# Reset dummynet to default config
dnctl -f flush

# Compose an addendum to the default config: creates a new anchor
(cat /etc/pf.conf &&
  echo 'dummynet-anchor "my_anchor"' &&
  echo 'anchor "my_anchor"') | pfctl -q -f -

# Configure the new anchor
cat <<EOF | pfctl -q -a my_anchor -f -
no dummynet quick on lo0 all
dummynet out proto tcp from any to any port 443 pipe 1
EOF

# Create the dummynet queue. Replace 3Mbit/s with whatever you like.
dnctl pipe 1 config bw 3Mbit/s

# Activate PF
pfctl -E

Call the second throttle_off.sh and paste the following contents into it:

#!/bin/bash
dnctl pipe 1 config bw 0

To start throttling, simply issue the command:

sudo sh throttle_on.sh

and to stop throttling, simply issue

sudo sh throttle_off.sh

That’s it! You’re done. Now you can sync your photos, music, and videos to your cloud provider of choice in peace.

To see whether outbound traffic is being throttled, do a Spotlight search for “Activity Monitor”– a utility that is built in to Mac OS X. Open it and look at the Network tab. Here’s a screenshot of mine before and after running  throttle_on.sh– you can see that data dropped a ton (note, you can switch between “PACKETS” and “DATA” in Activity Monitor just by clicking that text at the bottom):

Screen Shot 2016-01-03 at 12.17.04 AM

To give credit where due– this is a minor modification of psmith’s serverfault post. The big difference is that it only shapes traffic on outbound port 443, which is the major port that appears to be used for all outbound cloud-based file synchronization. This means that most other traffic to and from the machine should be fine.

4 thoughts on “Black Magic: Throttling uploads to Amazon Cloud Drive, Google Drive, and iCloud on Mac OS X El Capitan

  1. Wanted to make sure to thank you for this bit of work — I’ve had a long weekend of a new Mac killing overall internet for the whole family. Rather surprised how much Googling it took to stumble upon the issue and even longer to find this very elegant solution to an obvious miss in the cloud syncing offerings (ability to limit bandwidth).

    Thanks for the scripts and the walk through!

    Like

Leave a comment