Some Bits: Nelson's log

7 posts in March 2014

Automatic software updates considered harmful

Another day, another bandwidth management problem. Being on a slow 1Mbit link really makes you aware of how much crap Apple products downloads, with no user control.

Today’s scenario: trying to watch LoL tournament games on Twitch. That’s an 800kbps stream, so anything else running on my 1000kbps link is instantly notable. Like, say, my laptop. The one I’d like to use for very light web browsing while watching. Only the moment I open it up a bunch of Apple shit decides now’s the time it has to download updates. All invisibly, with no user feedback or control. Right now it’s softwareupdated downloading who knows what or how much, I’m guessing it’s the 120mb command line developer tools. Yesterday storeagent decided it had to download something, I still don’t know what, but that one started downloading with the lid closed and the machine nominally asleep.

Background downloads that happen quietly so your machine is ready to go are great. Background downloads that run in the middle of the day and consume all bandwidth are bad. If only they had some network saturation detection, or if there were a way to specify low priority network usage, or something. But this is TCP/IP and there’s not, so Apple’s a bit stuck. Still it’s awful and annoying.

Oh yeah, you can’t even kill storeagent. Ignores SIGINT. I finally did a SIGKILL. It seems to have recovered intelligently from that.

 

Heatmap of where I’ve been

Moved by Bobby Sudekum’s map and this Ask Metafilter question I drew a quick heatmap of all the places I’ve been in the past two years. Primary data source is OpenPaths, 6348 location points. Results in the gallery.

Doing this right is hard. OpenPaths samples non-uniformly in time, more points when you’re moving. So the honest thing would be to calculate dwell time from the timestamps. Also the heatmap fakery being done in TileMill is not really accurate, more of an alpha blending hack, but it does look nice. The result is not particularly scale-invariant, you need different settings for different zoom levels and different amounts of source data.

Here’s the steps I followed. Full Carto CSS below. These notes below aren’t a full cookbook, but if you sort of know TileMill already it may get you going.

  1. Get the right version of TileMill. This proved challenging; you need a dev build to get the special colorize-alpha image filter, but the absolute latest dev builds are broken. Version TileMill-v0.10.1-243-gafc00a ended up working for me.
  2. Download my data from OpenPaths in CSV format.
  3. Start up a TileMill project and import the OpenPaths data. Happily it detects the CSV and lat/long parameters with no trouble. Style it with simple dots and you have a map!
  4. Add some thematic layers for orientation; I used the Natural Earth data for country boundaries, state boundaries, and the small roads file (which is sadly US only). Put the locations dots as the top layer, then I put roads, admin1, and countries below.
  5. Switch to transparent markers. Grab the Mapnik fuzzy dot and drop it in my project directory, use that as a marker-file.
  6. Switch to the fancy heatmap. The magic there is mostly the image-filters:colorize-alpha. Also want to multiply markers, and allow overlap.
  7. Tweak the heatmap. Unfortunately there’s no scale-invariant way to do this, so I settled on making it look good at zoom=8. Both marker-width and marker-opacity are things you can tweak to make it look good depending on your density of location samples, zoom level, etc.

Here’s the full Carto CSS.

Map {
  background-color: #b8dee6;
}

#countries {
  line-color: black;
  line-width: 2;
  line-join: round;
  polygon-fill: #fff;
}

#10madmin1statesprovi {
  line-width: 0.5;
  line-color: #444;
  line-join: round;
}

#locations {
  marker-file:url(marker.png);
  marker-allow-overlap: true;
  comp-op: multiply;
  marker-width: 20px;
  marker-opacity: 0.5;
  image-filters:colorize-alpha(hsl(240,80%,50%), hsl(180,80%,50%), hsl(120,80%,50%), hsl(60,80%,50%), hsl(0,80%,50%));
}

#10mroads {
  line-width:0.5;
  line-color:#bbb;
  line-opacity: 0.8;
}

Traffic shaping vs. burst speeds

I’m a fan of the QoS controls built into Tomato firmware and other fancy routers. Unfortunately it doesn’t work on my slow Grass Valley link. The problem is the QoS algorithm they use needs to know the max link speed as a parameter; basically it throttles traffic that approaches 90% of that link speed when things get congested.

Except, I don’t have a single link speed. My link is 2500kbps for about 60 seconds, then is 1000kbps. If I set the QoS limit to 1000kbps then the router never allows any single stream to use more than that, basically wasting my burst. So I set it to 2500kbps, but then that screws up the traffic shaping when things get busy.

There’s other QoS algorithms out there that should be possible. I dimly recall back in 1999 when I studied this last that RED didn’t require knowing the link speed, just auto-detected congestion. That may be harder to pull off on a house router since it’s sitting behind the congested link, you really want to shape the link upstream of the bottleneck.

 

what’s using my bandwidth, take 20

Perpetual problem; network is slow, some process is using all the bandwidth, what is it?

On a Mac, the new short answer may be “use Mavericks”. The Activity Monitor includes a Network view and while it’s not perfect, it helps.

On an older Mac or other Unix machine, here’s one way:

Run iftop. It’s a top-like program that shows individual network sockets. Press “p” to turn on port number display. Press “t” to simplify to one line per host. The three columns of numbers on the left are download rates in kilobits/second, averages over 2/10/40 seconds.

Note the port number of the top flow. Then run lsof (as root) and search through the output for that port number. It contains the program name and process ID.

Using this I managed to find it was ocspd taking all my CPU. That program downloads fresh certificate revocation lists. Amazing how much data it had to grab.

iftop and lsof use existing kernel services, doesn’t require installing a kernel module or anything. Should be possible to write a patch to iftop that does the lsof-side of things to show the process ID and name. Or else a separate tool.

Rubbernet is a fine graphical tool to manage and shape Mac bandwidth in this fashion. But it’s €30. Also it requires a kernel module, which feels like dangerous overkill.

 

whois protocol notes

Whois is one of the magical old Internet protocols, going way back to 1982 in the time before TCP was even the standard. It still mostly works. I was curious how it’s scaled, in particular where the database state is held. The Wikipedia article is useful.

Long story short, each top level domain like .com has a whois server. Some of those servers maintain “thick” databases where they have a full copy of the database. Ie, the .ORG whois server has the full .ORG whois database itself. Others are “thin” and delegate queries to the domain registrar of record; for somebits.com, say, the .COM whois server looks up the name and sees TUCOWS is the registrar so sends the request for somebits info off to TUCOWS. It’s all basically a pretty centralized system and seems to work. RWhois is the proposal to replace the centralized system with a hierarchical one.

There’s about 100 million .com domains. Assuming a generous 4 kilobytes of data per record, that’s 400 GB of data. That’s a fair amount of data but not a whole lot, although there sure must be a lot of queries. Whois updates propagate fast, often in seconds, although TUCOWS has a 15 minute delay.

You can see this delegation when making a whois query (testing with the Mac command line client). Asking for somebits.com, the first query goes to a Verisign server who gives back a partial response, including a Whois Server at TUCOWS, the registrar for the domain. Then the whois client makes a second request to TUCOWS. Asking for somebits.org gives you the reply straight from a server at afilias.info, who I guess is running the whois for .org, a thick implementation.

How do you find the whois server for a particular TLD? There’s no standard, but IANA runs a database you can query via whois. Ie: whois -h whois.iana.org com. I don’t know if the whois tools use that online. My Mac client seems to know directly where to send whois queries for weird domains like .museum, .xxx, and .io. (Although it has a bunch of hilarious options to manually choose whois servers, like Russian and Caribbean authorities.)

The most important thing a whois server tells you is the DNS authority for the domain, where to go to look up IP addresses. In retrospect it’s odd that query is not part of the DNS system itself, is instead delegated to this other protocol. Then again the typical DNS client never does the whois requests themselves, they just ask a DNS resolver somewhere. And DNS has a huge amount of caching.

I have a lot of respect for the core old Internet protocols. Many have been in service for 30 years and still work great, despite a zillion-fold increase in Internet size.

ASUS RT-AC66U bug

My fancy new ASUS RT-AC66U has pretty good firmware; it seems based on the Tomato core, even the QoS. And unfortunately the built in DNS server, the one it advertises in DHCP. It has some bug that occasionally causes it to fail to respond to any requests for awhile, I think blocking on some other connection. I just had a failure where I couldn’t resolve names for about 45 seconds and it went away the moment an active HTTP download of a 60 megabyte file completed. The network was up the whole time (downloading the file), as was the router web interface, but DNS requests failed.

I should probably stop using the router DNS. Or else install Merlin’s patches.

Steam’s lousy throttling

Steam does a lousy job of bandwidth throttling. I had it set to limit downloads to 512kbytes/sec. (Why? Because despite using a fancy router with QoS control, QoS still sucks in 2014. Can’t stream video while downloading, derp). Here’s the graph of throughput from my router. X axis scale is 1 pixel = 2 seconds, max throughput is about 900 kbytes/sec. I turned off throttling halfway through.

Screen Shot 2014-03-02 at 8.35.12 AM

 

So looking at the first half of that graph, what Steam is actually doing is running at full capacity for about 10 seconds, then backing off to the requested 512 kbytes/sec for about 10 seconds, then averaging it out by going slow for 10 seconds. Back and forth. That’s just awesome.

I sure wish QoS worked on the modern Internet. The academic research I’m familiar with was all worried about solving the hard problem of fair congestion management through the whole Internet. I don’t care about that; I just want to manage QoS on one link, from my router to my ISP over the slow pipe.