<story><title>When setting an environment variable gives you a 40x speedup</title><url>https://news.sherlock.stanford.edu/posts/when-setting-an-environment-variable-gives-you-a-40-x-speedup</url></story><parent_chain></parent_chain><comment><author>mrb</author><text>Story time.&lt;p&gt;This took place around 2009. Back then I was working for Rapid7, on their network vulnerability scanner Nexpose. The codebase was mostly Java and was relatively large at 1M+ lines of code. We had many unit tests. Running the entire test suite took up to 40 minutes on Windows, and 20 minutes on Linux (Windows was always about twice slower on everything: building, product&amp;#x27;s startup time, etc.) The company had grown quickly to at least 30-50 software engineers. The problem was that every time one of them ran a build on his or her local machine (which happened multiple times a day) it would have to run the test suite and waste up to 40 minutes of this person&amp;#x27;s time. 40 minutes × dozens of engineers = lots of inefficiencies in the company.&lt;p&gt;I loved solving performance issues so one day I remember arriving at the office and making it my mission to investigate if there was an easy way to speed up the test suite. Our build system was based on Ant, and our tests used the JUnit framework. After a little time profiling Ant with basic tools (top, strace, ltrace), and taking a few Java stack traces, I realized that most of the wasted time was not actually running the individual tests, but many instances of the JVM kept being started and destroyed between each test. Our Ant build file was running the JUnit test with fork=yes, which was required for a reason I don&amp;#x27;t recall at the moment. This forks the JVM for running the tests. Then a little googling lead me to this:&lt;p&gt;&lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;ant.apache.org&amp;#x2F;manual&amp;#x2F;Tasks&amp;#x2F;junit.html&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;ant.apache.org&amp;#x2F;manual&amp;#x2F;Tasks&amp;#x2F;junit.html&lt;/a&gt;&lt;p&gt;While reading this documentation, I stumbled upon an unknown parameter to me: forkmode. What does it do?&lt;p&gt;&amp;quot;&lt;i&gt;forkmode: Controls how many JVMs get created if you want to fork some tests. Possible values are perTest (the default), perBatch and once. once creates only a single JVM for all tests while perTest creates a new JVM for each TestCase class. perBatch creates a JVM for each nested &amp;lt;batchtest&amp;gt; and one collecting all nested &amp;lt;test&amp;gt;s.&lt;/i&gt;&amp;quot;&lt;p&gt;Our Ant build file did not set forkmode, so it meant we were forking a new JVM for every test!&lt;p&gt;I immediately tried forkmode=perBatch and... the test suite ran 10× faster! 40 minutes down to 4 minutes on Windows. And Linux ran it in 2 minutes instead of 20 minutes. I told my boss right away but he was unbelieving. He asked that I check with our most-experienced Java developer. I showed him my 1-line patch speeding the test suite 10× and he said &amp;quot;I guess you are right, we can commit that.&amp;quot; By lunch time the fix was committed and everyone loved me :)</text></comment>
<story><title>When setting an environment variable gives you a 40x speedup</title><url>https://news.sherlock.stanford.edu/posts/when-setting-an-environment-variable-gives-you-a-40-x-speedup</url></story><parent_chain></parent_chain><comment><author>CaliforniaKarl</author><text>This was written by my coworker, Kilian Cavalotti.  We have two main file stores: $SCRATCH is a Lustre cluster, which is extremely performant but doesn&amp;#x27;t do well with lots of inodes.  And $HOME is a multi-node Isilon, which can handle all the inodes, but is not as performant.  And we have users who sometimes like to put many files in single directories.&lt;p&gt;You can find more information about us at &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;srcc.stanford.edu&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;srcc.stanford.edu&lt;/a&gt;&lt;p&gt;And you can find more information about Sherlock at &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;www.sherlock.stanford.edu&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;www.sherlock.stanford.edu&lt;/a&gt;</text></comment>