Jump to content

February 2017 »

26 27 28    
* * * * * 2 votes

Software at Scale: Practice Like You Play

4: Adsense

I recently learned an interesting lesson in developing software that needs to scale to large capacities.

I can't get into the specifics of what I was working on, but the essential facts are more or less as follows:
  • It includes a cache algorithm
  • I tested it with as much load as my workstation could generate
  • In tests, it performed well as far as I could stretch it
  • We deployed this system and it started falling over in difficult-to-understand ways

The frustrating thing about this process was that I followed good testing practices to the letter - or so I thought. Make sure you have good coverage, test for edge cases, think about how real use patterns will affect behavior of the system, and so on. I even set up my tests to deliberately try and thrash the cache, hoping that it would reveal any weaknesses in that algorithm.

I plotted some data from the pre-launch test runs to see how it scaled. It looked pretty much linear, and so I figured it would work fine under heavier loads, because the coefficients were small enough that linear would be well under hardware capacity even at full demand. Testing showed no flaws at small scale, and I extrapolated from the test numbers that it would scale perfectly well to the load demanded of it.

Except it didn't.

The crucial lesson here is simple: when you are designing a system that must scale to high capacity, never extrapolate your test data.

My mistake was in assuming that the linear-looking behavior would stay linear as the cache size grew and the number of active clients increased by a couple orders of magnitude; in reality, that innocuous linear-looking curve turned out to be substantially sub-linear. The actual big-O analysis of the algorithm is too intricate and boring to go into, but suffice it to say that the behavior as the cache filled degraded very quickly.

The system then fell into a state where it would take longer to satisfy requests than it took for clients to generate new requests, meaning that the backlog of load snowballed until the whole thing just ground to a halt and barely served any requests at all.

We discovered that, paradoxically, flushing the cache would result in better performance almost immediately once this happened; it only took a few seconds of profiling data collected via XPerf on a test machine to figure out why.

I rewrote the cache algorithm to eliminate several of the algorithmic complexity issues (and several practical problems that Big-O alone never would have revealed) and now throughput has jumped substantially. At this point, it takes longer to send the response of a request over the network than it does to compute that response to begin with - precisely the kind of scaling behavior we wanted originally.

TL;DR: practice like you play. If you don't test at scale, you are not ready to deploy at scale. Extrapolations from small-scale tests will be misleading, and can give you a false sense of confidence. If you can't test at scale, analyze things rigorously and relentlessly to make sure you don't have hidden sub-linear factors in your system.

Apr 20 2012 11:47 PM
This is actually where one of the practices of Eve Online comes in. They wrote a series of "bots" that they can plug into the game to run tests. For instance if they want to have a drake fight between 1500 players (Happens frequently enough already, but this is for testing) then they can setup the bots to login with a drake and start targeting and shooting each other with missiles. The goal is to, of course, test optimizations to their various algorithms (missiles have been adding lag for a long time now since each one actually flies and hits the target server side).

The system they have is more complex than that, since they can introduce artificial lag and similar instability to test how the optimizations will affect it when the players have a ping of 300ms or more.

In the day to day software development I currently do I have a test setup that includes a number of servers that run hypervisors. I can then spawn virtual machines on those hypervisors using my testing client. I can thus test not just on various operating systems, but under different load conditions as well. That combined with the networking gear available to me allows me to setup realistic scenarios for clients and client applications based on the expected load requirements.

Two of my testing rigs:

Posted ImagePosted Image
Apr 21 2012 12:27 AM
Yep, bot testing is a great tool, and I'm a big fan of it. In fact, my own tests from this story included (admittedly very simple) automated load-generating "bots" if you will.

The problem isn't lacking automated tests; the problem is assuming that your test of N bots will correlate in a predictable way to the performance of N*100 or N*1000 clients. You can easily get scaling curves that look awfully linear up to N, and then once you hit N*100 turn out to be exponential or something equally horrid.
Apr 21 2012 01:21 AM
well, hence the example :P which is that testing is useless unless you're providing realistic loads.

Note: GameDev.net moderates comments.