The Causes Blog

Causes Tech: Measuring Static Asset Failures with Duckweed

On January 11, 2012, in Tech, by Adam Derewecki
1

At Causes, we’ve been dealing with intermittent static asset failures. This manifests as certain images, stylesheets, and Javascripts failing to load and leads to a poor overall user experience. Our band-aid solution has been to fail over load balancers, which resolves the issue (until it crops up again). This is far from a perfect solution, and we still only know to failover when we get enough reports of site issues. Using Duckweed (http://github.com/causes/duckweed) and some simple Javascript, measuring static asset failures from the client can help determine when we’re having major problems.

First, put this Javascript in your layout (or load it onto every page some other way):

<script language="text/javascript">
$.post('/duckweed/track', {'event' : 'static-asset-attempt'});
</script>
<%= javascript_tag 'static_asset_check' %>

Then, create another Javascript file named ‘static_asset_check.js’ that simply contains:

$.post('/duckweed/track', {'event' : 'static-asset-success'});

There are two important things going on:

  1. Every page registers a ‘static-asset-attempt’ event
  2. Every page attempts to load a static asset that registers a ’static-asset-success’ event

So, count(static-asset-attempt) – count(static-asset-success) indicates how many times the static asset did not load. Because we’re only looking at one static asset (the Javascript file we created), this is only a sampling of the total static asset failures — but that’s still good enough to alert us as to when assets are failing more often across the board.

At Causes, we use Geckoboard to create pretty graphs from Duckweed data. Duckweed’s histogram function is really nice for producing the data for these graphs, but it can only take one event. The difference between two events (attempt – success) is really what we want, so I implemented a histogram-delta view that does just that. See commit ab13d1b for the gritty details. Now, the following URL:

http://mydomain/duckweed/histogram-delta/static-asset-attempt/static-asset-failure/minutes/60

yields a useful and pretty graph like:

Does this kind of work interest you? Do you want to help migrate us to Cloudfront? We’re hiring!

 

One Response to Causes Tech: Measuring Static Asset Failures with Duckweed

  1. simona says:

    sunt pentru mentinerea serviciului SMURD,