Some Bits: Nelson's log

3 posts in November 2012

msgpack for topojson

Mike Bostock has published topojson, a clever variant of GeoJSON that more efficiently encodes toplogies. For a map of US counties, for instance, the GeoJSON approach is a bunch of LineStrings or Polygons that define each state boundary. There’s a lot of redundant line segments; TopoJSON eliminates those by encoding the line segments separately and then referencing them to define each state boundary. Also TopoJSON uses a relative integer representation instead of absolute floating point geocoordinates, greatly reducing size.

But is it as small as possible? There’s a lot of pairs of small integers like [-1,0],[1,-20],[-14,10],[-27,-9]; roughly 8 bytes for what could fit in 2. I took a quick crack at using msgpack to encode the JSON for us-counties more efficiently, this is what I learned:

 Source 668312
 Gzip 175895
 Msgpack 344208
 Msgpack gzip 166761

Msgpack is about half the size of JSON, but after gzip that difference goes away. That’s what I found last time I looked at msgpack, too.

Some custom encoding could make the TopoJSON format smaller still, but I’m not convinced that after gzip it will make much difference. Probably not worth the complexity. The one thing I’d consider is recoding the list of pairs of integers  just as a list of integers, so instead of [[-1,0],[1,-20],[-14,10],[-27,-9]] you have [-1,0,1,-20,-14,10,-27,-9]. That removes 2 bytes per pair, although after gzip that may be negligible. (update: Mike tried it. 552K (vs. 656K) for uncompressed 164K (vs. 172K) for compressed)

 

#!/usr/bin/env python

import msgpack, zlib, sys, json

text = file(sys.argv[1]).read()
data = json.loads(text)
msgpackText = msgpack.packb(data)

def log(s, d):
    print "%20s %s" % (s, d)

log ("Source", len(text))
log ("Gzip", len(zlib.compress(text)))
log ("Msgpack", len(msgpackText))
log ("Msgpack gzip", len(zlib.compress(msgpackText)))

Tomato (Toastman) router config

Here’s some of the config I give my Tomato (Toastman flavor) router:

Basic / Network: DHCP is 192.168.0.2 - 192.168.0.63. Lease 1440. Wireless is WPA2 Personal security, Encryption is TKIP/AES. Wifi is currently auto channel, 20MHz wide. 40MHz is an interesting 802.11n option I’ll play with later.

Advanced / DHCP/DNS: I have “Use internal DNS” checked on. Not sure if this is wise, particularly since I can’t figure out how to override what DNS servers the router uses (presumably the ISP’s advertised on DHCP?) I mostly tell my computers to use Google DNS anyway, so maybe this doesn’t matter.

Advanced / Firewall: respond to ICMP ping. Not responding to ping is just stupid; it offers no meaningful security and makes diagnostics harder.

Port Forwarding / UPnP/NAT-PMP: enable both UPnP and NAT-PMP

QoS: enable QoS, this is the best feature of all of Tomato. It makes things work well if you can estimate your bandwidth limits. Note that “Outbound” refers to upload speed, packets leaving your house and going to the Internet. That’s the slow side on a DSL line. Also I turn on prioritize ACK packets (why isn’t this on by default?!)

Administration / Admin Access: enable SSH at startup. (No remote access, of course.) Save my SSH key.

Administration / Bandwidth Monitoring: enable, save to JFFS every 24 hours. Screw it if it’s not recommended.

Administration / IP Traffic Monitoring: enable, save to JFFS every 24 hours.

Administration / JFFS: enable, format.

Some settings to do once the router is installed:

Basic / Network: is 40Mhz channels wise?

Basic / DDNS: this is very useful, I’ve been using dyndns.com for years and it works great via Tomato.

Basic / DHCP/ARP/BW: another useful option, give static IP addresses to known computers.

Advanced / Conntrack: the default Toastman timeouts for NAT tracking seem awfully short, we’ll see how that works.

Advanced / Wireless: Transmit power was only 17 mW on this router. My old WRT54GL defaulted to 42mW. These may or may not be directly comparable numbers. Some discussion on this setting is here and here, no one seems to have any idea what they’re talking about.

Update I tried changing this from 17mW to 100mW and saw no measurable difference in RSSI on my laptop, or throughput, or anything. I only tested with a laptop very near the router already enjoying -55dBm (as measured via the Mac’s Wi-Fi diagnostics). So if the setting is most useful for distance I wouldn’t notice it. I left it back at 17mW. I am a bit peeved that my 802.11n laptop can only do 10mbits/sec to an 802.11g Mac Mini, despite a theoretical 54mbits/sec connection. Update 2: getting 22mbits/sec now, after rebooting the Mac Mini. Now it’s in 802.11n mode as well. But all on a mixed mode 2.4GHz network and with 20MHz wide bands.

Port Forwarding / Basic: haven’t set this up yet. I’m discouraged that it’s displaying an error “iptables-restore: line 39 failed”

QoS: check caps for the live network and set in place

QOS / Classification: Toastman has enabled a bunch of service classes. Would be nice to check if they are reasonable.

USB and NAS / FTP server: enable on LAN only. (Geez!)

Administration / Logging: remote log to syslog, particularly DHCP traffic. Big help for narrowing down problems.

Update 2: someone named “vibe666” commented “I saw your post about your router and that you are using TKIP/AES.  drop TKIP and just use AES on it’s own as TKIP is both a) not very secure, and b) pretty much obsolete anyway, and c) likely to be slowing down your wifi speeds overall to keep (potential) backwards compatibility with stuff almost nobody has anyway. :)”

Router notes

The Internet router continues to be the most important computer in a house. It’s also the most likely to be garbage. For a long time I’ve done well with Tomato firmware on a WRT54GL, but that config is starting to get long in the tooth. Tomato hasn’t been updated in a couple of years, the WRT56GL doesn’t do 802.11n, and in general the world has moved on.

After some research I settled on what I think is the new consensus setup, confirmed in part by Jeff Atwood’s suggestions.

Router hardware: ASUS RT-N16. It’s the popular hacker router now and at $80, a reasonable price. The big drawback is it’s 2.4GHz only, no 5.0GHz. I don’t much care about 5GHz. If I did, I’d consider an ASUS RT-N66U instead. But that’s $160 and at that price you start wanting a real PC, not a router appliance. My understanding is 802.11n will work on 2.4GHz co-existing with 802.11g and 802.11b, albeit at reduced performance.

Router software: a TomatoUSB variant, the Toastman builds. TomatoUSB is the continuation of Tomato but it itself stopped seeing development about a year ago. Toastman has picked up the mantle. The key feature he added that I need is per-IP bandwidth monitoring. Another popular choice is Tomato by Shibby, an alternate TomatoUSB variant. It looks good too. (Aside: it’s a shame none of these firmwares are nicely packaged. Half of what made Tomato so good is it was a very professional release with a great manual and UI. Very unusual for fan-produced hackerware.)

Toastman releases a zillion different builds. The one I picked was tomato-K26USB-1.28.7500.4MIPSR2Toastman-RT-Ext. Note the file is hosted at some ghetto download service you have to register for free with. Ugh.

First installation is a challenge; the stock ASUS firmware doesn’t like the build and ASUS’ software to reflash a router is Windows only. These TFTP instructions seem reasonable and mostly worked on my Mac. The weird thing is the ping to the router sort of failed before the tftp; first 10 packets didn’t come back. I just left the ping running and the tftp magically worked.

After the tftp there’s no visible sign anything’s going to work. So I held my breath and rebooted, and there’s a stock Tomato/Toastman router. Hooray! Next blog post will be about configuration options; there’s a lot. The default config is reasonable except there’s a typo in the DHCP range and some dumb things like an FTP server running on the WAN port.