<?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>Opower &#187; Dave Copeland</title>
	<atom:link href="http://blog.opower.com/author/dave-copeland/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.opower.com</link>
	<description>Blogs</description>
	<lastBuildDate>Thu, 23 May 2013 04:07:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Our Scala DSL for testing our web product</title>
		<link>http://blog.opower.com/2011/09/our-scala-dsl-for-testing-our-web-product/</link>
		<comments>http://blog.opower.com/2011/09/our-scala-dsl-for-testing-our-web-product/#comments</comments>
		<pubDate>Mon, 19 Sep 2011 14:34:57 +0000</pubDate>
		<dc:creator>Dave Copeland</dc:creator>
				<category><![CDATA[Opower Labs]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://www.heyitsopower.com/?p=480</guid>
		<description><![CDATA[This is actually a fairly old bit of tech for us, but I&#8217;ve been reading Martin Fowler&#8217;s DSL Book, and thought it might be good to talk about what we&#8217;ve done. Our Domain-Specific Language is&#8230;]]></description>
			<content:encoded><![CDATA[<p>
This is actually a fairly old bit of tech for us, but I&#8217;ve been reading <a href="http://www.amazon.com/Domain-Specific-Languages-Addison-Wesley-Signature-Fowler/dp/0321712943">Martin Fowler&#8217;s DSL Book</a>, and thought it might be good to talk about what we&#8217;ve done.
</p>
<p>
Our Domain-Specific Language is probably more domain-specific than you might be used to.  Frameworks like Ruby-on-Rails or ScalaTest are DSLs for very broad domains (web-app development, and testing, respectively).  Our DSL&#8217;s domain is <em>our web product</em>.  Not any web product, not any Spring app, <em>our</em> web app.  This is important, as it allows us to creating something that is very focused and specific to what we&#8217;re doing.  In general, the more specific the domain, the more concise and powerful you can make your DSL.
</p>
<h2>The domain of application: its architecture</h2>
<p>
To understand how it works, you need to understand how the apppilcation is architected.  While it&#8217;s a Spring MVC web app, in the general sense, there&#8217;s a lot more convention around how it&#8217;s built.  If you&#8217;ve used a &#8220;web framework&#8221; like Spring MVC, you know that it&#8217;s really a giant library for responding to HTTP requests at its core, and that it&#8217;s not very opinionated; it&#8217;s generally just as easy to do things one way as it is another (check out <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/web/bind/annotation/RequestMapping.html">this</a> if you disgree).  As such, you need conventions around how to use it. Developers shouldn&#8217;t spend time asking how to wire up URLs, or where code should go; they should be getting to work and building features.
</p>
<p>
Our app is built along two main concepts: <em>pages</em>, and <em>modules</em>.  A Page is made up of one or more modules.  Each module contains a basic bit of information needed to display a page.  Think about websites that say &#8220;Hi, Dave!&#8221; in the upper corner; that &#8220;Hi, Dave&#8221; would be controlled by  a module.  Each page is backed by a controller whose job it is to expose <strong>only</strong> what&#8217;s needed to configure the modules on the page. All stateful information (e.g. &#8220;who&#8217;s logged in?&#8221;) is in these controllers.  Modules, on the other hand, are stateless; they get all the information they need to render from the URL and query parameters.  Modules are made up of two parts: a resource, which identies the data to display, and a view, which renders that data.  A single resource can have many views, and together, they form a module.
</p>
<p>
This is all glued together via a souped-up version of a <code>&lt;jsp:include&gt;</code> tag.  A page jsp-includes a bunch of urls, that happen to be modules, and conform to these conventions.  We have scaffolding scripts to generate the massive boilerplate required to make this happen.
</p>
<h2>Testing with Scala</h2>
<p>
Which brings us to our DSL for testing this stuff.  Essentially, a module&#8217;s url can be requested and tested independently of any page; we don&#8217;t need to navigate through the application to test modules, since they are almost entirely stateless (typically, they might require a login, but this a cross-cutting concern).  By requesting the module&#8217;s URL, and forcing it to render a view, we also get test coverage of our JSP pages, and can push our app to QA with high confidence that all pages will at least render, and that the correct information will be somewhere on the page.
</p>
<p>
This can all be tested with HTMLUnit, however the tests began to look like bloated assembly-language.  Enter Scala.  I started by writing out the ideal pattern of a test for a module.  Let&#8217;s consider a module that renders a person&#8217;s most recent bill.  Suppose we have two views of this module; in the &#8220;large&#8221; view, we want to see the bill&#8217;s cost, KWh used, and an account number.  In the &#8220;small&#8221; view (that we might use on a dashboard page), we want to see just the bill&#8217;s cost.  How might we test this?
</p>
<pre>
resource for bill 34 from customer 123:
  requires login as customer 123
  contains "45.67" as the cost
  has a view "small"
  has a view "large"
    that contains "156" as the kwh
    that contains "655321" as the account number
</pre>
<p>
I decided I wanted to write this in code, and have it work.  Not having time to write a parser (or invent a new language), I decided an internal DSL would be the way to go, and that Scala would let me get as close as possible to this:
</p>
<p><script src="https://gist.github.com/1226977.js?file=DSLSimple.scala"></script></p>
<p>
This code creates several data structures that our test can now walk.  Essentially, what this will test:</p>
<ul>
<li>That accessing the url without being logged in gets an error</li>
<li>That, once logged in, requesting a view named &#8220;small&#8221; will not generate an error</li>
<li>That, once logged in, requesting a view named &#8220;large&#8221; will not generate an error</li>
<li>That neither view has message properties that are missing their values (we aggresively use message properties to allow localization)</li>
<li>That both views contain a div with the id price that contains the text &#8220;45.67&#8243;</li>
<li>That the &#8220;large&#8221; view also contains a div with id kwh that contains &#8220;156&#8243; <strong>and</strong> a div with id &#8220;accountNumber&#8221; that contains &#8220;655321&#8243;</li>
</ul>
<h2>Getting fancy</h2>
<p>
Since this is just Scala code, you can use this to do more sophisitcated things:
</p>
<p><script src="https://gist.github.com/1226977.js?file=DSL.scala"></script></p>
<p>
I don&#8217;t know if the developers are totally in love with this DSL, but there&#8217;s so much you get for free, I&#8217;m certain they&#8217;d hate testing that by hand even more (or, worse, simply not test some of these things):</p>
<ul>
<li>You never have to remember to check for authentication requirements</li>
<li>You never have to remember to check for missing message properties</li>
<li>You can dynamically generates tests via test-data (as demonstrated above)</li>
<li>Because making a new data structure in Scala is so easy, you can make very fluent tests and test data.</li>
</ul>
<p>
Of course, this DSL is entirely useless to anyone but our web team.  It&#8217;s tailor-made to test our web product and our web product only.  The win, other than conciseness, readability, and brevity, was that this could be implemented and documented very quickly; I didn&#8217;t have to make the ultimate web-based tesitng DSL; just one that worked for our product.
</p>
<p>
If you are considering creating a DSL, keep this in mind: make it exactly right for you, and fight the urge to make it more general.  Also, don&#8217;t be afraid to use Scala for this; it&#8217;s much easier than Java, and you can fully type-check and document it very easily.  I should note that I intentionally used very few of Scala&#8217;s features to do this; developers only need to learn a few new concepts to understand what this code does.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.opower.com/2011/09/our-scala-dsl-for-testing-our-web-product/feed/</wfw:commentRss>
		<slash:comments>1358</slash:comments>
		</item>
		<item>
		<title>How One Line of Code Can Change the World</title>
		<link>http://blog.opower.com/2011/02/how-one-line-of-code-can-change-the-world/</link>
		<comments>http://blog.opower.com/2011/02/how-one-line-of-code-can-change-the-world/#comments</comments>
		<pubDate>Mon, 07 Feb 2011 14:18:00 +0000</pubDate>
		<dc:creator>Dave Copeland</dc:creator>
				<category><![CDATA[Opower Labs]]></category>

		<guid isPermaLink="false">http://www.heyitsopower.com/?p=405</guid>
		<description><![CDATA[From my recent talk at a recruiting event, a very quick Prezi: How One Line of Code Can Change The World on Prezi]]></description>
			<content:encoded><![CDATA[<p>From my recent talk at a recruiting event, a very quick <a href="www.prezi.com">Prezi</a>:</p>
<div class="prezi-player">
<style type="text/css" media="screen">.prezi-player { width: 550px; } .prezi-player-links { text-align: center; }</style>
<p><object id="prezi_5dpc5twja_kl" name="prezi_5dpc5twja_kl" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="550" height="400"><param name="movie" value="http://prezi.com/bin/preziloader.swf"/><param name="allowfullscreen" value="true"/><param name="allowscriptaccess" value="always"/><param name="bgcolor" value="#ffffff"/><param name="flashvars" value="prezi_id=5dpc5twja_kl&amp;lock_to_path=0&amp;color=ffffff&amp;autoplay=no&amp;autohide_ctrls=0"/><embed id="preziEmbed_5dpc5twja_kl" name="preziEmbed_5dpc5twja_kl" src="http://prezi.com/bin/preziloader.swf" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="550" height="400" bgcolor="#ffffff" flashvars="prezi_id=5dpc5twja_kl&amp;lock_to_path=0&amp;color=ffffff&amp;autoplay=no&amp;autohide_ctrls=0"></embed></object>
<div class="prezi-player-links">
<p><a title="" href="http://prezi.com/5dpc5twja_kl/how-one-line-of-code-can-change-the-world/">How One Line of Code Can Change The World</a> on <a href="http://prezi.com">Prezi</a></p>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.opower.com/2011/02/how-one-line-of-code-can-change-the-world/feed/</wfw:commentRss>
		<slash:comments>1991</slash:comments>
		</item>
		<item>
		<title>How to Get Hired: Polish</title>
		<link>http://blog.opower.com/2011/01/how-to-get-hired-polish/</link>
		<comments>http://blog.opower.com/2011/01/how-to-get-hired-polish/#comments</comments>
		<pubDate>Mon, 03 Jan 2011 17:51:54 +0000</pubDate>
		<dc:creator>Dave Copeland</dc:creator>
				<category><![CDATA[Opower Labs]]></category>

		<guid isPermaLink="false">http://www.heyitsopower.com/?p=386</guid>
		<description><![CDATA[It&#8217;s been several months, but we are still hiring like crazy, with no chance of stopping. We get a ton of résumés, and there are many internal hoops a candidate&#8217;s application package must jump through&#8230;]]></description>
			<content:encoded><![CDATA[<p>
It&#8217;s been several months, but we are still <a href="http://www.opowerjobs.com">hiring like crazy</a>, with no chance of stopping.  We get a ton of résumés, and there are many internal hoops a candidate&#8217;s application package must jump through before we bring someone in for an interview.  Our goal is for anyone who&#8217;s brought in for an in-person interview to have a very high likelihood of being extended an offer.  To that end, everything is reviewed by OPOWER developers directly.  Résumés go through an initial screening with our recruiters, but everything else goes straight to us, and we look at everything closely and carefully.
</p>
<p>
One thing I&#8217;ve noticed about successful candidates is <em>polish</em>.  This isn&#8217;t a word thrown around when discussing developers a whole lot, but I&#8217;ve found it to be a strong indicator of a true software professional.  The OPOWER application is more than just a résumé; it&#8217;s a written quiz and a coding assignment as well. Sloppiness at any point is a negative; it shows that the candidate just doesn&#8217;t give a shit about getting the job.  It&#8217;s not a deal-breaker, but it has a huge effect on how excited we get about a candidate, <strong>and</strong> it could be the deciding factor between two otherwise identical candidates.  It&#8217;s our version of <a href="http://gettingreal.37signals.com/ch08_Wordsmiths.php">&#8220;hire the better writer.&#8221;</a>
</p>
<p>
So, what do I mean by &#8220;polish&#8221;?  Here&#8217;s a few examples:</p>
<ul>
<li>Make your code <em>better</em> than you would &#8220;at work.&#8221;  Don&#8217;t make me download the JUnit jar and type <code>javac `find .  -name *.java`</code> to compile your code; give me a <code>pom.xml</code> or Ant file with Ivy support.</li>
<li>Send PDFs instead of MS-Word; they are so much easier on the eyes (and processor).  This is dead simple on OS X, <a href="http://www.cutepdf.com/products/cutepdf/writer.asp">there&#8217;s some free options for Windows</a>, and there&#8217;s always <a href="http://www.latex-project.org/">LaTeX</a> (which will definitely earn you some geek cred <img src='http://blog.opower.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
<li>Don&#8217;t send me the functional spec of your last project and call it a résumé.  Use bullet lists, short sentences, and formatting to create an easy-to-scan CV.</li>
<li>Format your writing; compare <a href="http://www.heyitsopower.com/wordpress/home/35481/domains/heyitsopower.com/html/wordpress/wp-content/uploads/2011/01/sloppy.jpg">this</a>, to <a href="http://www.heyitsopower.com/wordpress/home/35481/domains/heyitsopower.com/html/wordpress/wp-content/uploads/2011/01/polished.jpg">this</a>.  Even though they both are excerpts from correctly-answered quizzes, which one is going to be easier and more engaging for me to read?</li>
<li>English: <a href="http://www.imdb.com/title/tt0110912/quotes">do you speak it?</a>.  Being able to communicate effectively using the written word is absolutely <strong>crucial</strong> for being a good developer, especially at OPOWER.  It doesn&#8217;t need to be your first, or even best, language; you just need to wield it as effectively as you do Java</li>
</ul>
<p>
A lack of polish won&#8217;t get you refused, but putting an extra shine on your application can make you stand out quite a bit&hellip;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.opower.com/2011/01/how-to-get-hired-polish/feed/</wfw:commentRss>
		<slash:comments>1351</slash:comments>
		</item>
		<item>
		<title>Boxed primitives and ==</title>
		<link>http://blog.opower.com/2010/05/boxed-primitives-and/</link>
		<comments>http://blog.opower.com/2010/05/boxed-primitives-and/#comments</comments>
		<pubDate>Thu, 27 May 2010 15:25:06 +0000</pubDate>
		<dc:creator>Dave Copeland</dc:creator>
				<category><![CDATA[Opower Labs]]></category>

		<guid isPermaLink="false">http://www.heyitsopower.com/?p=215</guid>
		<description><![CDATA[One part of programming culture at OPOWER is to program defensively, providing useful information when contracts are violated. What does this have to do with boxed primitives? Getting an assertion message of &#8220;Person 1001&#8242;s customer&#8230;]]></description>
			<content:encoded><![CDATA[<p>One part of programming culture at OPOWER is to program defensively, providing useful information when contracts are violated.   What does this have to do with boxed primitives?  Getting an assertion message of &#8220;Person 1001&#8242;s customer id 109032 didn&#8217;t match the passed-in customer&#8217;s id of 109032&#8243; seemed logically impossible, but was somehow true.</p>
<p>But first, let&#8217;s talk about defensive coding and how we do it.  For example:</p>
<pre name="code" class="java">/**
 * frobs the bar and baz.
 * @param bar the bar to frob; may not be null
 * @param baz the baz to from; must be positive
 */
public String frob(String bar, int baz) {
  if (bar.length() &gt; baz) {
    return bar.substring(baz);
  }
  else {
    return bar;
  }
}</pre>
<p>If the contract is violated by the caller, we will get a <code>NullPointerException</code> or some other <code>StringIndexOutOfBoundsException</code>.  Not too helpful.  Instead, we use an internal validator helper class to provide useful messages.  This is <strong>crucial</strong> for properly understanding bugs that occur in production; there&#8217;s nothing worse than coming into work to find a <code>NullPointerException</code> in your inbox and no clue what went wrong.</p>
<pre name="code" class="java">/**
 * frobs the bar and baz.
 * @param bar the bar to frob; may not be null
 * @param baz the baz to from; must be positive
 */
public String frob(String bar, int baz) {
  Validate.notNull(bar,"bar must not be null to frob");
  Validate.isTrue(baz &gt; 0,"baz must be positive");
  if (bar.length() &gt; baz) {
    return bar.substring(baz);
  }
  else {
    return bar;
  }
}</pre>
<p><code>Validate.*</code>  methods essentially throw <code>IllegalArgumentException</code> if what they are checking for fails.<br />
We use this pattern extensively, even in constructors of simple data-structure style objects.  This (plus keeping this things immutable) allows users of these objects to safely rely upon the <code>get</code> methods behaving properly. I had need of a class to hold both a <code>Person</code> (representing a website user) and a <code>Customer</code> (representing a utility-company customer).  This class (called, naturally, <code>PersonAndCustomer</code>), takes both objects in its constructor and requires that they are both non-null.  As a further sanity check, I wanted to make sure that the <code>Person</code>&#8216;s <code>customerId</code> matched the id of the <code>Customer</code> that was being passed in (i.e. that they represented the same actual human in the real world):</p>
<pre name="code" class="java">public PersonAndCustomer(Person p, Customer c) {
  Validate.notNull(p,"Person may not be null");
  Validate.notNull(c,"Customer may not be null");
  Validate.isTrue(p.getCustomerId() == c.getId(),
    "Person %d's customer id %d didn't match passed-in customer's id %d",
    p.getId(),
    p.getCustomerId(),
    c.getId());
  ...
}</pre>
<p>Looks pretty inocuous, right?  Well, because these objects are Hibernate-managed, all of our ids are <code>Long</code> and not <code>long</code>.  So, my <code>isTrue</code> validation is really checking that the person&#8217;s <code>customerId</code> <em>object</em> is the <em>same object</em> as the customer&#8217;s <code>id</code> object.  What&#8217;s worse, in several months of development and production deployment, these two objects <em>happened to be the same</em>.</p>
<p>Until this week; we were testing our application for a new client and I got the error posted above (&#8220;Person 1001&#8242;s customer id 109032 didn&#8217;t match the passed-in customer&#8217;s id of 109032&#8243;).  It seems that much like how the JVM will re-use string objects, it also will sometimes re-use boxed objects as well.  But not always.  The fix for this is obvious, but I wanted to make sure I could actually recreate this situation.  So, I created a test that gave both the <code>Person</code> and <code>Customer</code> the same <em>value</em> for the customer id, but as different objects. and verified that the class could still be constructed.  Sure enough, the test failed.  The fix:</p>
<pre name="code" class="java">public PersonAndCustomer(Person p, Customer c) {
  Validate.notNull(p,"Person may not be null");
  Validate.notNull(c,"Customer may not be null");
  Validate.isTrue(p.getCustomerId().equals(c.getId()),
    "Person %d's customer id %d didn't match passed-in customer's id %d",
    p.getId(),
    p.getCustomerId(),
    c.getId());
  ...
}</pre>
<p>What&#8217;s interesting is that if one end of the <code>==</code> is a primitive, the JVM will unbox the other one and the test succeeds:</p>
<pre name="code" class="java">Long l1 = new Long(45L);
Long l2 = new Long(45L);

System.out.println(l1 == l2);      // false
System.out.println(l1.equals(l2)); // true
System.out.println(l1 == 45L);     // true!</pre>
<p>The moral of the story is to always know what you are comparing.  Might even be best to always use <code>.equals()</code> unless the compiler complains.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.opower.com/2010/05/boxed-primitives-and/feed/</wfw:commentRss>
		<slash:comments>42</slash:comments>
		</item>
		<item>
		<title>Dave&#8217;s Talk at ScalaDays 2010</title>
		<link>http://blog.opower.com/2010/05/daves-talk-at-scaladays-2010/</link>
		<comments>http://blog.opower.com/2010/05/daves-talk-at-scaladays-2010/#comments</comments>
		<pubDate>Mon, 03 May 2010 10:29:26 +0000</pubDate>
		<dc:creator>Dave Copeland</dc:creator>
				<category><![CDATA[Opower Labs]]></category>

		<guid isPermaLink="false">http://www.heyitsopower.com/?p=188</guid>
		<description><![CDATA[OPOWER graciously sent me to Switzerland this year for ScalaDays 2010. I was lucky enough to be asked to present on &#8220;Sneaking Scala into the Enterprise&#8221;. OPOWER sponsored the videography. My talk, on starting to&#8230;]]></description>
			<content:encoded><![CDATA[<p>OPOWER graciously sent me to Switzerland this year for ScalaDays 2010.  I was lucky enough to be asked to present on &#8220;Sneaking Scala into the Enterprise&#8221;.  OPOWER sponsored the videography.  My talk, on starting to use Scala in your organization (based on my experience at OPOWER), is linked below; all the talks are online <a href="http://days2010.scala-lang.org/node/136">here</a>.<br />
<a href="http://days2010.scala-lang.org/node/138/169"><img class="alignnone size-full wp-image-189" title="Video | Scala Days 2010" src="http://www.heyitsopower.com/wordpress/home/35481/domains/heyitsopower.com/html/wordpress/wp-content/uploads/2010/04/Video-Scala-Days-2010.jpg" alt="Video | Scala Days 2010" width="648" height="388" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.opower.com/2010/05/daves-talk-at-scaladays-2010/feed/</wfw:commentRss>
		<slash:comments>1193</slash:comments>
		</item>
		<item>
		<title>Tie Tuesday &#8211; more fun that it sounds</title>
		<link>http://blog.opower.com/2010/01/tie-tuesday-more-fun-that-it-sounds/</link>
		<comments>http://blog.opower.com/2010/01/tie-tuesday-more-fun-that-it-sounds/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 14:56:28 +0000</pubDate>
		<dc:creator>Dave Copeland</dc:creator>
				<category><![CDATA[Opower Labs]]></category>

		<guid isPermaLink="false">http://www.heyitsopower.com/?p=183</guid>
		<description><![CDATA[The developers have an informal &#8220;Tie Tuesday&#8221; each work. It&#8217;s exactly what it sounds like. And, since you asked, yes, it is more fun to wear a tie when you don&#8217;t have to. Not everyone&#8230;]]></description>
			<content:encoded><![CDATA[<p>
The developers have an informal &#8220;Tie Tuesday&#8221; each work.  It&#8217;s exactly what it sounds like.  And, since you asked, yes, it is more fun to wear a tie when you don&#8217;t have to.  Not everyone does it every week, but this week, we had the best participation yet:
</p>
<div id="attachment_182" class="wp-caption alignnone" style="width: 535px"><img src="http://www.heyitsopower.com/wordpress/home/35481/domains/heyitsopower.com/html/wordpress/wp-content/uploads/2010/01/our-opower-mascot-on-tie-tuesday.jpeg" alt="Riley Dawg participates in tie tuesday" title="Our Mascot on Tie Tuesday" width="525" height="700" class="size-full wp-image-182" /><p class="wp-caption-text">Riley Dawg participates in tie tuesday</p></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.opower.com/2010/01/tie-tuesday-more-fun-that-it-sounds/feed/</wfw:commentRss>
		<slash:comments>317</slash:comments>
		</item>
		<item>
		<title>When adding more threads makes it all slower</title>
		<link>http://blog.opower.com/2009/11/when-adding-more-threads-makes-it-all-slower/</link>
		<comments>http://blog.opower.com/2009/11/when-adding-more-threads-makes-it-all-slower/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 18:07:25 +0000</pubDate>
		<dc:creator>Dave Copeland</dc:creator>
				<category><![CDATA[Opower Labs]]></category>
		<category><![CDATA[scaling]]></category>
		<category><![CDATA[threads]]></category>

		<guid isPermaLink="false">http://www.heyitsopower.com/?p=154</guid>
		<description><![CDATA[I&#8217;ve been working on a new feature that requires analysis of each individual&#8217;s entire energy-use history. In other words, I have a process that will touch every single bit of data in our database. This&#8230;]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a new feature that requires analysis of each individual&#8217;s entire energy-use history.  In other words, I have a process that will touch <strong>every single bit of data</strong> in our database. This should be a rare thing, so if it takes a while, it&#8217;s not that big of a deal.  My initial implementation was on track to complete in&#8230;11 days.</p>
<p>My first thought was: there&#8217;s lots of blocking reading and writing from the database, so adding some threads should speed things up.  While one thread was analyzing Bob&#8217;s energy data, another could be fetching Mary&#8217;s, while another could be updating Joe&#8217;s meta-data with the results.  Or so I thought.</p>
<p>The more threads I added, the slower the entire thing became.  It turned out that <strong>the fastest implementation was a single-threaded one</strong>.  But why?  It all has to do with the diminishing returns one gets from scaling out.</p>
<p>If you think of a task as having a serial component, which cannot be broken up concurrently, and then multiple tasks which <strong>can</strong> be done concurrently, we can analyze the returns we get by increasing the number of available processors (threads, in my case).  This is <a href="http://en.wikipedia.org/wiki/Amdahl%27s_law">Amdahl&#8217;s Law</a> and is exemplified by the following equation (where &#8220;x&#8221; is the number of processors or threads, and &#8220;s&#8221; is the percentage of your overall task that must be serialized; &#8220;y&#8221; is the increase in speed you will see from scaling).<br />
<img class="alignnone size-full wp-image-157" title="Amdahl's Equation" src="http://www.heyitsopower.com/wordpress/home/35481/domains/heyitsopower.com/html/wordpress/wp-content/uploads/2009/11/amdahl.png" alt="Amdahl's Equation" width="97" height="34" /></p>
<p>When you graph this, it&#8217;s pretty obvious that there are diminishing returns to adding more threads/processors (the graph below assumes that 90% of the overall job can be done concurrently).  As we add threads, we get less and less of a gain in speed.<br />
But there&#8217;s still a gain to get, so what happened to me?</p>
<p><img class="alignnone size-medium wp-image-165" title="Graph of Amdahl's Equation with 10% of our task serialized" src="http://www.heyitsopower.com/wordpress/home/35481/domains/heyitsopower.com/html/wordpress/wp-content/uploads/2009/11/Picture-3-300x106.png" alt="Graph of Amdahl's Equation with 10% of our task serialized" width="300" height="106" /></p>
<p>Amdahl&#8217;s law is actually pretty optimistic.  It doesn&#8217;t account for the overhead required to synchronize the shared data.  If we account for this, with a new value &#8220;k&#8221; ( the percentage penalty for maintaining consistency), we see that increasing our processors/threads actually starts to hurt us (this equation is in red)!</p>
<p><img class="alignnone size-medium wp-image-161" title="Taking shared state synchronization into account" src="http://www.heyitsopower.com/wordpress/home/35481/domains/heyitsopower.com/html/wordpress/wp-content/uploads/2009/11/Coherence-300x105.png" alt="Taking shared state synchronization into account" width="300" height="105" /></p>
<p>In my case, almost all of this synchronization is happening within the database; it turns out that almost all the time my process needs is accessing data from the database.  So, I dialed it down to only one thread, and we should be done early next week.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.opower.com/2009/11/when-adding-more-threads-makes-it-all-slower/feed/</wfw:commentRss>
		<slash:comments>1163</slash:comments>
		</item>
		<item>
		<title>Slides on Improving Your Agile Development Process</title>
		<link>http://blog.opower.com/2009/10/slides-on-improving-your-agile-development-process/</link>
		<comments>http://blog.opower.com/2009/10/slides-on-improving-your-agile-development-process/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 14:32:40 +0000</pubDate>
		<dc:creator>Dave Copeland</dc:creator>
				<category><![CDATA[Opower Labs]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[devdays]]></category>
		<category><![CDATA[process improvement]]></category>

		<guid isPermaLink="false">http://www.heyitsopower.com/?p=131</guid>
		<description><![CDATA[Dead last, after the headline act, and after Joel Spolsky told everyone to go home, I did a lightning talk at DC&#8217;s recent DevDays (A StackOverflow production) on how we have used process metrics from&#8230;]]></description>
			<content:encoded><![CDATA[<p>Dead last, after the headline act, and after Joel Spolsky told everyone to go home, I did a lightning talk at DC&#8217;s recent DevDays (<a href="http://www.stackoverflow.com">A StackOverflow</a> production) on how we have used <a href="/development/measuring-our-awesomeness-iteration-by-iteration/">process metrics</a> from our bug tracker to improve our process.</p>
<div id="__ss_2359457" style="width: 425px; text-align: left;"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" title="Improving your Agile Process" href="http://www.slideshare.net/davetron5000/measuring-agile-process-shorter-2359457">Improving your Agile Process</a><object style="margin:0px" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=measuringagileprocess-shorter-091027130310-phpapp01&amp;rel=0&amp;stripped_title=measuring-agile-process-shorter-2359457" /><param name="allowfullscreen" value="true" /><embed style="margin:0px" type="application/x-shockwave-flash" width="425" height="355" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=measuringagileprocess-shorter-091027130310-phpapp01&amp;rel=0&amp;stripped_title=measuring-agile-process-shorter-2359457" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<div style="font-size: 11px; font-family: tahoma,arial; height: 26px; padding-top: 2px;">View more <a style="text-decoration:underline;" href="http://www.slideshare.net/">documents</a> from <a style="text-decoration:underline;" href="http://www.slideshare.net/davetron5000">David Copeland</a>.</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.opower.com/2009/10/slides-on-improving-your-agile-development-process/feed/</wfw:commentRss>
		<slash:comments>761</slash:comments>
		</item>
		<item>
		<title>A year-long analysis of snack consumption</title>
		<link>http://blog.opower.com/2009/08/a-year-long-analysis-of-snack-consumption/</link>
		<comments>http://blog.opower.com/2009/08/a-year-long-analysis-of-snack-consumption/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 18:53:27 +0000</pubDate>
		<dc:creator>Dave Copeland</dc:creator>
				<category><![CDATA[Opower Labs]]></category>
		<category><![CDATA[doritos]]></category>
		<category><![CDATA[snacks]]></category>

		<guid isPermaLink="false">http://www.heyitsopower.com/?p=43</guid>
		<description><![CDATA[Consistently, month after month, the chips that get left in the giant &#8216;box-o-free-snacks&#8217; are: Nacho Cheese Doritos. Honorable Mentions: Fritos and Cool Ranch Doritos.]]></description>
			<content:encoded><![CDATA[<p>Consistently, month after month, the chips that get left in the giant &#8216;box-o-free-snacks&#8217; are:
</p>
<p>
<img src="http://www.heyitsopower.com/wordpress/wp-content/uploads/2009/08/IMG_0255-1024x768.jpg" alt="Doritos Are No Bueno" title="Doritos Are No Bueno" width="768" class="alignnone size-large wp-image-42" /></p>
<p>
Nacho Cheese Doritos.
</p>
<p>
<em>Honorable Mentions: Fritos and Cool Ranch Doritos</em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.opower.com/2009/08/a-year-long-analysis-of-snack-consumption/feed/</wfw:commentRss>
		<slash:comments>42</slash:comments>
		</item>
		<item>
		<title>Measuring our awesomeness iteration by iteration</title>
		<link>http://blog.opower.com/2009/08/measuring-our-awesomeness-iteration-by-iteration/</link>
		<comments>http://blog.opower.com/2009/08/measuring-our-awesomeness-iteration-by-iteration/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 12:00:47 +0000</pubDate>
		<dc:creator>Dave Copeland</dc:creator>
				<category><![CDATA[Opower Labs]]></category>
		<category><![CDATA[process improvment]]></category>
		<category><![CDATA[qa]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[sinatra]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.heyitsopower.com/?p=4</guid>
		<description><![CDATA[<p>
Like a lot of startups (and big companies!) we use iterative development: we break up our work into "stories" describing features and implement as many as we can in one month.  We then repeat that until we conquer the world.  But, if we can do more, or work more efficiently with each iteration, our goal of world domination will approach that much quicker :)
</p>
<p>
The easiest way to do that is to look at the bugs our QA staff find in the product updates.  Although we have a lot of automated tests, we still need some eyes on the applications to check for things like text overruns of our printed reports, or JavaScript weirdness in some <a href="http://blog.digg.com/?p=878">less-than-well-behaved</a>) browsers.
</p>]]></description>
			<content:encoded><![CDATA[<p>
Like a lot of startups (and big companies!) we use iterative development: we break up our work into &#8220;stories&#8221; describing features and implement as many as we can in one month.  We then repeat that until we conquer the world.  But, if we can do more, or work more efficiently with each iteration, our goal of world domination will approach that much quicker <img src='http://blog.opower.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
</p>
<p>
The easiest way to do that is to look at the bugs our QA staff find in the product updates.  Although we have a lot of automated tests, we still need some eyes on the applications to check for things like text overruns of our printed reports, or JavaScript weirdness in some <a href="http://blog.digg.com/?p=878">less-than-well-behaved</a>) browsers.
</p>
<p>
After a few iterations, Anh (our beloved program manager) ran some queries on our bug-tracking database and, using some Excel magic, showed us numbers like &#8220;number of defects in the web application&#8221; and &#8220;average number of days a critical bug sat unassigned&#8221;.  This is good stuff; seeing hard data about what we&#8217;re doing lets us focus on inefficiency.  Since we release software every month (and launch new clients almost as frequently), this is a <b>huge</b> help in making each iteration better than the previous.
</p>
<p>
While Anh&#8217;s hand-jammed report was awesome, manually connecting SQLite and Excel is no fun for anyone.  I whipped up a basic Ruby application using <a href="http://www.sinatrarb.com/">Sinatra</a> to automate most of what we&#8217;d like to see.  We can now see how long critical defects site open and unfixed, as well as how many overall defects we&#8217;re fixing and even the <i>root source</i> of our defects (e.g. did we get the wrong requirements, or just mess up implementing them?)
</p>
<p>
We still need to show trends, however.  &#8220;Classic&#8221; thinking in software process improvement says to do that by dividing everything by lines of code; if we had 10 defects per 1,000 lines of code this month, but only 8 the following, we&#8217;re doing better.  This is not a great measure for us, since we are changing and enhancing our product (as opposed to writing fresh code each time), so we decided to normalize our measurements by the story points we assigned to the iteration.  This way, we can see charts like the one below (which says we are doing better each time):
</p>
<p><img src="http://www.heyitsopower.com/wordpress/wp-content/uploads/2009/08/MetricsChart.png" alt="Metrics Chart" title="Metrics Chart" width="442" height="314" class="alignnone size-full wp-image-7" /></p>
<p>
This information is dead simple to collect; the burden on developers and testers when writing defects is almost nothing.  With only a priority, severity, and &#8220;source of defect&#8221;, we can collect a lot of advanced information about our development process &mdash; and make it better iteration by iteration.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.opower.com/2009/08/measuring-our-awesomeness-iteration-by-iteration/feed/</wfw:commentRss>
		<slash:comments>1162</slash:comments>
		</item>
	</channel>
</rss>
