Some Bits: Nelson's log

7 posts in October 2020

One weird trick to improve network latency

A smokeping from my house to 8.8.8.8

Can you spot the moment PG&E cut the power to our area? The network (and my house) are on backup power, so I’m still online. Looks like a whole lot of other customers aren’t though. Pings dropped roughly from 52ms to 42ms. It’s the fastest I’ve ever seen, even faster than at 3am.

It’s possible that what’s really going on is a different route is being used now that power is down. Here’s the route I have right now:

                                       Packets               Pings
 Host                                Loss%   Snt   Last   Avg  Best  Wrst StDev
 1. setup.ubnt.com                    0.0%    21    0.7   0.7   0.4   1.1   0.2
 2. 10.33.1.1                         0.0%    20    0.9   1.0   0.7   1.4   0.2
 3. BR-Switch_tik-a.ppk.sbbnet.net    0.0%    20   25.5  32.3  19.4 105.4  17.6
 4. 172.16.1.149                      0.0%    20   23.8  31.2  21.3  81.4  13.0
 5. 172.16.1.138                      0.0%    20   32.0  35.6  17.5  80.4  12.1
 6. ether4_tik-c1.crx.sbbnet.net      0.0%    20   30.9  29.4  18.4  41.2   6.2
 7. Gi022_rtr-e.crx.sbbnet.net        0.0%    20   24.1  28.5  17.6  36.1   5.4
 8. pr02-ae12.sea09.net.google.com    0.0%    20   37.4  45.2  32.6  51.7   5.2
 9. 74.125.243.193                    0.0%    20   51.5  45.5  34.8  58.1   6.4
10. 209.85.254.237                    0.0%    20   48.7  45.9  33.4  56.0   6.1
11. dns.google                        0.0%    20   69.1  50.3  39.0  75.4  10.4

Edit: one weird trick to increase latency! Note graph is 30 hour time scale.

The long steady part at left is Smarter Broadband, you can barely see the little dip in latency from 50ms to 40ms I reported above. The outage is when both they and AT&T cellular were down. Then I switched to AT&T cellular with 150-400ms ping times to Google DNS overnight. Just about 7am that let up to 500ms ping times. It’s still working, but they must be severely congested or something.

Here’s an mtr:

                                       Packets               Pings
 Host                                Loss%   Snt   Last   Avg  Best  Wrst StDev
 1. 192.168.3.1                       0.0%   134    0.7   0.7   0.3   1.1   0.2
 2. 100.127.125.128                   0.0%   134    1.6   1.3   0.8   1.7   0.2
 3. 100.127.173.124                   0.0%   134    2.1   1.8   1.2   5.0   0.4
 4. 107.94.133.11                     1.5%   134  551.2 397.4  89.4 955.8 125.3
 5. 166.185.45.162                    4.5%   134  535.3 393.0  80.5 643.1 112.0
 6. 192.168.192.74                    2.2%   134  517.8 430.0 108.2 1094. 124.8
 7. 192.168.196.8                     3.0%   134  538.8 430.3 108.9 1058. 125.7
 8. 162.244.250.1                     5.2%   134  557.3 432.1 106.9 1017. 120.6
 9. 162.244.250.54                    3.7%   134  506.6 434.2 117.5 966.9 120.9
10. (waiting for reply)
11. 148.66.238.120                    1.5%   134  488.9 450.1 123.0 934.0 130.0
12. 148.66.238.125                    6.0%   134  534.0 448.3 128.7 932.0 126.8
13. 148.66.238.99                     3.8%   134  539.3 456.0 121.8 881.6 130.0
14. 148.66.237.195                    3.0%   134  592.4 452.5 121.6 845.8 129.0
15. 4.59.30.121                      92.5%   134  580.4 511.9 313.3 759.1 122.6
16. 4.69.141.154                     89.5%   134  550.0 451.5 329.1 569.9  85.7
17. 72.14.203.208                     3.8%   134  624.7 468.0 164.4 850.5 117.8
18. 216.239.56.153                    5.3%   134  577.3 493.0 204.1 3320. 287.9
19. 216.239.42.153                    3.0%   134  578.2 459.6 137.2 831.6 118.2
20. 8.8.8.8                           1.5%   133  594.3 458.0 155.7 781.3 118.8

One more latency graph, shorter timescale. Most of this time is on AT&T’s cellular network until the very end (one short period, then the end). There’s jitter and then there’s jitter, you know?

QGIS: drawing roads with lines in casings

Many maps follow a sort of standard for symbology where roads are drawn as brown-orange-red lines with black casings around them. Like this, from a Wikipedia style guide.

QGIS has almost no support for drawing lines with casings, as common as it is. It’s something of a right of passage for map makers to figure out how to do it. I think I figured it out finally but I’m not an expert; please correct me in comments if I need it. This StackOverflow question is also helpful.

The basic idea is to draw two lines; a thick black line, then the thinner orange line on top of it. That’s simple enough. But it’s subtle and if you do it wrong all sorts of ugly things can happen.

Part of what makes doing this hard is that in most GIS data sets, roads aren’t just one single line. Particularly in OSM data roads are many line objects that are separate, little segments of road, and they just happen to overlap / join up right. Those joints can look terrible if you draw things wrong, see below. Also the intersections between roads need special attention.

I should note up-front that it’s important to test your results in whatever output format you’re really going to use. The on-screen preview in QGIS looks nice. But if you use the layout manager to compose a print run, know that the layout manager renders differently than the preview. Worse you’re probably really rendering to PDF or SVG, so you really have to look at those output files. And if you care about print, well, print it; the printer will change the way it looks once again. Most of the screenshots here are going to be in the main QGIS edit / preview mode.

The simplest thing is to just style the lines for your roads with two overlapping lines , like this in the Symbol Selector. Note the order matters!

In this case I have the black line as 1mm and the orange line as 0.6mm. Something like this is available as a default symbol in QGIS, the “Topo Main Road”.

This mostly works, and you should try it first and see if it’s acceptable because it’s so simple. However if you look closely, you’ll see small errors in the black casing. Particularly for roads made of many line segments. You can fix some of these by fiddling with the cap style; “flat” on the black line and “square” on the orange line works best for me. Here’s what square/square looks like blown up to 4mm to exaggerate the problems:

Another drawback with this simple approach is you don’t have any control over road intersections. They can end up looking terrible.

The more complicated drawing option is to have two layers for roads; one for the casings and one for the orange lines. You don’t actually need two full GIS layers though, you can also just duplicate the line data in the symbology classifier. In this case I’m using an OSM PBF extract with a Rule-Based Layer. (You might also be able to do this with a Categorized layer, but that type is less amenable to having multiple symbols for one type of data.)

If you just try this straight it might or might not work. The problem is that the order of these lines is not consistent in QGIS; they don’t necessarily draw in the order you have the rules in. To fix that you have to enable symbol levels (more info). This lets you specify the z-order of the symbols to control what order they are drawn in. Higher numbered levels are drawn on top of lower levels.

Note I’ve added in some extra complexity here; multiple sizes of roads. The general rule is you want to draw small roads first and then bigger roads on top of them. So the primary road is given the highest level, 15, so it draws on top of secondary and tertiar.

In this case I drew the casings right before the roads; doing things in that order makes it so the primary road has an uninterrupted casing. Here’s a sample of some roads of different sizes blown up to exaggerate the lines. (And the glitches in the casings, sigh. It looks better at normal resolution.)

Another option is to draw all the casings last, after all the roads. (Ie: have secondary’s orange line higher priority than the primary casing.) Doing that results in something that looks like this:

I’m not actually certain which is correct. I like the former better, so I’m doing that. Google Maps and the beautiful hand-rendered maps by Imus Geographics do the latter, so maybe I’m wrong. Honestly at normal map sizes you’d need a magnifying glass to see the difference.

One last note: symbol levels seem to only be relevant within their map layer. A symbol with a high level but in a lower map layer will not overdraw a symbol in a higher map layer.

So there you have it, roads with casings. And imperfections. I don’t know if it’s possible to actually do better in QGIS; I should really ask an expert. I sure wish QGIS just had support for “line with casing” as a symbol style. The “topo road” thing doesn’t cut it.

Smokeping notes

I’m trying to improve my Internet uptime monitoring. Right now I have a junky script that sends an ICMP ping every 1 or 5 seconds to a few carefully chosen IP addresses; my router, my upstream link, Google DNS, etc. It logs a text summary when a string of pings fail in a row. It works OK but is janky.

So I asked on the Internet for a better ping monitoring system and was reminded about smokeping. I have it sorta set up on my Ubuntu box now and it’s OK. Before I deep dive on that I also want to give a shout out to vaping, a rewrite of smokeping in Python. It’s not as featureful but then it’s not as old and idiosyncratic, either.

So the setup. I have smokeping sending 3 pings every 5 seconds to a total of 8 hosts. It makes graphs of latency for the ping replies along with highlighting packet loss. Eazy peazy.

Why 3 pings every 5 seconds? Well smokeping is really designed to send a whole lot of pings at once and show the distribution of latencies. The default is 20 pings! Also the default is only to measure every 5 minutes, which is fine for long term monitoring but I’m trying to catch short failures. It turns out 3 pings is the minimum smokeping is willing to send. 5 seconds was a compromise for me not wanting to spam too much. Works out to 3 * 8 / 5 = ~ 5 ping packets a second.

I’m using the default FPing probe. It’s fairly smart about handling timeouts, spacing an interval between pings, rotating through different hosts, etc. There’s also an FPing_Continuous probe option in smokeping whose main difference is it uses the “--loop” option in FPing. Near as I can tell that just moves the control loop from smokeping to fping, not sure that really buys you anything. Maybe it spreads the pings out more evenly?

As near as I can tell there’s no way to get smokeping to ping once a second. I found some years-old discussion about architectural assumptions in smokeping about the minimum interval between pings, and how much time the pings should take, etc that make it sound like that “20 pings every 5 minutes” really is the intended use case. Also I now have a giant RRD file I’m sure, and the code seems to be regenerating all the graphs every 5 seconds whether I need them or not. It’s all a bit silly and overkill but I think harmless for now.

I might also yet replace smokeping with vaping. It’s not nearly as fancy, but then it seems designed precisely for my 1 ping-per-second desired scenario.

Sample to ping.ubnt.com

Android phone migration experience

My 18 month old Pixel 3 had a hardware failure; the battery swelled, apparently a common problem. To Google’s credit they got a replacement to me in 36 hours at no cost to me. So now I have the experience of transferring my life from one Android phone to the other.

This was a transfer from a Pixel 3 running Android 11 to a Pixel 3 running Android 10. No idea if the downlevel OS caused a problem; I didn’t see any option to upgrade first.

Top line: it’s not a great experience compared to an iPhone. Apple has very simple one button backup and restore. Android does not. Instead it has like six different things you might want to back up, some of which are automatic and some are not.

I mostly had the data and settings stuff configured for backup to Google, so I figured I was OK. I also made a backup over USB of all the files on the phone, although I haven’t restored those.

Setting up the new phone at first was easy. You turn it on and it prompts you to plug a cable in to the old phone to transfer everything. Great! Go go go! It only took a few minutes, too. But the fact it only transferred 7GB of stuff was a clue something was wrong; I’ve got 30+GB on the phone.

A big part of what didn’t transfer were my apps. Instead the phone decided to redownload all the apps from the Internet. That’s not a terrible choice but it’s slow and possibly expensive and seems a little unnecessary. It took over an hour to redownload 150 apps, many of which I honestly don’t want.

Then the phone is mostly like before. Except.. all sorts of settings and configurations aren’t carried over. Many are, but not everything, and it’s quite confusing. Some things not restored:

  • Notification customizations. All these apps are back spamming me with noisy notifications.
  • Most logins. Almost every app demands I log in again. Fair enough. Happily, 1Password transferred over with little problem.
  • Authy auth state. I ended up having to delete Authy from the new phone, change the backup password on the old phone, then reinstall it on the new phone to get my login tokens back.
  • App permissions. Have to completely re-set-up which apps get access to location services, etc.
  • Random app preferences. Like my weather app forgot that I want weather for where I am right now, now Tokyo. Tapet seems to have remembered I want a new background every hour and that I’d paid for the app, but forgot my color preferences. GSAM Battery Monitor totally lost its state. Golf on Mars kept everything.

I think what I find most baffling is the app inconsistency, the way some settings carried over and others didn’t. Logins too. I have 4 gay hookup apps on my phone (go ahead and judge; I would). 2 of them made me log in again, 2 didn’t! So weird.

None of this is a catastrophe, but it’s definitely a nuisance.

Update: see the discussion here. Particularly the link to data backup docs for developers. I guess since Android 6 auto-backup for apps is on by default but limited to 25MB / app. There’s also a more manual backed up Key/Value store for properties, etc.

QGIS: drawing elevation increments

I wanted to make a map where every 100m of altitude has a different color. Ie: not a continuous ramp, but discrete colors. This turned out to be tricky enough I’m writing note.

1. Import DEM data like SRTM

2. Set the render style to “singleband pseudocolor”. Do not use “singleband grey”; it does not have the options we need.

3. set min / max to reasonable values. Ie 0 to 4000 meters. Set color interpolation to Discrete, pick a color ramp you like. (see step 7 for more)

4. Set mode to “Equal Interval”. Change the number of classes as you see fit; I chose 8. Click the “Classify” button.

5. Apply the style. It should look close to the result you want.

6. Tweak the Brightness / Saturation / Contrast to modify the overall effect as you need.

7. Experiment with different color maps. There’s a lot more built in than you’d think; if you “Create new color ramp” of type “Catalog: cpt-city” you find a lot of interesting options including many that are specifically for topography.

Here’s a simple brown every 500 meters scale I’m using.

The result looks like this (along with blue river lines from another data layer)

BTW the color map for my favorite Wikipedia map ever is one of the ones built in to QGIS. Or at least something similar. Look for “wiki-france” under “topography and bathymetry”.

Cursed hillshade

This is what you get in QGIS if you use its hillshader and then zoom in finer than the resolution of the DEM data. May need to view image full size to get the effect.

Ubiquiti Security Gateway failures

Trying to diagnose a problem with my Grass Valley network where the Internet goes down 20-120 seconds every few hours. I think this is an old problem that dates back to my old router (Ubiquiti EdgeMAX) but it may be related to the new USG or the LTE failover device I recently installed, even though it’s now disabled.

The symptom is the whole Internet goes down. My router logs this message:

WAN iface [eth0] transition to state [active] 11:33 am 2020-10-05
WAN iface [eth0] transition to state [inactive] 11:32 am 2020-10-0

I’m able to reproduce that the Internet is really down with a simple looping ping script. But that just tells me the Internet is down, not why. My question is why is the router logging that message?

Related: this webpage has excellent docs on how Ubiquiti’s failure detection and failover works.

Theories

My first theory was that my WISP is just flaky and that’s to be expected. I swear I’ve had problems like this for years. But I had a long chat with them yesterday and they assured me that’s not expected behavior. Also that my device had a clear strong signal for at least a week. But their monitoring is only good to 5 minutes, so wouldn’t catch a 30 second outage.

My second theory is that my WAN device, a Cambium ePMP 1000, is genuinely just failing. That the device loses power or for some other reason reboots. Unfortunately it’s up in a tree and I don’t have the access to read any stats or SNMP data from it, so I don’t know. But that’d surely explain why the router decided eth0 was inactive, if it lost ethernet link.

The third theory is that it’s Ubiquiti’s watchdog itself that’s failing. If you configure a WAN2 failover (say, my LTE device) they run a watchdog process that tries to ping ping.ubnt.com every 10 seconds. If that fails 3 times in a row it decides the WAN1 interface is down, sets it inactive, and fails over to WAN2.

Evidence

But would they still be running this failover algorithm even if WAN2 is disabled and not running? I fear maybe so. Logging in as root on the USG and running show load-balance watchdog I see some evidence that the failover stuff is still happening.

Group wan_failover
eth0
status: Running
pings: 2457
fails: 0
run fails: 0/3
route drops: 7
ping gateway: ping.ubnt.com - REACHABLE
last route drop : Tue Oct 6 02:53:08 2020
last route recover: Tue Oct 6 02:53:59 2020

That timestamp corresponds to my latest failure and suggests the watchdog apparatus is still running. show load-balance status also has some interesting info in it.

There’s more information in /var/log/messages on the router:

Oct 6 02:52:38 ubnt zebra[753]: interface eth0 index 2 changed .
Oct 6 02:52:38 ubnt kernel: eth0: Link down
Oct 6 02:52:39 ubnt zebra[753]: interface eth0 index 2 changed .
Oct 6 02:52:39 ubnt kernel: eth0: 100 Mbps Full duplex, port 0
Oct 6 02:53:08 ubnt wlb: wlb-wan_failover-eth0 wlb-wan_failover-eth0 reachability failed, failover
Oct 6 02:53:08 ubnt wlb: group wan_failover, interface eth0 going Inactive
Oct 6 02:53:08 ubnt wan-event: [WAN Transition] eth0 to state inactive
Oct 6 02:53:59 ubnt wlb: group wan_failover, interface eth0 going Active
Oct 6 02:53:59 ubnt wan-event: [WAN Transition] eth0 to state active

In this log, the ethernet interface goes down first, before the watchdog is involved. That’s consistent with theory #2: the connection to the WISP antenna is flaking out. Looking back in the logs that’s the same pattern for many failures. The ethernet link goes down for about 2 seconds, then comes back. Then about 30 seconds later the failover system kicks in and marks the WAN inactive. Then some period of time later (51 seconds in this instance) the failover marks the link active again.

My local ping to the WISP antenna shows a shorter outage. Clocks are both NTP synchronized, but 7 hours off because of timezones.

Ping 35446 failed Tue Oct 6 09:52:42 2020.
Ping 35447 failed Tue Oct 6 09:52:47 2020
Ping 35448 failed Tue Oct 6 09:52:52 2020
Ping 35449 failed Tue Oct 6 09:52:57 2020
Outage for 21 seconds started Tue Oct 6 09:52:36 2020

I also have a different monitor pinging ping.ubnt.com from my own Linux box

Ping 197355 failed Tue Oct 6 09:52:42 2020
Ping 197356 failed Tue Oct 6 09:53:12 2020
Ping 197357 failed Tue Oct 6 09:53:22 2020
Ping 197358 failed Tue Oct 6 09:53:27 2020
Ping 197359 failed Tue Oct 6 09:53:32 2020
Ping 197360 failed Tue Oct 6 09:53:37 2020
Ping 197361 failed Tue Oct 6 09:53:42 2020
Ping 197362 failed Tue Oct 6 09:53:52 2020
Ping 197363 failed Tue Oct 6 09:53:57 2020
Ping 197364 failed Tue Oct 6 09:54:02 2020
Outage for 90 seconds started Tue Oct 6 09:52:32 2020

Putting that all together, the timeline:

  • 02:52:38 to 02:52:39 router notices WISP ethernet is down
  • 02:52:42 to 02:52:57 (approx) can’t ping the antenna IP address
  • 02:53:08 to 02:53:59 router marks WAN interface inactive
  • 02:52:42 to 02:54:02 (approx) can’t ping an Internet host

Note that even though the ethernet is down for 1 second, the whole Internet is down for 90 seconds. But the WISP antenna is only down for about 20 seconds.

My guess is the ethernet connection to the WISP antenna, including its power, failed. Or else the WISP antenna rebooted itself. The ethernet link comes back very fast on reboot on that device, like 1 second. But it takes 20 seconds to get up and running enough it’ll respond to pings. And in this case, 90 seconds to fully recover and be online again reliably. Not all the outages are this long; most are more like 60 seconds.

Next steps

So that’s all consistent with theory #2: the connection to the WISP antenna is flaking out. I mean it’s right there in the “link down” message. I’m still confused as to how a momentary break in ethernet signal makes for a 60 second outage.

I’ve asked my ISP whether it can give me more information about what’s happening to WISP antenna device. At least, its uptime.

I’ve got a pretty marginal wiring solution for the antenna; the ethernet cable is 350+ feet long and the PoE injector is at far end from the antenna. I’ve also got a simple passive cable joiner about 50 feet from the antenna. I should split it there and put the PoE injector and maybe an ethernet switch nearer the antenna and see if that makes it more reliable.

Update

Well damn, a theory shut down. My ISP got back to me:

I logged into the antenna, and it is showing an up time of 6 days and 7 hours at the time of this email. I also looked at the signal history for the last 3 days and found no breaks or loss of the signal between the antenna and the radio tower. That antenna has a reboot time of about 1 to 2 minutes.

So much for my theory that the antenna was losing power and rebooting.

However I’m still convinced that the ethernet link between the router and the antenna is failing. I mean, the router says so in its logs! That could still be a result of the long ethernet run through a coupler, so there may be still be an advantage to putting a switch in the middle of that long run; it may never have been PoE, but data / link failure. I also wonder if it’s possible the WAN1 port on the USG itself is broken. Seems unlikely but...

I had no outages at all for nearly 36 hours, then today I’ve had 10 outages in 5 hours (mostly overnight). Really confusing.

Update 2

It’s been bugging me that the local antenna seems to go down for 21 seconds, but then the whole WAN goes down for a minute+. I think we’ve got an unfortunate coincidence of timings. The watchdog default is (I think) 3 pings in 10 seconds failing for a failure, and 3 pings in 10 seconds working for a success. With my antenna link outages 3 pings just barely fail in a row. The 4th would work but the router has already decided the link is not working. Then it waits for 3 more pings before re-activating the link. I can sort of verify this behavior; I had the antenna fail a ping once for 6 seconds (don’t know why), and the router didn’t detect that as a real outage.

So for now I’m testing changing the config to need 6 bad pings in a row to detect WAN failover. Once the LTE device is back working it’ll be a longer wait for it to come online, but it might hide these ethernet link outages or at least make them less severe.

$configure
ubnt@ubnt# set load-balance group wan_failover interface eth0 route-test count failure 6
[edit]
ubnt@ubnt# set load-balance group wan_failover interface eth0 route-test count success 3
[edit]
ubnt@ubnt# show load-balance group wan_failover
flush-on-active enable
interface eth0 {
route-test {
count {
failure 6
success 3
}
initial-delay 20
interval 10
}
}
interface tun900 {
failover-only
route-test {
initial-delay 60
interval 600
}
}
sticky {
dest-addr enable
dest-port enable
source-addr enable
}
transition-script /config/scripts/wan-event-report.sh
[edit]
ubnt@ubnt# commit
[edit]
ubnt@ubnt# save
Saving configuration to '/config/config.boot'…
Done
[edit]

These changes aren’t persistent; next time the controller reprovisions the router they’ll be wiped out. The linked docs talk about how to make them persist through that too but I’m told these only work through a USG, not a Dream Machine. Fortunately I have the USG.

Update 3

Those changes may have made things worse; outages seem to be even longer. Honestly I can’t really understand what’s happening. Since making those changes:

Outage for 60 seconds started Mon Oct 12 14:19:03 2020
Outage for 90 seconds started Tue Oct 13 16:13:22 2020
Outage for 75 seconds started Tue Oct 13 16:18:27 2020
Outage for 51 seconds started Tue Oct 13 16:29:32 2020
Outage for 75 seconds started Wed Oct 14 08:37:20 2020
Outage for 16 seconds started Wed Oct 14 08:38:35 2020
Outage for 14 seconds started Wed Oct 14 19:08:41 2020
Outage for 55 seconds started Wed Oct 14 21:09:21 2020
Outage for 121 seconds started Thu Oct 15 01:40:31 2020
Outage for 90 seconds started Thu Oct 15 18:25:41 2020
Outage for 90 seconds started Fri Oct 16 19:50:06 2020

I’ve tried setting the “success” timer from 3 consecutive pings (ie: 30 seconds) to just one. Not ideal if there’s a working failover, but in the absence of one I think this is better than waiting?