<?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>t h e D a v i d A i k e n &#187; Parallel</title>
	<atom:link href="http://www.davidaiken.com/tag/parallel/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.davidaiken.com</link>
	<description>Not Statistically Significant</description>
	<lastBuildDate>Wed, 16 Nov 2011 04:04:31 +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>Speed up your workers with .net 4.0 parallel extensions</title>
		<link>http://www.davidaiken.com/2010/06/09/speed-up-your-workers-with-net-4-0-parallel-extensions/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.davidaiken.com/2010/06/09/speed-up-your-workers-with-net-4-0-parallel-extensions/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 15:06:56 +0000</pubDate>
		<dc:creator>theDavidAiken</dc:creator>
				<category><![CDATA[Windows Azure]]></category>
		<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[Parallel]]></category>

		<guid isPermaLink="false">http://www.davidaiken.com/2010/06/09/speed-up-your-workers-with-net-4-0-parallel-extensions/</guid>
		<description><![CDATA[Now you can use .net 4.0 in Windows Azure, it opens up some possibilities to get even more out of your workers. If you have workers that read messages from queues, then do some processing against storage, you may want to consider converting your message processing loops into parallel loops.
Here is  [...]]]></description>
			<content:encoded><![CDATA[<p>Now you can use .net 4.0 in Windows Azure, it opens up some possibilities to get even more out of your workers. If you have workers that read messages from queues, then do some processing against storage, you may want to consider converting your message processing loops into parallel loops.</p>
<p>Here is the shell of some code and a typical pattern:</p>
<pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">foreach</span> (var s <span style="color: #0000ff">in</span> masterList)
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">{
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #008000">// Do some work with s</span>
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">}</pre>
</pre>
<p>You can very easily convert this to use the parallel extensions by using the following code:</p>
<pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">Parallel.ForEach(masterList, s =&gt;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">{
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #008000">// Do some work with s</span>
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">}
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">);</pre>
</pre>
<p>So the code change is easy, but what is the difference? </p>
<p>Well you should certainly consider how much work you are doing for each message – short simple tasks probably won’t benefit from being parallel.</p>
<p>You should also consider how much IO is performed against storage etc. – the more IO performed the more you will benefit from using the extensions.</p>
<p>But David PLEASE GIVE ME SOME FIGURES.</p>
<p>Ok – here is the low down.</p>
<p>The code I have reads some data from a collection (loaded from a blob) then writes a row into table storage for each item in the collection. There is a total of 748 items in the collection spread across 7 partitions.</p>
<p>Without the parallel extension the results look like this across 3 identical runs:</p>
<table border="1" cellspacing="0" cellpadding="2" width="500">
<tbody>
<tr>
<td valign="top" width="100">&#160;</td>
<td valign="top" width="100">1</td>
<td valign="top" width="100">2</td>
<td valign="top" width="100">3</td>
</tr>
<tr>
<td valign="top" width="100">Start Time</td>
<td valign="top" width="100">13:55:01.4366386</td>
<td valign="top" width="100">14:04:59.5006458</td>
<td valign="top" width="100">14:08:37.6709250</td>
</tr>
<tr>
<td valign="top" width="100">End Time</td>
<td valign="top" width="100">13:55:36.2911237</td>
<td valign="top" width="100">14:05:28.4387517</td>
<td valign="top" width="100">14:09.20.3591933</td>
</tr>
</tbody>
</table>
<p>No I don’t know what happened to the last one, but its around ~35 seconds or about 21 entities per second.</p>
<p>With the parallel extensions the results are:</p>
<table border="1" cellspacing="0" cellpadding="2" width="500">
<tbody>
<tr>
<td valign="top" width="125">&#160;</td>
<td valign="top" width="125">1</td>
<td valign="top" width="125">2</td>
<td valign="top" width="125">3</td>
</tr>
<tr>
<td valign="top" width="125">Start Time</td>
<td valign="top" width="125">14:23:51.2536114</td>
<td valign="top" width="125">14:28:54.6648367</td>
<td valign="top" width="125">14:31:58.3643092</td>
</tr>
<tr>
<td valign="top" width="125">End Time</td>
<td valign="top" width="125">14:24.03.0634712</td>
<td valign="top" width="125">14:29:08.3145661</td>
<td valign="top" width="125">14:32:10.2021354</td>
</tr>
</tbody>
</table>
<p>That is a tad faster at ~14 seconds or about 53 entities per second (probably faster as I’m being generous here).</p>
<p>The tests were all done using a small VM size (1 core) and the tables etc. were deleted between tests. It’s not terribly scientific, but its good enough to show its worth looking into.</p>
<p>For a simple code change, that is not a bad days work.</p>
<p>You can find out some more about the extensions at <a title="http://msdn.microsoft.com/en-us/library/dd460693.aspx" href="http://msdn.microsoft.com/en-us/library/dd460693.aspx">http://msdn.microsoft.com/en-us/library/dd460693.aspx</a> as well as the C9 10-4 show at <a title="http://channel9.msdn.com/shows/10-4/10-4-Episode-6-Parallel-Extensions/" href="http://channel9.msdn.com/shows/10-4/10-4-Episode-6-Parallel-Extensions/">http://channel9.msdn.com/shows/10-4/10-4-Episode-6-Parallel-Extensions/</a>.</p>
<p>THIS POSTING IS PROVIDED “AS IS” WITH NO WARRANTIES, AND CONFERS NO RIGHTS, NOBODY EVER READS THIS BIT EITHER SO I DON’T EVEN KNOW WHY I BOTHER SOMETIMES</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidaiken.com/2010/06/09/speed-up-your-workers-with-net-4-0-parallel-extensions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

