<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Pragmatic Dictator &#187; testing</title>
	<atom:link href="http://www.dancres.org/blitzblog/tag/testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dancres.org/blitzblog</link>
	<description></description>
	<lastBuildDate>Sat, 31 Dec 2011 19:08:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Remoting</title>
		<link>http://dancres.org/feeder/?FeederAction=clicked&#038;feed=Articles+%28RSS2%29&#038;seed=http%3A%2F%2Fwww.dancres.org%2Fblitzblog%2F2010%2F11%2F09%2Fremoting%2F&#038;seed_title=Remoting</link>
		<comments>http://dancres.org/feeder/?FeederAction=clicked&#038;feed=Articles+%28RSS2%29&#038;seed=http%3A%2F%2Fwww.dancres.org%2Fblitzblog%2F2010%2F11%2F09%2Fremoting%2F&#038;seed_title=Remoting#comments</comments>
		<pubDate>Mon, 08 Nov 2010 22:04:59 +0000</pubDate>
		<dc:creator>Dan Creswell</dc:creator>
				<category><![CDATA[Distributed Systems]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[Engineering]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.dancres.org/blitzblog/?p=349</guid>
		<description><![CDATA[The difficulty of constructing remote services is often not in writing them but testing and debugging whilst ensuring that some of the nastier types of failure (e.g. packet loss or machine failure) are adequately handled. The norm for these kinds of testing scenarios is to have a full, mocked-up test environment with a bunch of [...]]]></description>
			<content:encoded><![CDATA[<p>The difficulty of constructing remote services is often not in writing them but testing and debugging whilst ensuring that some of the nastier types of failure (e.g. packet loss or machine failure) are adequately handled.</p>
<p>The norm for these kinds of testing scenarios is to have a full, mocked-up test environment with a bunch of servers. Such a setup needs sysadmin and repeated deployment steps which for most organisations are slow, ponderous things. Incremental test cycles in such an environment become costly which leads to onerous, last-minute testing and the late discovery of difficult to fix bugs that introduce endless release delays.</p>
<p>Over the years I&#8217;ve developed an approach for pushing all these testing scenarios back toward the unit level so they can be run regularly per build as they take mere minutes to complete. The core philosophy is to design the software in such a fashion that it runs on a single machine using all the network protocols it would use when deployed across many servers (ah, the power of localhost/127.0.0.1).</p>
<h2>Preliminaries</h2>
<p>Putting this philosophy into practice requires that we adopt certain design practices:</p>
<ol>
<li><strong>Clean separation between the transport/remote layers and the core service logic</strong>. This makes it easy to develop tests that verify the core logic without any remoteness concerns and a second set of tests that perform the more heavyweight remote tests. The benefit is that we can more easily isolate issues when they occur. For example, if the core logic tests pass but the remote tests fail we can be pretty confident the issue is in the remote layers.</li>
<li><strong>Clean separation of configuration source from core service and transport/remote layer</strong>. This ensures all our software requests configuration using a consistent API which could then be implemented via LDAP, flat-files, in-memory etc. Such a setup allows us to easily build up configuration inside of our tests and make it available to the services we&#8217;re building.</li>
<li><strong>Runtime discovery of endpoints</strong>. To allow us to dynamically allocate port/ip combinations and make them available to whichever services require them. One can achieve this via the abstracted configuration source but it&#8217;s often cleaner to have a dynamic lookup/discovery mechanism.</li>
<li><strong>Configurable log file locations</strong>. So that we can avoid path clashes between services.</li>
</ol>
<p>Once these things are in place, unit tests can construct transports, endpoints and configuration dynamically at run time in whatever combination is required for a test. It is thus possible to instantiate a collection of services inside of a single process and have them talk to each other as if they were all running remotely. This is somewhat at odds with other design practices where we typically look to remove remoteness when running services locally for purposes of performance.</p>
<h2>Failure Scenarios</h2>
<p>By virtue of the unit tests having control of all the services and their transports/endpoints it becomes possible to stop or disable services thus simulating machine failures but it&#8217;s also possible to extend the approach to cover problems such as packet loss, corruption or increased latency.</p>
<p>These more advanced scenarios are more readily handled with server construction toolkits such as <a href="http://jboss.org/netty">Netty</a> which allows tight control of packet processing and protocol. Using Netty, one can build up the protocol stack per service exactly as required and introduce <a href="http://docs.jboss.org/netty/3.2/api/org/jboss/netty/channel/ChannelPipeline.html">Decoder/Encoder pairs, Handlers</a> or wrappers around core service implementation that can randomly (and silently without severing the connection) lose messages or packets, break connections etc.</p>
<h2>Example</h2>
<p>I&#8217;ve been working on a <a href="http://en.wikipedia.org/wiki/Paxos_algorithm">Paxos</a> implementation which breaks down into:</p>
<ul>
<li>State machines &#8211; Leader, Acceptor and Learner and associated elements such as leader election and failure detection.</li>
<li>Persistent storage layer &#8211; as various state must be remembered across Paxos instances.</li>
<li>Remote communications layer &#8211; including cluster membership and remote communications.</li>
</ul>
<p>The state machines accept messages, make appropriate state transitions and produce messages. These are then passed around between participants via the remote communications layer. The persistent storage layer allows for specification of file locations at construction time which allows test code to allocate separate directories on a single-disk to hold respective state.</p>
<p>The remote layer is built such that none of the members need static/well-known ports to operate off. There is one exception which is a fixed multicast address that is used to do initial cluster discovery. It is implemented using Netty and consists of some codecs for the various messages and a handler that passes messages to and from the state machines.</p>
<p>There are several different implementations of the handler. There is the normal version that dispatches messages reliably and several others that randomly drop messages or lose them at critical moments in an instance of Paxos. The exact behaviour of these handlers is configured at runtime which allows unit tests to construct random or specific failure scenarios and ensure the state machines behave appropriately.</p>
<p>All these elements together allow unit tests to construct, in a single-process, fully remote services that communicate via TCP and UDP/Multicast as if they were running on a network and simulate failure scenarios. Alongside these tests are a collection to verify correct behaviour of the state machines and a set that validates their failure handling via timeouts, leader election behaviours etc. The entire suite including the failure scenarios runs in less than five minutes. That leaves one long-running test that exercises a collection of state machines concurrently for long periods, a necessary soak test run separately.</p>
<h2>Alternative Implementations</h2>
<p>A similar testing approach is possible with the likes of <a href="http://eclipse.org/jetty/">Jetty 7</a> as the lower IO layers are open enough to be customised to support these test scenarios. This can be a better option than Netty if services are Servlet based.</p>
<p>More challenging are the RPC-based services as these tend to run atop closed stacks that limit the amount of customisation possible and often have horrid configuration methods. However <a href="http://thrift.apache.org/">Thrift</a>, by virtue of it&#8217;s <a href="http://jnb.ociweb.com/jnb/jnbJun2009.html">Processor/Protocol abstraction</a> can be readily modified to support such testing.</p>
<p><em>Sidenotes:</em></p>
<p><em>
<ol>
<li>Applications that use databases for state storage can make this sort of testing tricky but it&#8217;s not impossible. One solution to the problem is to make use of virtual machines where one instantiates an image containing a pre-defined database and shuts it down afterwards alongside some scripts to prepare and tear down data within the database</li>
<li>I&#8217;ve recently applied this approach to several other systems including a trade management system written in Clojure, a trading platform written in Scala and a gossip-based directory service also written in Scala</li>
</ol>
<p> </em></p>
]]></content:encoded>
			<wfw:commentRss>http://dancres.org/feeder/?FeederAction=clicked&#038;feed=Articles+%28RSS2%29&#038;seed=http%3A%2F%2Fwww.dancres.org%2Fblitzblog%2F2010%2F11%2F09%2Fremoting%2F&#038;seed_title=Remoting/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Performing</title>
		<link>http://dancres.org/feeder/?FeederAction=clicked&#038;feed=Articles+%28RSS2%29&#038;seed=http%3A%2F%2Fwww.dancres.org%2Fblitzblog%2F2010%2F06%2F04%2Fperforming%2F&#038;seed_title=Performing</link>
		<comments>http://dancres.org/feeder/?FeederAction=clicked&#038;feed=Articles+%28RSS2%29&#038;seed=http%3A%2F%2Fwww.dancres.org%2Fblitzblog%2F2010%2F06%2F04%2Fperforming%2F&#038;seed_title=Performing#comments</comments>
		<pubDate>Fri, 04 Jun 2010 00:14:15 +0000</pubDate>
		<dc:creator>Dan Creswell</dc:creator>
				<category><![CDATA[Engineering]]></category>
		<category><![CDATA[Systems]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.dancres.org/blitzblog/?p=337</guid>
		<description><![CDATA[My current company has for obvious business reasons got a serious interest in delivering a quality website experience during the World Cup and thus I&#8217;ve been spending a lot of time focused on our own performance and capacity management of late. P&#38;C is one of those 80/20 tradeoffs. There&#8217;s always more one can do or [...]]]></description>
			<content:encoded><![CDATA[<p>My <a href="http://www.sportingindex.com/">current company</a> has for obvious business reasons got a serious interest in delivering a quality website experience during the World Cup and thus I&#8217;ve been spending a lot of time focused on our own performance and capacity management of late.</p>
<p>P&amp;C is one of those 80/20 tradeoffs. There&#8217;s always more one can do or measure or test, equally getting the basics in place will deliver substantial benefit. I&#8217;d go further and argue that without a solid grasp of the basics, one cannot easily determine what else beyond that might be required. Here then are the basics that I&#8217;ve found myself repeating over and over:</p>
<ul>
<li>Have an enquiring mind &#8211; anomalies are not to be ignored or dismissed on the basis of pure speculation. Determining root cause is essential to prevent surprises in production. Some recent examples:
<ol>
<li>In one test we noticed that every so often we&#8217;d get a substantial blip in disk I/O on servers that should be processing entirely out of memory. Along with that blip there&#8217;d be a corresponding reduction in throughput, we could have ignored it, after all things sorted themselves out relatively quickly but we chose to investigate. All these servers were periodically running a cleanup job the developers were unaware of and had not factored into their capacity calculations. The implications for production would have been a regularly overloaded, badly performing website. We&#8217;ve since tuned the jobs, adjusted their schedules and  increased our capacity to ensure we can always spread the load around enough to accommodate them.</li>
<li>An examination of the distribution of load on the boxes behind our load-balancers revealed a higher than expected amount of variance in CPU and connections. A review of the application revealed that any particular user&#8217;s traffic is sticky to one box, unfortunate as it&#8217;s stateless, time for a code change. We also spent time looking at the monitoring infrastructure and discovered that in certain cases we&#8217;d get false reports of 100% CPU utilisation, that one will be fixed with an OS patch.</li>
</ol>
</li>
<p></p>
<li>Gather the right data &#8211; there&#8217;s no value in allowing oneself to be limited by what is easily available via some set of tools people are comfortable with. One tool we were using had an unreasonably low ceiling on the number and rate of samples it could handle such that any graphs it produced showed hardly anything of the true profile of e.g. CPU utilisation, memory consumption or I/O. Forming any opinion about system behaviour in respect of load was going to be an exercise in speculation. We junked the tool and are looking for a replacement, in the meantime we&#8217;ve fallen back to making use of low level performance counters which we can sample local to the machine and whack onto disk for later analysis via scripts, opensource tools etc.</li>
<p></p>
<li>Design tests that support reasoning &#8211; One should indeed try and replicate production load behaviours to judge overall system behaviour. The challenge of such testing is that it can be difficult to relate performance data back to exactly what was going on during some period of a test and make a diagnosis or be confident of an improvement. There are a number of things we can do to improve the situation:
<ol>
<li>Ensure tests are deterministic such that any given run can be compared against other runs. This isn&#8217;t as simple as it looks when e.g. you wish to gradually increase load at a fixed rate that is being produced by more than one box.</li>
<li>Have tests produce sufficient logging that one can easily identify what was going on at particular points in the sampled data. Logging of course can actually affect test behaviour and that isn&#8217;t always desirable.</li>
<li>Build additional tests that target particular user journey&#8217;s through the system. Doing this for all possible journey&#8217;s can be costly so it makes sense to focus on testing those which are most popular with users. These kinds of tests restrict the reasoning tree making analysis, diagnosis and solution identification much easier.</li>
</ol>
</li>
<p></p>
<li>Measure what customers care about &#8211; they don&#8217;t care about CPUs, I/O or memory, they worry about things like response times. It is important to focus on maintaining a quality user experience not endlessly improving system efficiency. Considering user factors such as response times stops us expending huge effort on CPU utilisation when we should be focusing on say, network I/O, browser performance or reducing the amount of data we push to the browser before a page can render.</li>
<p></p>
<li>Beware of averages &#8211; it is very tempting to combine datasets via the use of averaging unfortunately such a practice can easily hide spikes that might be indicative of a problem. On more than one occasion an engineer has presented a graph that tracks the average CPU and a table that summarises min, avg and max. After which they&#8217;ve pronounced load testing was a success and yet they have no explanation for why the average is never more than 50% but the max is 100% and whether or not this is good or bad.</li>
<p><br/></p>
<li>More than load &#8211; excessive focus on measuring the effect of a particular load can make us blind to another important metric, resource cost per unit of work &#8211; these are the collection of tests and analysis that help us understand what to tune and how much to keep our appetite for boxes and bandwidth reasonable. One simple thing teams can do per sprint (assuming you&#8217;re agile, why wouldn&#8217;t you be?) is point a profiler at each component and look for the low hanging fruit that is poor algorithm selection or inefficient code (e.g. repeated scanning of lists where a hashmap would be better or repeatedly computing something that could be cached).</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://dancres.org/feeder/?FeederAction=clicked&#038;feed=Articles+%28RSS2%29&#038;seed=http%3A%2F%2Fwww.dancres.org%2Fblitzblog%2F2010%2F06%2F04%2Fperforming%2F&#038;seed_title=Performing/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

