<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Mark S. Rasmussen - Blog</title>
	
	<link>http://improve.dk</link>
	<description />
	<lastBuildDate>Thu, 23 May 2013 09:00:50 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Improvedk" /><feedburner:info uri="improvedk" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Could Not Load Type ‘NewRelic.Agent.Core.AgentApi’</title>
		<link>http://feedproxy.google.com/~r/Improvedk/~3/tHQNBwnHAvw/</link>
		<comments>http://improve.dk/could-not-load-type-newrelic-agent-core-agentapi/#comments</comments>
		<pubDate>Thu, 23 May 2013 09:00:50 +0000</pubDate>
		<dc:creator>Mark S. Rasmussen</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[New Relic]]></category>
		<category><![CDATA[TypeLoadException]]></category>

		<guid isPermaLink="false">http://improve.dk/?p=3392</guid>
		<description><![CDATA[<p>Recently I&#8217;ve begun using New Relic, and so far it&#8217;s been an excellent experience. About two weeks ago I started using their .NET Agent API to customize some of the data reported by our application to their servers. This makes the data way more valuable to us as we can now selectively ignore certain parts of our application while getting better reporting from other, more critical, parts of the application. Random Outages Unfortunately, in the last couple of weeks, ever [...]</p><p>The post <a href="http://improve.dk/could-not-load-type-newrelic-agent-core-agentapi/">Could Not Load Type &#8216;NewRelic.Agent.Core.AgentApi&#8217;</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Recently I&#8217;ve begun using <a href="http://newrelic.com/">New Relic</a>, and so far it&#8217;s been an excellent experience. About two weeks ago I started using their <a href="https://newrelic.com/docs/dotnet/the-net-agent-api">.NET Agent API</a> to customize some of the data reported by our application to their servers. This makes the data way more valuable to us as we can now selectively ignore certain parts of our application while getting better reporting from other, more critical, parts of the application.</p>

<h2>Random Outages</h2>
<p>Unfortunately, in the last couple of weeks, ever since introducing the .NET Agent API, we&#8217;ve had a number of outages (thankfully invisible to the customers due to a self-healing load-balancer setup shielding the individual application servers) where one of our applications servers would randomly start throwing the same exception on all requests:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="csharp"><pre class="de1"><span class="kw5">System</span><span class="sy0">.</span><span class="me1">TypeLoadException</span><span class="sy0">:</span> Could not load type <span class="st0">'NewRelic.Agent.Core.AgentApi'</span> <span class="kw1">from</span> assembly <span class="st0">'NewRelic.Api.Agent, Version=2.5.112.0, Culture=neutral, PublicKeyToken=06552fced0b33d87'</span><span class="sy0">.</span> 
<span class="me1">at</span> NewRelic<span class="sy0">.</span><span class="me1">Api</span><span class="sy0">.</span><span class="me1">Agent</span><span class="sy0">.</span><span class="me1">NewRelic</span><span class="sy0">.</span><span class="me1">SetTransactionName</span><span class="br0">&#40;</span><span class="kw4">String</span> category, <span class="kw4">String</span> name<span class="br0">&#41;</span> 
at <span class="kw5">System.<span class="me1">Web</span></span><span class="sy0">.</span><span class="me1">HttpApplication</span><span class="sy0">.</span><span class="me1">SyncEventExecutionStep</span><span class="sy0">.</span><span class="kw5">System.<span class="me1">Web</span></span><span class="sy0">.</span><span class="me1">HttpApplication</span><span class="sy0">.</span><span class="me1">IExecutionStep</span><span class="sy0">.</span><span class="me1">Execute</span><span class="br0">&#40;</span><span class="br0">&#41;</span> 
at <span class="kw5">System.<span class="me1">Web</span></span><span class="sy0">.</span><span class="me1">HttpApplication</span><span class="sy0">.</span><span class="me1">ExecuteStep</span><span class="br0">&#40;</span>IExecutionStep step, Boolean<span class="sy0">&amp;</span> completedSynchronously<span class="br0">&#41;</span></pre></div></div></div></div></div></div></div>




<p>The error seemed to crop up randomly on all of our servers, though not at the same time and in with no predictable patterns &#8211; except it was always just after an application pool recycle. Once the error occurred it would continue happening until we either recycled the pool manually or it was recycled automatically according to its schedule.</p>

<h2>The Support Experience</h2>
<p>To make a long story short, I opened a support case with New Relic as I couldn&#8217;t find anything in neither their docs, nor on Google, related to the specific exception. After about a week of going back and forth between their engineers and me they managed to track down the root cause:</p>

<blockquote>It appears that some of the caching we do is not being correctly invalidated. I have removed the caching code and you should see this fix in our next release.</blockquote>

<p>In the meantime I&#8217;ve had to stop using the .NET Agent API to avoid the issue from happening again. This doesn&#8217;t mean we won&#8217;t get any data; it&#8217;s just not as well polished as before. I&#8217;m eagerly looking forward to the next agent release so we can get back to using the .NET Agent API again.</p>

<p>In conclusion I must say I&#8217;m impressed by the overall support experience. The responses have been quick and professional. Naturally I&#8217;d prefer not to have had any issues, but we all know they can happen, and in those cases it&#8217;s a matter of having a solid triage process &#8211; and in this case I&#8217;m just happy to be able to assist in identifying the cause.</p><p>The post <a href="http://improve.dk/could-not-load-type-newrelic-agent-core-agentapi/">Could Not Load Type &#8216;NewRelic.Agent.Core.AgentApi&#8217;</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p><img src="http://feeds.feedburner.com/~r/Improvedk/~4/tHQNBwnHAvw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://improve.dk/could-not-load-type-newrelic-agent-core-agentapi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://improve.dk/could-not-load-type-newrelic-agent-core-agentapi/</feedburner:origLink></item>
		<item>
		<title>Partial DNS Forwarding Using Individual Windows DNS Zones</title>
		<link>http://feedproxy.google.com/~r/Improvedk/~3/Pk0JoWZo-Fg/</link>
		<comments>http://improve.dk/partial-dns-forwarding-using-individual-windows-dns-zones/#comments</comments>
		<pubDate>Tue, 21 May 2013 13:52:50 +0000</pubDate>
		<dc:creator>Mark S. Rasmussen</dc:creator>
				<category><![CDATA[Windows]]></category>
		<category><![CDATA[DNS]]></category>
		<category><![CDATA[Forwarding]]></category>
		<category><![CDATA[Zone]]></category>

		<guid isPermaLink="false">http://improve.dk/?p=3205</guid>
		<description><![CDATA[<p>At our office, all machines are using a local Windows DNS server for their outgoing DNS queries. This allows us to make internal zones like .ipaperlan that points to all of our internal systems, while setting up the DNS server to forward all unknown queries to Google DNS. One feature I&#8217;m missing in the standard Windows DNS server is the option to partially forward individual zones. However, there is a workaround that will allow you to setup partial DNS forwarding [...]</p><p>The post <a href="http://improve.dk/partial-dns-forwarding-using-individual-windows-dns-zones/">Partial DNS Forwarding Using Individual Windows DNS Zones</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>At our office, all machines are using a local Windows DNS server for their outgoing DNS queries. This allows us to make internal zones like .ipaperlan that points to all of our internal systems, while setting up the DNS server to forward all unknown queries to Google DNS. One feature I&#8217;m missing in the standard Windows DNS server is the option to partially forward individual zones. However, there is a workaround that will allow you to setup partial DNS forwarding using individual Windows DNS zones.</p>

<h2>The Scenario</h2>

<p>Imagine you have a domain <i>improve.dk</i> that already has a number of public DNS records like the following.</p>

<div class='imgwrapper'><div><a href="http://improve.dk/wp-content/uploads/2013/03/Capture.png"><img src="http://improve.dk/wp-content/uploads/2013/03/Capture.png" alt="Capture" width="730" height="85" class="alignnone size-full wp-image-3207" /></a></div></div>

</p>In this case all I want to do is to add a record on our internal network, <i>jira.improve.dk</i>. As this record should only be made available internally, we can&#8217;t just add it to the public DNS records for the domain.</p>

<p>I could make a new DNS zone for the improve.dk domain in our local DNS server, but that would result in all DNS queries for improve.dk being answered by our local DNS server, rather than being forwarded. As long as I recreate all public DNS records in our local DNS server, this would work fine, but it&#8217;s not a viable solution as I&#8217;d now have to keep the two DNS setups in sync manually.</p>

<h2>The Solution</h2>

<p>Instead of creating a zone for the whole improve.dk domain, you can make a zone specifically for just the record you need to add. First right click &#8220;Forward Lookup Zones&#8221; and select &#8220;New Zone&#8230;&#8221; and then follow these steps (pretty much all defaults):</p>

<div class='imgwrapper'><div><a href="http://improve.dk/wp-content/uploads/2013/03/1.png"><img src="http://improve.dk/wp-content/uploads/2013/03/1.png" alt="1" width="500" height="381" class="alignnone size-full wp-image-3208" /></a></div></div>

<div class='imgwrapper'><div><a href="http://improve.dk/wp-content/uploads/2013/03/2.png"><img src="http://improve.dk/wp-content/uploads/2013/03/2.png" alt="2" width="502" height="384" class="alignnone size-full wp-image-3209" /></a></div></div>

<div class='imgwrapper'><div><a href="http://improve.dk/wp-content/uploads/2013/03/3.png"><img src="http://improve.dk/wp-content/uploads/2013/03/3.png" alt="3" width="496" height="381" class="alignnone size-full wp-image-3210" /></a></div></div>

<div class='imgwrapper'><div><a href="http://improve.dk/wp-content/uploads/2013/03/4.png"><img src="http://improve.dk/wp-content/uploads/2013/03/4.png" alt="4" width="499" height="380" class="alignnone size-full wp-image-3211" /></a></div></div>

<div class='imgwrapper'><div><a href="http://improve.dk/wp-content/uploads/2013/03/5.png"><img src="http://improve.dk/wp-content/uploads/2013/03/5.png" alt="5" width="504" height="385" class="alignnone size-full wp-image-3212" /></a></div></div>

<div class='imgwrapper'><div><a href="http://improve.dk/wp-content/uploads/2013/03/6.png"><img src="http://improve.dk/wp-content/uploads/2013/03/6.png" alt="6" width="496" height="384" class="alignnone size-full wp-image-3213" /></a></div></div>

<p>Now that the zone has been created, simply right click it and choose &#8220;New Host (A or AAAA)&#8230;&#8221;. In the dialog, leave the Name blank as that&#8217;ll affect the record itself, while entering the desired IP like so:</p>

<div class='imgwrapper'><div><a href="http://improve.dk/wp-content/uploads/2013/03/6_b.png"><img src="http://improve.dk/wp-content/uploads/2013/03/6_b.png" alt="6_b" width="293" height="203" class="alignnone size-full wp-image-3214" /></a></div></div>

<div class='imgwrapper'><div><a href="http://improve.dk/wp-content/uploads/2013/03/7.png"><img src="http://improve.dk/wp-content/uploads/2013/03/7.png" alt="7" width="340" height="346" class="alignnone size-full wp-image-3215" /></a></div></div>

<p>And just like that, DNS lookups for jira.improve.dk will now be answered locally while all other requests will be forwarded to whatever DNS server is set up as the forwarding server.</p>

<p><b>One word of warning</b> &#8211; You might not want to do this on Active Directory domain servers as they&#8217;re somewhat more finicky about their DNS setup. I&#8217;m honestly not aware of what complications might arise, so I&#8217;d advice you to be careful or perhaps find another solution.</p><p>The post <a href="http://improve.dk/partial-dns-forwarding-using-individual-windows-dns-zones/">Partial DNS Forwarding Using Individual Windows DNS Zones</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p><img src="http://feeds.feedburner.com/~r/Improvedk/~4/Pk0JoWZo-Fg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://improve.dk/partial-dns-forwarding-using-individual-windows-dns-zones/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://improve.dk/partial-dns-forwarding-using-individual-windows-dns-zones/</feedburner:origLink></item>
		<item>
		<title>OrcaMDF Is Now Available on NuGet</title>
		<link>http://feedproxy.google.com/~r/Improvedk/~3/bodclWTfV3k/</link>
		<comments>http://improve.dk/orcamdf-is-now-available-on-nuget/#comments</comments>
		<pubDate>Mon, 13 May 2013 10:55:40 +0000</pubDate>
		<dc:creator>Mark S. Rasmussen</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[OrcaMDF]]></category>
		<category><![CDATA[NuGet]]></category>

		<guid isPermaLink="false">http://improve.dk/?p=3352</guid>
		<description><![CDATA[<p>Thanks to Justin Dearing (b&#124;t), OrcaMDF is now available on NuGet! OrcaMDF being on NuGet means the bar just got lowered even more if you want to try it out. Let me show you how easy it is to read the Adventureworks 2008 R2 Database using OrcaMDF: To begin, let&#8217;s create a vanilla .NET Console Application: Once the solution has been made, right click References and go to Manage NuGet Packages: Once the dialog opens, simply search for OrcaMDF and [...]</p><p>The post <a href="http://improve.dk/orcamdf-is-now-available-on-nuget/">OrcaMDF Is Now Available on NuGet</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Thanks to Justin Dearing (<a href="http://www.justaprogrammer.net/">b</a>|<a href="https://twitter.com/zippy1981">t</a>), OrcaMDF is now available on <a href="https://www.nuget.org/packages/OrcaMDF.Core">NuGet</a>!</p>

<p>OrcaMDF being on NuGet means the bar just got lowered even more if you want to try it out. Let me show you how easy it is to read the Adventureworks 2008 R2 Database using OrcaMDF:</p>

<p>To begin, let&#8217;s create a vanilla .NET <i>Console Application</i>:</p>

<div class='imgwrapper'><div><a href="http://improve.dk/wp-content/uploads/2013/05/1.png"><img src="http://improve.dk/wp-content/uploads/2013/05/1.png" alt="1" width="951" height="656" class="alignnone size-full wp-image-3353" /></a></div></div>

<p>Once the solution has been made, right click <i>References</i> and go to <i>Manage NuGet Packages</i>:</p>

<div class='imgwrapper'><div><a href="http://improve.dk/wp-content/uploads/2013/05/2.png"><img src="http://improve.dk/wp-content/uploads/2013/05/2.png" alt="2" width="491" height="423" class="alignnone size-full wp-image-3355" /></a></div></div>

<p>Once the dialog opens, simply search for <i>OrcaMDF</i> and click the <i>Install</i> button for the OrcaMDF.Core package:</p>

<div class='imgwrapper'><div><a href="http://improve.dk/wp-content/uploads/2013/05/3.png"><img src="http://improve.dk/wp-content/uploads/2013/05/3.png" alt="3" width="894" height="596" class="alignnone size-full wp-image-3356" /></a></div></div>

<p>When done, you should now see a small green checkmark next to the OrcaMDF.Core package:</p>

<div class='imgwrapper'><div><a href="http://improve.dk/wp-content/uploads/2013/05/4.png"><img src="http://improve.dk/wp-content/uploads/2013/05/4.png" alt="4" width="894" height="595" class="alignnone size-full wp-image-3357" /></a></div></div>

<p>At this point the OrcaMDF.Core assembly will be available and all you have to do is start using it. For example you could print out all of the products along with their prices by modifying the Program.cs file like so (you&#8217;ll have to alter the path to AdventureWorks2008R2_Data.mdf file so it points to a local copy (which must not be in use by SQL Server) on your machine):</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="csharp"><pre class="de1"><span class="kw1">using</span> <span class="co3">System</span><span class="sy0">;</span>
<span class="kw1">using</span> <span class="co3">OrcaMDF.Core.Engine</span><span class="sy0">;</span>
&nbsp;
<span class="kw1">namespace</span> ConsoleApplication1
<span class="br0">&#123;</span>
	<span class="kw4">class</span> Program
	<span class="br0">&#123;</span>
		<span class="kw1">static</span> <span class="kw4">void</span> Main<span class="br0">&#40;</span><span class="br0">&#41;</span>
		<span class="br0">&#123;</span>
			<span class="kw1">using</span> <span class="br0">&#40;</span><span class="kw1">var</span> db <span class="sy0">=</span> <span class="kw3">new</span> Database<span class="br0">&#40;</span><span class="st_h">@&quot;C:\AdventureWorks2008R2_Data.mdf&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
			<span class="br0">&#123;</span>
				<span class="kw1">var</span> scanner <span class="sy0">=</span> <span class="kw3">new</span> DataScanner<span class="br0">&#40;</span>db<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
				<span class="kw1">foreach</span> <span class="br0">&#40;</span><span class="kw1">var</span> row <span class="kw1">in</span> scanner<span class="sy0">.</span><span class="me1">ScanTable</span><span class="br0">&#40;</span><span class="st0">&quot;Product&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
				<span class="br0">&#123;</span>
					Console<span class="sy0">.</span><span class="me1">WriteLine</span><span class="br0">&#40;</span>row<span class="sy0">.</span><span class="me1">Field</span><span class="sy0">&lt;</span><span class="kw4">string</span><span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="st0">&quot;Name&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
					Console<span class="sy0">.</span><span class="me1">WriteLine</span><span class="br0">&#40;</span><span class="st0">&quot;Price: &quot;</span> <span class="sy0">+</span> row<span class="sy0">.</span><span class="me1">Field</span><span class="sy0">&lt;</span><span class="kw4">double</span><span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="st0">&quot;ListPrice&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
					Console<span class="sy0">.</span><span class="me1">WriteLine</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
				<span class="br0">&#125;</span>
			<span class="br0">&#125;</span>
		<span class="br0">&#125;</span>
	<span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre></div></div></div></div></div></div></div>




<p>And then just running the solution:</p>

<div class='imgwrapper'><div><a href="http://improve.dk/wp-content/uploads/2013/05/5.png"><img src="http://improve.dk/wp-content/uploads/2013/05/5.png" alt="5" width="676" height="340" class="alignnone size-full wp-image-3359" /></a></div></div>

<p>And there you have it, in just a few quick short steps you&#8217;ve now fetched OrcaMDF and read the Products table, from the standard AdventureWorks 2008 R2 database, without even touching SQL Server.</p>

<p>With OrcaMDF now being available on NuGet as well as with <a href="http://improve.dk/orcamdf-studio-release-feature-recap/">a simple GUI</a>, it really doesn&#8217;t get any simpler to take it for a spin :)</p><p>The post <a href="http://improve.dk/orcamdf-is-now-available-on-nuget/">OrcaMDF Is Now Available on NuGet</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p><img src="http://feeds.feedburner.com/~r/Improvedk/~4/bodclWTfV3k" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://improve.dk/orcamdf-is-now-available-on-nuget/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://improve.dk/orcamdf-is-now-available-on-nuget/</feedburner:origLink></item>
		<item>
		<title>How to Identify Which Request Caused a Runaway Thread, Using Windbg</title>
		<link>http://feedproxy.google.com/~r/Improvedk/~3/_5RUamb92LU/</link>
		<comments>http://improve.dk/how-to-identify-which-request-caused-a-runaway-thread-using-windbg/#comments</comments>
		<pubDate>Tue, 07 May 2013 09:26:28 +0000</pubDate>
		<dc:creator>Mark S. Rasmussen</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[Windbg]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[iis]]></category>
		<category><![CDATA[Threading]]></category>

		<guid isPermaLink="false">http://improve.dk/?p=3289</guid>
		<description><![CDATA[<p>When your w3wp process is stuck at 100% like, like when I used a non-thread-safe Dictionary concurrently, you may want to identify what request the runaway thread is actually serving. Let me show you how to identify which request caused a runaway thread, using windbg. First you&#8217;ll want to identify the process ID (PID) of the w3wp process. In my case, that&#8217;s 102600: Next you&#8217;ll want to start up Windbg (make sure to use the correct bitness (x86 vs x64) [...]</p><p>The post <a href="http://improve.dk/how-to-identify-which-request-caused-a-runaway-thread-using-windbg/">How to Identify Which Request Caused a Runaway Thread, Using Windbg</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>When your w3wp process is stuck at 100% like, <a href="/debugging-in-production-part-1-analyzing-100-cpu-usage-using-windbg/">like when I used a non-thread-safe Dictionary concurrently</a>, you may want to identify what request the runaway thread is actually serving. Let me show you how to identify which request caused a runaway thread, using windbg.</p>

<p>First you&#8217;ll want to identify the process ID (PID) of the w3wp process. In my case, that&#8217;s <b>102600</b>:</p>

<div class='imgwrapper'><div><a href="http://improve.dk/wp-content/uploads/2013/04/Taskmgr.png"><img src="http://improve.dk/wp-content/uploads/2013/04/Taskmgr.png" alt="Taskmgr" width="544" height="235" class="alignnone size-full wp-image-3291" /></a></div></div>

<p>Next you&#8217;ll want to start up Windbg (make sure to use the correct bitness (x86 vs x64) that corresponds to the bitness of your process). Once started, press <b>F6</b> to open up the <i>Attach to Process</i> dialog. Once open, enter your process ID and click OK.</p>

<div class='imgwrapper'><div><a href="http://improve.dk/wp-content/uploads/2013/04/Attach-to-Process.png"><img src="http://improve.dk/wp-content/uploads/2013/04/Attach-to-Process.png" alt="Attach to Process" width="391" height="534" class="alignnone size-full wp-image-3292" /></a></div></div>

<p>Doing so should bring up the Command window, ready for your command:</p>

<div class='imgwrapper'><div><a href="http://improve.dk/wp-content/uploads/2013/04/Windbg11.png"><img src="http://improve.dk/wp-content/uploads/2013/04/Windbg11.png" alt="Windbg1" width="913" height="625" class="alignnone size-full wp-image-3293" /></a></div></div>

<p>As the first thing, start out by loading the <a href="http://msdn.microsoft.com/en-us/library/bb190764.aspx">Son of Strike</a> extension, allowing us to debug managed code.</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="csharp"><pre class="de1"><span class="nu0">0</span><span class="sy0">:</span>039<span class="sy0">&gt;</span> <span class="sy0">.</span><span class="me1">loadby</span> sos clr</pre></div></div></div></div></div></div></div>




<p>Then continue by running the !runaway command to get a list of runaway (basically threads using lots of CPU) threads:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="csharp"><pre class="de1"><span class="nu0">0</span><span class="sy0">:</span>039<span class="sy0">&gt;</span> <span class="sy0">!</span>runaway
&nbsp;
 User Mode Time
  Thread       Time
  <span class="nu0">20</span><span class="sy0">:</span><span class="nu0">14930</span>      <span class="nu0">0</span> days <span class="nu0">0</span><span class="sy0">:</span><span class="nu0">21</span><span class="sy0">:</span><span class="nu0">44.261</span>
  <span class="nu0">21</span><span class="sy0">:</span><span class="nu0">15204</span>      <span class="nu0">0</span> days <span class="nu0">0</span><span class="sy0">:</span><span class="nu0">21</span><span class="sy0">:</span><span class="nu0">00.878</span>
  <span class="nu0">27</span><span class="sy0">:</span>19d48      <span class="nu0">0</span> days <span class="nu0">0</span><span class="sy0">:</span>04<span class="sy0">:</span><span class="nu0">23.860</span>
  <span class="nu0">32</span><span class="sy0">:</span><span class="nu0">18748</span>      <span class="nu0">0</span> days <span class="nu0">0</span><span class="sy0">:</span>02<span class="sy0">:</span><span class="nu0">59.260</span>
  <span class="nu0">31</span><span class="sy0">:</span>18bcc      <span class="nu0">0</span> days <span class="nu0">0</span><span class="sy0">:</span>02<span class="sy0">:</span><span class="nu0">19.277</span>
  <span class="nu0">30</span><span class="sy0">:</span>19d80      <span class="nu0">0</span> days <span class="nu0">0</span><span class="sy0">:</span>01<span class="sy0">:</span><span class="nu0">44.083</span>
  <span class="nu0">25</span><span class="sy0">:</span>19ec0      <span class="nu0">0</span> days <span class="nu0">0</span><span class="sy0">:</span>01<span class="sy0">:</span><span class="nu0">32.446</span>
  <span class="nu0">24</span><span class="sy0">:</span><span class="nu0">16534</span>      <span class="nu0">0</span> days <span class="nu0">0</span><span class="sy0">:</span>01<span class="sy0">:</span><span class="nu0">31.135</span>
  <span class="nu0">29</span><span class="sy0">:</span>19a80      <span class="nu0">0</span> days <span class="nu0">0</span><span class="sy0">:</span>01<span class="sy0">:</span><span class="nu0">08.297</span>
  <span class="nu0">23</span><span class="sy0">:</span><span class="nu0">19110</span>      <span class="nu0">0</span> days <span class="nu0">0</span><span class="sy0">:</span>00<span class="sy0">:</span><span class="nu0">30.591</span>
   <span class="nu0">6</span><span class="sy0">:</span>19b40      <span class="nu0">0</span> days <span class="nu0">0</span><span class="sy0">:</span>00<span class="sy0">:</span><span class="nu0">00.109</span>
  <span class="nu0">26</span><span class="sy0">:</span>18a14      <span class="nu0">0</span> days <span class="nu0">0</span><span class="sy0">:</span>00<span class="sy0">:</span><span class="nu0">00.015</span>
   <span class="nu0">0</span><span class="sy0">:</span>19dcc      <span class="nu0">0</span> days <span class="nu0">0</span><span class="sy0">:</span>00<span class="sy0">:</span><span class="nu0">00.015</span>
  <span class="nu0">39</span><span class="sy0">:</span>16fa8      <span class="nu0">0</span> days <span class="nu0">0</span><span class="sy0">:</span>00<span class="sy0">:</span><span class="nu0">00.000</span>
  <span class="sy0">...</span></pre></div></div></div></div></div></div></div>




<p>Threads 20 &#038; 21 seem to be the interesting ones. Let&#8217;s start out by selecting thread #20 as the active thread:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="csharp"><pre class="de1"><span class="nu0">0</span><span class="sy0">:</span>039<span class="sy0">&gt;</span> ~20s
&nbsp;
000007fe`913a15d9 3bc5            cmp     eax,ebp</pre></div></div></div></div></div></div></div>




<p>Once selected, we can analyze the stack and its parameters by running the !CLRStack command with the -p parameter:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="csharp"><pre class="de1"><span class="nu0">0</span><span class="sy0">:</span>020<span class="sy0">&gt;</span> <span class="sy0">!</span>CLRStack <span class="sy0">-</span>p
&nbsp;
OS Thread Id<span class="sy0">:</span> 0x14930 <span class="br0">&#40;</span><span class="nu0">20</span><span class="br0">&#41;</span>
        Child SP               IP Call Site
000000000dccdb00 000007fe913a15d9 <span class="kw5">System.<span class="me1">Collections</span></span><span class="sy0">.</span><span class="me1">Generic</span><span class="sy0">.</span><span class="me1">Dictionary</span>`<span class="nu0">2</span><span class="br0">&#91;</span><span class="br0">&#91;</span><span class="kw5">System</span><span class="sy0">.</span><span class="me1">Int16</span>, mscorlib<span class="br0">&#93;</span>,<span class="br0">&#91;</span><span class="kw5">System</span><span class="sy0">.</span>__Canon, mscorlib<span class="br0">&#93;</span><span class="br0">&#93;</span><span class="sy0">.</span><span class="me1">FindEntry</span><span class="br0">&#40;</span>Int16<span class="br0">&#41;</span>
    PARAMETERS<span class="sy0">:</span>
        <span class="kw1">this</span> <span class="sy0">=</span> <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
        key <span class="sy0">=</span> <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
&nbsp;
000000000dccdb50 000007fe913a14c0 <span class="kw5">System.<span class="me1">Collections</span></span><span class="sy0">.</span><span class="me1">Generic</span><span class="sy0">.</span><span class="me1">Dictionary</span>`<span class="nu0">2</span><span class="br0">&#91;</span><span class="br0">&#91;</span><span class="kw5">System</span><span class="sy0">.</span><span class="me1">Int16</span>, mscorlib<span class="br0">&#93;</span>,<span class="br0">&#91;</span><span class="kw5">System</span><span class="sy0">.</span>__Canon, mscorlib<span class="br0">&#93;</span><span class="br0">&#93;</span><span class="sy0">.</span><span class="me1">get_Item</span><span class="br0">&#40;</span>Int16<span class="br0">&#41;</span>
    PARAMETERS<span class="sy0">:</span>
        <span class="kw1">this</span> <span class="sy0">=</span> <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
        key <span class="sy0">=</span> <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
&nbsp;
000000000dccdb80 000007fe91421cbb iPaper<span class="sy0">.</span><span class="me1">BL</span><span class="sy0">.</span><span class="me1">Backend</span><span class="sy0">.</span><span class="me1">Modules</span><span class="sy0">.</span><span class="me1">Languages</span><span class="sy0">.</span><span class="me1">LanguageCache</span><span class="sy0">.</span><span class="me1">GetLanguageByID</span><span class="br0">&#40;</span>Int32, iPaper<span class="sy0">.</span><span class="me1">BL</span><span class="sy0">.</span><span class="me1">Backend</span><span class="sy0">.</span><span class="me1">Infrastructure</span><span class="sy0">.</span><span class="me1">PartnerConfiguration</span><span class="sy0">.</span><span class="me1">IPartnerConfig</span><span class="br0">&#41;</span> <span class="br0">&#91;</span>e<span class="sy0">:</span>\iPaperCMS\BL\Backend\Modules\Languages\LanguageCache<span class="sy0">.</span><span class="me1">cs</span> @ <span class="nu0">44</span><span class="br0">&#93;</span>
    PARAMETERS<span class="sy0">:</span>
        languageID <span class="br0">&#40;</span>0x000000000dccdc20<span class="br0">&#41;</span> <span class="sy0">=</span> 0x0000000000000001
        partnerConfig <span class="br0">&#40;</span>0x000000000dccdc28<span class="br0">&#41;</span> <span class="sy0">=</span> 0x00000000fffc3e50
&nbsp;
000000000dccdc20 000007fe91421dfa iPaper<span class="sy0">.</span><span class="me1">BL</span><span class="sy0">.</span><span class="me1">Backend</span><span class="sy0">.</span><span class="me1">Modules</span><span class="sy0">.</span><span class="me1">Languages</span><span class="sy0">.</span><span class="me1">Language</span><span class="sy0">.</span><span class="me1">GetFontFileForLanguage</span><span class="br0">&#40;</span>Int32, iPaper<span class="sy0">.</span><span class="me1">BL</span><span class="sy0">.</span><span class="me1">Backend</span><span class="sy0">.</span><span class="me1">Infrastructure</span><span class="sy0">.</span><span class="me1">PartnerConfiguration</span><span class="sy0">.</span><span class="me1">IPartnerConfig</span><span class="br0">&#41;</span> <span class="br0">&#91;</span>e<span class="sy0">:</span>\iPaperCMS\BL\Backend\Modules\Languages\Language<span class="sy0">.</span><span class="me1">cs</span> @ <span class="nu0">37</span><span class="br0">&#93;</span>
    PARAMETERS<span class="sy0">:</span>
        languageID <span class="br0">&#40;</span>0x000000000dccdc70<span class="br0">&#41;</span> <span class="sy0">=</span> 0x0000000000000001
        partnerConfig <span class="br0">&#40;</span>0x000000000dccdc78<span class="br0">&#41;</span> <span class="sy0">=</span> 0x00000000fffc3e50
&nbsp;
000000000dccdc70 000007fe91417400 iPaper<span class="sy0">.</span><span class="me1">Web</span><span class="sy0">.</span><span class="me1">FlexFrontend</span><span class="sy0">.</span><span class="me1">BL</span><span class="sy0">.</span><span class="me1">Common</span><span class="sy0">.</span><span class="me1">CachedUrlInformation</span><span class="sy0">.</span><span class="me1">GetFromUrlDirectoryPath</span><span class="br0">&#40;</span><span class="kw5">System</span><span class="sy0">.</span><span class="kw4">String</span>, <span class="kw5">System</span><span class="sy0">.</span><span class="kw4">String</span>, iPaper<span class="sy0">.</span><span class="me1">BL</span><span class="sy0">.</span><span class="me1">Backend</span><span class="sy0">.</span><span class="me1">Infrastructure</span><span class="sy0">.</span><span class="me1">PartnerConfiguration</span><span class="sy0">.</span><span class="me1">IPartnerConfig</span><span class="br0">&#41;</span> <span class="br0">&#91;</span>e<span class="sy0">:</span>\iPaperCMS\Frontend\BL\Common\CachedUrlInformation<span class="sy0">.</span><span class="me1">cs</span> @ <span class="nu0">89</span><span class="br0">&#93;</span>
    PARAMETERS<span class="sy0">:</span>
        url <span class="br0">&#40;</span>0x000000000dccde80<span class="br0">&#41;</span> <span class="sy0">=</span> 0x00000003fff27e30
        host <span class="br0">&#40;</span>0x000000000dccde88<span class="br0">&#41;</span> <span class="sy0">=</span> 0x00000003fff29618
        partnerConfig <span class="br0">&#40;</span>0x000000000dccde90<span class="br0">&#41;</span> <span class="sy0">=</span> 0x00000000fffc3e50
&nbsp;
000000000dccde80 000007fe91417576 iPaper<span class="sy0">.</span><span class="me1">Web</span><span class="sy0">.</span><span class="me1">FlexFrontend</span><span class="sy0">.</span><span class="me1">BL</span><span class="sy0">.</span><span class="me1">Common</span><span class="sy0">.</span><span class="me1">CachedUrlInformation</span><span class="sy0">.</span><span class="me1">GetFromHttpContext</span><span class="br0">&#40;</span><span class="kw5">System</span><span class="sy0">.</span><span class="kw4">String</span>, <span class="kw5">System.<span class="me1">Web</span></span><span class="sy0">.</span><span class="me1">HttpContext</span>, iPaper<span class="sy0">.</span><span class="me1">BL</span><span class="sy0">.</span><span class="me1">Backend</span><span class="sy0">.</span><span class="me1">Infrastructure</span><span class="sy0">.</span><span class="me1">PartnerConfiguration</span><span class="sy0">.</span><span class="me1">IPartnerConfig</span><span class="br0">&#41;</span> <span class="br0">&#91;</span>e<span class="sy0">:</span>\iPaperCMS\Frontend\BL\Common\CachedUrlInformation<span class="sy0">.</span><span class="me1">cs</span> @ <span class="nu0">122</span><span class="br0">&#93;</span>
    PARAMETERS<span class="sy0">:</span>
        paperPath <span class="br0">&#40;</span>0x000000000dcce010<span class="br0">&#41;</span> <span class="sy0">=</span> 0x00000003fff27e30
        context <span class="br0">&#40;</span>0x000000000dcce018<span class="br0">&#41;</span> <span class="sy0">=</span> 0x00000000fffa6040
        partnerConfig <span class="br0">&#40;</span>0x000000000dcce020<span class="br0">&#41;</span> <span class="sy0">=</span> 0x00000000fffc3e50
&nbsp;
000000000dcce010 000007fe91415529 iPaper<span class="sy0">.</span><span class="me1">Web</span><span class="sy0">.</span><span class="me1">FlexFrontend</span><span class="sy0">.</span><span class="me1">BL</span><span class="sy0">.</span><span class="me1">RequestHandler</span><span class="sy0">.</span><span class="me1">RequestHandler</span><span class="sy0">.</span><span class="me1">loadFrontendContext</span><span class="br0">&#40;</span><span class="kw5">System</span><span class="sy0">.</span><span class="kw4">String</span><span class="br0">&#41;</span> <span class="br0">&#91;</span>e<span class="sy0">:</span>\iPaperCMS\Frontend\BL\RequestHandler\RequestHandler<span class="sy0">.</span><span class="me1">cs</span> @ <span class="nu0">469</span><span class="br0">&#93;</span>
    PARAMETERS<span class="sy0">:</span>
        <span class="kw1">this</span> <span class="br0">&#40;</span>0x000000000dcce260<span class="br0">&#41;</span> <span class="sy0">=</span> 0x00000000fffa9590
        paperPath <span class="br0">&#40;</span>0x000000000dcce268<span class="br0">&#41;</span> <span class="sy0">=</span> 0x00000003fff27e30
&nbsp;
000000000dcce260 000007fe91414b73 iPaper<span class="sy0">.</span><span class="me1">Web</span><span class="sy0">.</span><span class="me1">FlexFrontend</span><span class="sy0">.</span><span class="me1">BL</span><span class="sy0">.</span><span class="me1">RequestHandler</span><span class="sy0">.</span><span class="me1">RequestHandler</span><span class="sy0">.</span><span class="me1">context_PostAcquireRequestState</span><span class="br0">&#40;</span><span class="kw5">System</span><span class="sy0">.</span><span class="kw4">Object</span>, <span class="kw5">System</span><span class="sy0">.</span><span class="me1">EventArgs</span><span class="br0">&#41;</span> <span class="br0">&#91;</span>e<span class="sy0">:</span>\iPaperCMS\Frontend\BL\RequestHandler\RequestHandler<span class="sy0">.</span><span class="me1">cs</span> @ <span class="nu0">95</span><span class="br0">&#93;</span>
    PARAMETERS<span class="sy0">:</span>
        <span class="kw1">this</span> <span class="br0">&#40;</span>0x000000000dcce5f0<span class="br0">&#41;</span> <span class="sy0">=</span> 0x00000000fffa9590
        sender <span class="br0">&#40;</span>0x000000000dcce5f8<span class="br0">&#41;</span> <span class="sy0">=</span> 0x00000000fffa8a50
        e <span class="br0">&#40;</span>0x000000000dcce600<span class="br0">&#41;</span> <span class="sy0">=</span> 0x00000000fffaebb0
&nbsp;
000000000dcce5f0 000007fedb72c520 <span class="kw5">System.<span class="me1">Web</span></span><span class="sy0">.</span><span class="me1">HttpApplication</span><span class="sy0">+</span>SyncEventExecutionStep<span class="sy0">.</span><span class="kw5">System.<span class="me1">Web</span></span><span class="sy0">.</span><span class="me1">HttpApplication</span><span class="sy0">.</span><span class="me1">IExecutionStep</span><span class="sy0">.</span><span class="me1">Execute</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
    PARAMETERS<span class="sy0">:</span>
        <span class="kw1">this</span> <span class="sy0">=</span> <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
&nbsp;
000000000dcce650 000007fedb70b745 <span class="kw5">System.<span class="me1">Web</span></span><span class="sy0">.</span><span class="me1">HttpApplication</span><span class="sy0">.</span><span class="me1">ExecuteStep</span><span class="br0">&#40;</span>IExecutionStep, Boolean ByRef<span class="br0">&#41;</span>
    PARAMETERS<span class="sy0">:</span>
        <span class="kw1">this</span> <span class="br0">&#40;</span>0x000000000dcce6f0<span class="br0">&#41;</span> <span class="sy0">=</span> 0x00000000fffa8a50
        step <span class="br0">&#40;</span>0x000000000dcce6f8<span class="br0">&#41;</span> <span class="sy0">=</span> 0x00000000fffabc28
        completedSynchronously <span class="br0">&#40;</span>0x000000000dcce700<span class="br0">&#41;</span> <span class="sy0">=</span> 0x000000000dcce77a
&nbsp;
000000000dcce6f0 000007fedb72a4e1 <span class="kw5">System.<span class="me1">Web</span></span><span class="sy0">.</span><span class="me1">HttpApplication</span><span class="sy0">+</span>PipelineStepManager<span class="sy0">.</span><span class="me1">ResumeSteps</span><span class="br0">&#40;</span><span class="kw5">System</span><span class="sy0">.</span><span class="me1">Exception</span><span class="br0">&#41;</span>
    PARAMETERS<span class="sy0">:</span>
        <span class="kw1">this</span> <span class="br0">&#40;</span>0x000000000dcce7d0<span class="br0">&#41;</span> <span class="sy0">=</span> 0x00000000fffac718
        error <span class="sy0">=</span> <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
&nbsp;
000000000dcce7d0 000007fedb70b960 <span class="kw5">System.<span class="me1">Web</span></span><span class="sy0">.</span><span class="me1">HttpApplication</span><span class="sy0">.</span><span class="me1">BeginProcessRequestNotification</span><span class="br0">&#40;</span><span class="kw5">System.<span class="me1">Web</span></span><span class="sy0">.</span><span class="me1">HttpContext</span>, <span class="kw5">System</span><span class="sy0">.</span><span class="me1">AsyncCallback</span><span class="br0">&#41;</span>
    PARAMETERS<span class="sy0">:</span>
        <span class="kw1">this</span> <span class="sy0">=</span> <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
        context <span class="sy0">=</span> <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
        cb <span class="sy0">=</span> <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
&nbsp;
000000000dcce820 000007fedb704c8e <span class="kw5">System.<span class="me1">Web</span></span><span class="sy0">.</span><span class="me1">HttpRuntime</span><span class="sy0">.</span><span class="me1">ProcessRequestNotificationPrivate</span><span class="br0">&#40;</span><span class="kw5">System.<span class="me1">Web</span></span><span class="sy0">.</span><span class="me1">Hosting</span><span class="sy0">.</span><span class="me1">IIS7WorkerRequest</span>, <span class="kw5">System.<span class="me1">Web</span></span><span class="sy0">.</span><span class="me1">HttpContext</span><span class="br0">&#41;</span>
    PARAMETERS<span class="sy0">:</span>
        <span class="kw1">this</span> <span class="br0">&#40;</span>0x000000000dcce8c0<span class="br0">&#41;</span> <span class="sy0">=</span> 0x00000000fff3fb20
        wr <span class="br0">&#40;</span>0x000000000dcce8c8<span class="br0">&#41;</span> <span class="sy0">=</span> 0x00000000fffa5eb0
        context <span class="br0">&#40;</span>0x000000000dcce8d0<span class="br0">&#41;</span> <span class="sy0">=</span> 0x00000000fffa6040
&nbsp;
000000000dcce8c0 000007fedb70e771 <span class="kw5">System.<span class="me1">Web</span></span><span class="sy0">.</span><span class="me1">Hosting</span><span class="sy0">.</span><span class="me1">PipelineRuntime</span><span class="sy0">.</span><span class="me1">ProcessRequestNotificationHelper</span><span class="br0">&#40;</span>IntPtr, IntPtr, IntPtr, Int32<span class="br0">&#41;</span>
    PARAMETERS<span class="sy0">:</span>
        rootedObjectsPointer <span class="sy0">=</span> <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
        nativeRequestContext <span class="br0">&#40;</span>0x000000000dccea58<span class="br0">&#41;</span> <span class="sy0">=</span> 0x0000000000ccccc0
        moduleData <span class="sy0">=</span> <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
        flags <span class="sy0">=</span> <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
&nbsp;
000000000dccea50 000007fedb70e2c2 <span class="kw5">System.<span class="me1">Web</span></span><span class="sy0">.</span><span class="me1">Hosting</span><span class="sy0">.</span><span class="me1">PipelineRuntime</span><span class="sy0">.</span><span class="me1">ProcessRequestNotification</span><span class="br0">&#40;</span>IntPtr, IntPtr, IntPtr, Int32<span class="br0">&#41;</span>
    PARAMETERS<span class="sy0">:</span>
        rootedObjectsPointer <span class="sy0">=</span> <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
        nativeRequestContext <span class="sy0">=</span> <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
        moduleData <span class="sy0">=</span> <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
        flags <span class="sy0">=</span> <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
&nbsp;
000000000dcceaa0 000007fedbe6b461 DomainNeutralILStubClass<span class="sy0">.</span><span class="me1">IL_STUB_ReversePInvoke</span><span class="br0">&#40;</span>Int64, Int64, Int64, Int32<span class="br0">&#41;</span>
    PARAMETERS<span class="sy0">:</span>
        <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
        <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
        <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
        <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
&nbsp;
000000000dccf298 000007fef0a9334e <span class="br0">&#91;</span>InlinedCallFrame<span class="sy0">:</span> 000000000dccf298<span class="br0">&#93;</span> <span class="kw5">System.<span class="me1">Web</span></span><span class="sy0">.</span><span class="me1">Hosting</span><span class="sy0">.</span><span class="me1">UnsafeIISMethods</span><span class="sy0">.</span><span class="me1">MgdIndicateCompletion</span><span class="br0">&#40;</span>IntPtr, <span class="kw5">System.<span class="me1">Web</span></span><span class="sy0">.</span><span class="me1">RequestNotificationStatus</span> ByRef<span class="br0">&#41;</span>
000000000dccf298 000007fedb7b9c4b <span class="br0">&#91;</span>InlinedCallFrame<span class="sy0">:</span> 000000000dccf298<span class="br0">&#93;</span> <span class="kw5">System.<span class="me1">Web</span></span><span class="sy0">.</span><span class="me1">Hosting</span><span class="sy0">.</span><span class="me1">UnsafeIISMethods</span><span class="sy0">.</span><span class="me1">MgdIndicateCompletion</span><span class="br0">&#40;</span>IntPtr, <span class="kw5">System.<span class="me1">Web</span></span><span class="sy0">.</span><span class="me1">RequestNotificationStatus</span> ByRef<span class="br0">&#41;</span>
000000000dccf270 000007fedb7b9c4b DomainNeutralILStubClass<span class="sy0">.</span><span class="me1">IL_STUB_PInvoke</span><span class="br0">&#40;</span>IntPtr, <span class="kw5">System.<span class="me1">Web</span></span><span class="sy0">.</span><span class="me1">RequestNotificationStatus</span> ByRef<span class="br0">&#41;</span>
    PARAMETERS<span class="sy0">:</span>
        <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
        <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
&nbsp;
000000000dccf340 000007fedb70e923 <span class="kw5">System.<span class="me1">Web</span></span><span class="sy0">.</span><span class="me1">Hosting</span><span class="sy0">.</span><span class="me1">PipelineRuntime</span><span class="sy0">.</span><span class="me1">ProcessRequestNotificationHelper</span><span class="br0">&#40;</span>IntPtr, IntPtr, IntPtr, Int32<span class="br0">&#41;</span>
    PARAMETERS<span class="sy0">:</span>
        rootedObjectsPointer <span class="sy0">=</span> <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
        nativeRequestContext <span class="sy0">=</span> <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
        moduleData <span class="sy0">=</span> <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
        flags <span class="sy0">=</span> <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
&nbsp;
000000000dccf4d0 000007fedb70e2c2 <span class="kw5">System.<span class="me1">Web</span></span><span class="sy0">.</span><span class="me1">Hosting</span><span class="sy0">.</span><span class="me1">PipelineRuntime</span><span class="sy0">.</span><span class="me1">ProcessRequestNotification</span><span class="br0">&#40;</span>IntPtr, IntPtr, IntPtr, Int32<span class="br0">&#41;</span>
    PARAMETERS<span class="sy0">:</span>
        rootedObjectsPointer <span class="sy0">=</span> <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
        nativeRequestContext <span class="sy0">=</span> <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
        moduleData <span class="sy0">=</span> <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
        flags <span class="sy0">=</span> <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
&nbsp;
000000000dccf520 000007fedbe6b461 DomainNeutralILStubClass<span class="sy0">.</span><span class="me1">IL_STUB_ReversePInvoke</span><span class="br0">&#40;</span>Int64, Int64, Int64, Int32<span class="br0">&#41;</span>
    PARAMETERS<span class="sy0">:</span>
        <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
        <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
        <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
        <span class="sy0">&lt;</span>no data<span class="sy0">&gt;</span>
&nbsp;
000000000dccf768 000007fef0a935a3 <span class="br0">&#91;</span>ContextTransitionFrame<span class="sy0">:</span> 000000000dccf768<span class="br0">&#93;</span></pre></div></div></div></div></div></div></div>




<p>This returns the full stack with a lot of frames that we&#8217;re not really interested in. What we&#8217;re looking for is the first instance of an HttpContext. If we start from the bottom and work our way up, this seems to be the first time an HttpContext is present:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="csharp"><pre class="de1">000000000dcce820 000007fedb704c8e <span class="kw5">System.<span class="me1">Web</span></span><span class="sy0">.</span><span class="me1">HttpRuntime</span><span class="sy0">.</span><span class="me1">ProcessRequestNotificationPrivate</span><span class="br0">&#40;</span><span class="kw5">System.<span class="me1">Web</span></span><span class="sy0">.</span><span class="me1">Hosting</span><span class="sy0">.</span><span class="me1">IIS7WorkerRequest</span>, <span class="kw5">System.<span class="me1">Web</span></span><span class="sy0">.</span><span class="me1">HttpContext</span><span class="br0">&#41;</span>
    PARAMETERS<span class="sy0">:</span>
        <span class="kw1">this</span> <span class="br0">&#40;</span>0x000000000dcce8c0<span class="br0">&#41;</span> <span class="sy0">=</span> 0x00000000fff3fb20
        wr <span class="br0">&#40;</span>0x000000000dcce8c8<span class="br0">&#41;</span> <span class="sy0">=</span> 0x00000000fffa5eb0
        context <span class="br0">&#40;</span>0x000000000dcce8d0<span class="br0">&#41;</span> <span class="sy0">=</span> 0x00000000fffa6040</pre></div></div></div></div></div></div></div>




<p>Knowing that the HttpContext contains a reference to an HttpRequest, and that HttpRequest contains the RawUrl string value, we&#8217;ll start digging in. Start out by dumping the HttpContext object using the !do command:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="csharp"><pre class="de1"><span class="nu0">0</span><span class="sy0">:</span>020<span class="sy0">&gt;</span> <span class="sy0">!</span><span class="kw1">do</span> 0x00000000fffa6040
&nbsp;
Name<span class="sy0">:</span>        <span class="kw5">System.<span class="me1">Web</span></span><span class="sy0">.</span><span class="me1">HttpContext</span>
MethodTable<span class="sy0">:</span> 000007fedb896398
EEClass<span class="sy0">:</span>     000007fedb4882e0
Size<span class="sy0">:</span>        <span class="nu0">416</span><span class="br0">&#40;</span>0x1a0<span class="br0">&#41;</span> bytes
File<span class="sy0">:</span>        C<span class="sy0">:</span>\Windows\Microsoft<span class="sy0">.</span><span class="me1">Net</span>\assembly\GAC_64\<span class="kw5">System.<span class="me1">Web</span></span>\v4<span class="sy0">.</span>0_4<span class="sy0">.</span>0<span class="sy0">.</span>0<span class="sy0">.</span>0__b03f5f7f11d50a3a\<span class="kw5">System.<span class="me1">Web</span></span><span class="sy0">.</span><span class="me1">dll</span>
Fields<span class="sy0">:</span>
              MT    Field   Offset                 Type VT     Attr            <span class="kw1">Value</span> Name
000007fedb897c80  40010a3        <span class="nu0">8</span> <span class="sy0">...</span><span class="me1">IHttpAsyncHandler</span>  <span class="nu0">0</span> instance 0000000000000000 _asyncAppHandler
000007fedb88e618  40010a4      <span class="nu0">158</span>         <span class="kw5">System</span><span class="sy0">.</span><span class="me1">Int32</span>  <span class="nu0">1</span> instance                <span class="nu0">0</span> _asyncPreloadModeFlags
000007feef9fdc30  40010a5      <span class="nu0">168</span>       <span class="kw5">System</span><span class="sy0">.</span><span class="me1">Boolean</span>  <span class="nu0">1</span> instance                <span class="nu0">0</span> _asyncPreloadModeFlagsSet
000007fedb895610  40010a6       <span class="nu0">10</span> <span class="sy0">...</span><span class="me1">b</span><span class="sy0">.</span><span class="me1">HttpApplication</span>  <span class="nu0">0</span> instance 00000000fffa8a50 _appInstance
000007fedb897ce8  40010a7       <span class="nu0">18</span> <span class="sy0">....</span><span class="me1">Web</span><span class="sy0">.</span><span class="me1">IHttpHandler</span>  <span class="nu0">0</span> instance 00000003fff28c20 _handler
000007fedb898170  40010a8       <span class="nu0">20</span> <span class="sy0">...</span><span class="me1">m</span><span class="sy0">.</span><span class="me1">Web</span><span class="sy0">.</span><span class="me1">HttpRequest</span>  <span class="nu0">0</span> instance 00000000fffa61f8 _request
000007fedb898550  40010a9       <span class="nu0">28</span> <span class="sy0">....</span><span class="me1">Web</span><span class="sy0">.</span><span class="me1">HttpResponse</span>  <span class="nu0">0</span> instance 00000000fffa6378 _response
000007fedb893cb0  40010aa       <span class="nu0">30</span> <span class="sy0">...</span><span class="me1">HttpServerUtility</span>  <span class="nu0">0</span> instance 00000003fff27ed8 _server
000007feefa05ac0  40010ab       <span class="nu0">38</span> <span class="sy0">...</span><span class="me1">Collections</span><span class="sy0">.</span><span class="me1">Stack</span>  <span class="nu0">0</span> instance 0000000000000000 _traceContextStack
000007fedb8a41d8  40010ac       <span class="nu0">40</span> <span class="sy0">....</span><span class="me1">Web</span><span class="sy0">.</span><span class="me1">TraceContext</span>  <span class="nu0">0</span> instance 0000000000000000 _topTraceContext
000007feefa00548  40010ad       <span class="nu0">48</span> <span class="sy0">...</span><span class="me1">ections</span><span class="sy0">.</span><span class="me1">Hashtable</span>  <span class="nu0">0</span> instance 00000000fffab198 _items
000007feef9f85e0  40010ae       <span class="nu0">50</span> <span class="sy0">...</span><span class="me1">ections</span><span class="sy0">.</span><span class="me1">ArrayList</span>  <span class="nu0">0</span> instance 0000000000000000 _errors
000007feef9fc588  40010af       <span class="nu0">58</span>     <span class="kw5">System</span><span class="sy0">.</span><span class="me1">Exception</span>  <span class="nu0">0</span> instance 0000000000000000 _tempError
<span class="sy0">...</span></pre></div></div></div></div></div></div></div>




<p>This contains a lot of fields (some of which I&#8217;ve snipped out). The interesting part however, is this line:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="csharp"><pre class="de1">000007fedb898170  40010a8       <span class="nu0">20</span> <span class="sy0">...</span><span class="me1">m</span><span class="sy0">.</span><span class="me1">Web</span><span class="sy0">.</span><span class="me1">HttpRequest</span>  <span class="nu0">0</span> instance 00000000fffa61f8 _request</pre></div></div></div></div></div></div></div>




<p>This contains a pointer to the HttpRequest instance. Let&#8217;s try dumping that one:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="csharp"><pre class="de1"><span class="nu0">0</span><span class="sy0">:</span>020<span class="sy0">&gt;</span> <span class="sy0">!</span><span class="kw1">do</span> 00000000fffa61f8 
&nbsp;
Name<span class="sy0">:</span>        <span class="kw5">System.<span class="me1">Web</span></span><span class="sy0">.</span><span class="me1">HttpRequest</span>
MethodTable<span class="sy0">:</span> 000007fedb898170
EEClass<span class="sy0">:</span>     000007fedb488c00
Size<span class="sy0">:</span>        <span class="nu0">384</span><span class="br0">&#40;</span>0x180<span class="br0">&#41;</span> bytes
File<span class="sy0">:</span>        C<span class="sy0">:</span>\Windows\Microsoft<span class="sy0">.</span><span class="me1">Net</span>\assembly\GAC_64\<span class="kw5">System.<span class="me1">Web</span></span>\v4<span class="sy0">.</span>0_4<span class="sy0">.</span>0<span class="sy0">.</span>0<span class="sy0">.</span>0__b03f5f7f11d50a3a\<span class="kw5">System.<span class="me1">Web</span></span><span class="sy0">.</span><span class="me1">dll</span>
Fields<span class="sy0">:</span>
              MT    Field   Offset                 Type VT     Attr            <span class="kw1">Value</span> Name
000007fedb89aa30  <span class="nu0">4001150</span>        <span class="nu0">8</span> <span class="sy0">...</span><span class="me1">HttpWorkerRequest</span>  <span class="nu0">0</span> instance 00000000fffa5eb0 _wr
000007fedb896398  <span class="nu0">4001151</span>       <span class="nu0">10</span> <span class="sy0">...</span><span class="me1">m</span><span class="sy0">.</span><span class="me1">Web</span><span class="sy0">.</span><span class="me1">HttpContext</span>  <span class="nu0">0</span> instance 00000000fffa6040 _context
<span class="sy0">...</span>
000007fee6e1dc48  <span class="nu0">4001165</span>       <span class="nu0">90</span>           <span class="kw5">System</span><span class="sy0">.</span><span class="me1">Uri</span>  <span class="nu0">0</span> instance 00000003fff29588 _url
000007fee6e1dc48  <span class="nu0">4001166</span>       <span class="nu0">98</span>           <span class="kw5">System</span><span class="sy0">.</span><span class="me1">Uri</span>  <span class="nu0">0</span> instance 0000000000000000 _referrer
000007fedb900718  <span class="nu0">4001167</span>       a0 <span class="sy0">...</span><span class="me1">b</span><span class="sy0">.</span><span class="me1">HttpInputStream</span>  <span class="nu0">0</span> instance 0000000000000000 _inputStream
000007fedb8c43d0  <span class="nu0">4001168</span>       a8 <span class="sy0">...</span><span class="me1">ClientCertificate</span>  <span class="nu0">0</span> instance 0000000000000000 _clientCertificate
000007feefa07e90  <span class="nu0">4001169</span>       b0 <span class="sy0">...</span><span class="me1">l</span><span class="sy0">.</span><span class="me1">WindowsIdentity</span>  <span class="nu0">0</span> instance 0000000000000000 _logonUserIdentity
000007fedb8d7fd0  400116a       b8 <span class="sy0">...</span><span class="me1">ng</span><span class="sy0">.</span><span class="me1">RequestContext</span>  <span class="nu0">0</span> instance 0000000000000000 _requestContext
000007feef9fc358  400116b       c0        <span class="kw5">System</span><span class="sy0">.</span><span class="kw4">String</span>  <span class="nu0">0</span> instance 00000000fffa64f0 _rawUrl
000007feefa008b8  400116c       c8     <span class="kw5">System.<span class="me1">IO</span></span><span class="sy0">.</span><span class="me1">Stream</span>  <span class="nu0">0</span> instance 0000000000000000 _readEntityBodyStream
000007fedb8d5ac8  400116d      <span class="nu0">160</span>         <span class="kw5">System</span><span class="sy0">.</span><span class="me1">Int32</span>  <span class="nu0">1</span> instance                <span class="nu0">0</span> _readEntityBodyMode
000007fedb8bbcb0  400116e       d0 <span class="sy0">...</span><span class="me1">atedRequestValues</span>  <span class="nu0">0</span> instance 00000003fff27fe8 _unvalidatedRequestValues
<span class="sy0">...</span></pre></div></div></div></div></div></div></div>




<p>Once again there are a lot of fields that we don&#8217;t care about. The interesting one is this one:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="csharp"><pre class="de1">000007feef9fc358  400116b       c0        <span class="kw5">System</span><span class="sy0">.</span><span class="kw4">String</span>  <span class="nu0">0</span> instance 00000000fffa64f0 _rawUrl</pre></div></div></div></div></div></div></div>




<p>Dumping the RawUrl property reveals the actual URL that made the request which eventually ended up causing a runaway thread:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="csharp"><pre class="de1"><span class="nu0">0</span><span class="sy0">:</span>020<span class="sy0">&gt;</span> <span class="sy0">!</span><span class="kw1">do</span> 00000000fffa64f0 
&nbsp;
Name<span class="sy0">:</span>        <span class="kw5">System</span><span class="sy0">.</span><span class="kw4">String</span>
MethodTable<span class="sy0">:</span> 000007feef9fc358
EEClass<span class="sy0">:</span>     000007feef363720
Size<span class="sy0">:</span>        <span class="nu0">150</span><span class="br0">&#40;</span>0x96<span class="br0">&#41;</span> bytes
File<span class="sy0">:</span>        C<span class="sy0">:</span>\Windows\Microsoft<span class="sy0">.</span><span class="me1">Net</span>\assembly\GAC_64\mscorlib\v4<span class="sy0">.</span>0_4<span class="sy0">.</span>0<span class="sy0">.</span>0<span class="sy0">.</span>0__b77a5c561934e089\mscorlib<span class="sy0">.</span><span class="me1">dll</span>
<span class="kw4">String</span><span class="sy0">:</span>      <span class="sy0">/</span>Catalogs<span class="sy0">/</span>SomeClient<span class="sy0">/</span>Uge45<span class="sy0">/</span>Image<span class="sy0">.</span><span class="me1">ashx</span><span class="sy0">?</span>PageNumber<span class="sy0">=</span><span class="nu0">1</span><span class="sy0">&amp;</span>ImageType<span class="sy0">=</span>Thumb
Fields<span class="sy0">:</span>
              MT    Field   Offset                 Type VT     Attr            <span class="kw1">Value</span> Name
000007feef9ff108  40000aa        <span class="nu0">8</span>         <span class="kw5">System</span><span class="sy0">.</span><span class="me1">Int32</span>  <span class="nu0">1</span> instance               <span class="nu0">62</span> m_stringLength
000007feef9fd640  40000ab        c          <span class="kw5">System</span><span class="sy0">.</span><span class="kw4">Char</span>  <span class="nu0">1</span> instance               2f m_firstChar
000007feef9fc358  40000ac       <span class="nu0">18</span>        <span class="kw5">System</span><span class="sy0">.</span><span class="kw4">String</span>  <span class="nu0">0</span>   shared           <span class="kw1">static</span> Empty
                                 <span class="sy0">&gt;&gt;</span> Domain<span class="sy0">:</span><span class="kw1">Value</span>  0000000001ec80e0<span class="sy0">:</span>NotInit  0000000001f8e840<span class="sy0">:</span>NotInit</pre></div></div></div></div></div></div></div>




<p>And there we go! The offending URL seems to be:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="csharp"><pre class="de1"><span class="sy0">/</span>Catalogs<span class="sy0">/</span>SomeClient<span class="sy0">/</span>Uge45<span class="sy0">/</span>Image<span class="sy0">.</span><span class="me1">ashx</span><span class="sy0">?</span>PageNumber<span class="sy0">=</span><span class="nu0">1</span><span class="sy0">&amp;</span>ImageType<span class="sy0">=</span>Thumb</pre></div></div></div></div></div></div></div>




<p>If you want the complete URL, including hostname, you could dig your way into the _url field on the HttpRequest object and work your way from there. In just the same way you can dig into pretty much any object, whether it&#8217;s in your code or in the IIS codebase.</p><p>The post <a href="http://improve.dk/how-to-identify-which-request-caused-a-runaway-thread-using-windbg/">How to Identify Which Request Caused a Runaway Thread, Using Windbg</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p><img src="http://feeds.feedburner.com/~r/Improvedk/~4/_5RUamb92LU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://improve.dk/how-to-identify-which-request-caused-a-runaway-thread-using-windbg/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://improve.dk/how-to-identify-which-request-caused-a-runaway-thread-using-windbg/</feedburner:origLink></item>
		<item>
		<title>Debugging in Production Part 3 – Thread-Safe Dictionaries</title>
		<link>http://feedproxy.google.com/~r/Improvedk/~3/N4CIC2uWMms/</link>
		<comments>http://improve.dk/debugging-in-production-part-3-thread-safe-dictionaries/#comments</comments>
		<pubDate>Tue, 30 Apr 2013 11:13:08 +0000</pubDate>
		<dc:creator>Mark S. Rasmussen</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Windbg]]></category>
		<category><![CDATA[ConcurrentDictionary]]></category>
		<category><![CDATA[Dictionary]]></category>
		<category><![CDATA[Threading]]></category>

		<guid isPermaLink="false">http://improve.dk/?p=3260</guid>
		<description><![CDATA[<p>In part 2 we found out that the concurrent access to a generic dictionary triggered a race condition bug that caused threads to get stuck at 100% CPU usage. In this part, I&#8217;ll show how easy it is to rewrite the code, using the new thread-safe dictionaries in .NET 4.0, so it&#8217;s protected from race condition bugs like the one I encountered. Enter ConcurrentDictionary The problem can be solved by changing just two lines of code. Instead of using a [...]</p><p>The post <a href="http://improve.dk/debugging-in-production-part-3-thread-safe-dictionaries/">Debugging in Production Part 3 &#8211; Thread-Safe Dictionaries</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><a href="/debugging-in-production-part-2-latent-race-condition-bugs">In part 2 we found out that the concurrent access to a generic dictionary triggered a race condition bug</a> that caused threads to get stuck at 100% CPU usage. In this part, I&#8217;ll show how easy it is to rewrite the code, using the new thread-safe dictionaries in .NET 4.0, so it&#8217;s protected from race condition bugs like the one I encountered.</p>


<h2>Enter ConcurrentDictionary</h2>

<p>The problem can be solved by changing just two lines of code. Instead of using a generic Dictionary, we&#8217;ll change it to a generic ConcurrentDictionary like so:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="csharp"><pre class="de1"><span class="kw1">private</span> <span class="kw1">static</span> <span class="kw1">readonly</span> ConcurrentDictionary<span class="sy0">&lt;</span><span class="kw4">short</span>, ConcurrentDictionary<span class="sy0">&lt;</span>SettingDescription, SettingDescriptionContainer<span class="sy0">&gt;&gt;</span> cache <span class="sy0">=</span>
	<span class="kw3">new</span> ConcurrentDictionary<span class="sy0">&lt;</span><span class="kw4">short</span>, ConcurrentDictionary<span class="sy0">&lt;</span>SettingDescription, SettingDescriptionContainer<span class="sy0">&gt;&gt;</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div></div></div></div></div></div>




<p>As described by this <a href="http://msdn.microsoft.com/en-us/library/dd997369.aspx">MSDN article on adding and removing items from a ConcurrentDictionary</a>, it&#8217;s fully thread-safe:</p>

<blockquote>ConcurrentDictionary<TKey, TValue> is designed for multithreaded scenarios. You do not have to use locks in your code to add or remove items from the collection.</blockquote>

<p>Performance wise ConcurrentDictionary is about 50% slower (anecdotally) than the regular Dictionary type but even if this code is run very often, that is absolutely negligible compared to making just a single database access call.</p>

<p>Besides switching the Dictionary out with a ConcurrentDictionary, we also need to modify the init function since the ConcurrentDictionary way of adding items is slightly different:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="csharp"><pre class="de1"><span class="kw1">private</span> <span class="kw1">static</span> <span class="kw4">object</span> syncRoot <span class="sy0">=</span> <span class="kw3">new</span> <span class="kw4">object</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
<span class="kw1">private</span> <span class="kw1">static</span> <span class="kw4">void</span> init<span class="br0">&#40;</span>IPartnerConfig partnerConfig<span class="br0">&#41;</span>
<span class="br0">&#123;</span>
	<span class="co1">// We only want one inside the init method at a time</span>
	<span class="kw1">lock</span> <span class="br0">&#40;</span>syncRoot<span class="br0">&#41;</span>
	<span class="br0">&#123;</span>
		<span class="kw1">if</span> <span class="br0">&#40;</span>cache<span class="sy0">.</span><span class="me1">ContainsKey</span><span class="br0">&#40;</span>partnerConfig<span class="sy0">.</span><span class="me1">PartnerID</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
			<span class="kw1">return</span><span class="sy0">;</span>
&nbsp;
		<span class="kw1">var</span> dict <span class="sy0">=</span> <span class="kw3">new</span> ConcurrentDictionary<span class="sy0">&lt;</span>SettingDescription, SettingDescriptionContainer<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
		<span class="sy0">...</span> <span class="co1">// Populate the dict variable with data from the database</span>
&nbsp;
		cache<span class="sy0">.</span><span class="me1">AddOrUpdate</span><span class="br0">&#40;</span>partnerConfig<span class="sy0">.</span><span class="me1">PartnerID</span>, dict, <span class="br0">&#40;</span>k, ov<span class="br0">&#41;</span> <span class="sy0">=&gt;</span> dict<span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre></div></div></div></div></div></div></div>




<p>The syncRoot lock ensures that only one initialization is going on at the same time. While not necessary in regards of avoiding the race condition, this will avoid hitting the database multiple times if the init method is being called concurrently. This could be optimized in that there could be a syncRoot object per PartnerID to allow concurrently initializing the cache for each PartneriD. But, alas, I opt to keep it simple as the init method is only called once in the lifetime of the application.</p>

<p>Instead of just adding an item to the cache, we have to use the AddOrUpdate() signature that takes in the key, value and a lambda that returns a new value, in case the key already exists in the dictionary. In this case, no matter if the key exists or not, we want to set it to the new value, so the lambda just returns the same value as passed in the second parameter.</p><p>The post <a href="http://improve.dk/debugging-in-production-part-3-thread-safe-dictionaries/">Debugging in Production Part 3 &#8211; Thread-Safe Dictionaries</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p><img src="http://feeds.feedburner.com/~r/Improvedk/~4/N4CIC2uWMms" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://improve.dk/debugging-in-production-part-3-thread-safe-dictionaries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://improve.dk/debugging-in-production-part-3-thread-safe-dictionaries/</feedburner:origLink></item>
		<item>
		<title>Debugging in Production Part 2 – Latent Race Condition Bugs</title>
		<link>http://feedproxy.google.com/~r/Improvedk/~3/Pj7zLVs_nmM/</link>
		<comments>http://improve.dk/debugging-in-production-part-2-latent-race-condition-bugs/#comments</comments>
		<pubDate>Mon, 15 Apr 2013 09:31:41 +0000</pubDate>
		<dc:creator>Mark S. Rasmussen</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[Tools of the Trade]]></category>
		<category><![CDATA[Windbg]]></category>
		<category><![CDATA[Dump]]></category>
		<category><![CDATA[iis]]></category>
		<category><![CDATA[Locking]]></category>
		<category><![CDATA[Race condition]]></category>
		<category><![CDATA[Threading]]></category>

		<guid isPermaLink="false">http://improve.dk/?p=3248</guid>
		<description><![CDATA[<p>Having analyzed the process dump in part 1, let&#8217;s take a look at the code we suspect of causing the issue, in particular how race condition bugs can be avoided. Looking at the User Code There were three methods in action, all of them in the SettingDescriptionCache class: GetAllDescriptions, init and GetAllDescriptionsAsDictionary. GetAllDescriptions and GetAllDescriptionsAsDictionary are for all intents and purposes identical and both implement a pattern like this: public static IEnumerable&#60;SettingDescriptionContainer&#62; GetAllDescriptions&#40;IPartnerConfig partnerConfig&#41; &#123; // Optimistic return. If it [...]</p><p>The post <a href="http://improve.dk/debugging-in-production-part-2-latent-race-condition-bugs/">Debugging in Production Part 2 &#8211; Latent Race Condition Bugs</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Having <a href="/debugging-in-production-part-1-analyzing-100-cpu-usage-using-windbg">analyzed the process dump in part 1</a>, let&#8217;s take a look at the code we suspect of causing the issue, in particular how race condition bugs can be avoided.</p>


<h2>Looking at the User Code</h2>

<p>There were three methods in action, all of them in the SettingDescriptionCache class: GetAllDescriptions, init and GetAllDescriptionsAsDictionary. GetAllDescriptions and GetAllDescriptionsAsDictionary are for all intents and purposes identical and both implement a pattern like this:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="csharp"><pre class="de1"><span class="kw1">public</span> <span class="kw1">static</span> IEnumerable<span class="sy0">&lt;</span>SettingDescriptionContainer<span class="sy0">&gt;</span> GetAllDescriptions<span class="br0">&#40;</span>IPartnerConfig partnerConfig<span class="br0">&#41;</span>
<span class="br0">&#123;</span>
	<span class="co1">// Optimistic return. If it fails we'll populate the cache and return it.</span>
	<span class="kw1">try</span>
	<span class="br0">&#123;</span>
		<span class="kw1">return</span> cache<span class="br0">&#91;</span>partnerConfig<span class="sy0">.</span><span class="me1">PartnerID</span><span class="br0">&#93;</span><span class="sy0">.</span><span class="me1">Values</span><span class="sy0">;</span>
	<span class="br0">&#125;</span>
	<span class="kw1">catch</span> <span class="br0">&#40;</span>KeyNotFoundException<span class="br0">&#41;</span>
	<span class="br0">&#123;</span>
		init<span class="br0">&#40;</span>partnerConfig<span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="br0">&#125;</span>
&nbsp;
	<span class="kw1">return</span> cache<span class="br0">&#91;</span>partnerConfig<span class="sy0">.</span><span class="me1">PartnerID</span><span class="br0">&#93;</span><span class="sy0">.</span><span class="me1">Values</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div></div></div></div></div></div></div>




<p>Both methods access a static variable defined in the class like so:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="csharp"><pre class="de1"><span class="kw1">private</span> <span class="kw1">static</span> <span class="kw1">readonly</span> Dictionary<span class="sy0">&lt;</span><span class="kw4">short</span>, Dictionary<span class="sy0">&lt;</span>SettingDescription, SettingDescriptionContainer<span class="sy0">&gt;&gt;</span> cache <span class="sy0">=</span>
	<span class="kw3">new</span> Dictionary<span class="sy0">&lt;</span><span class="kw4">short</span>, Dictionary<span class="sy0">&lt;</span>SettingDescription, SettingDescriptionContainer<span class="sy0">&gt;&gt;</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div></div></div></div></div></div>




<p>As this code is being called quite a lot, it&#8217;s written using an optimistic pattern that assumes the cache is populated. This is faster than checking if the cache is populated beforehand, or performing a TryGet(). I&#8217;ve previously blogged about <a href="http://improve.dk/defending-against-the-improbable/">why you shouldn&#8217;t defend against the improbable</a>.</p>


<h2>Dictionaries are Not Thread Safe</h2>

<p>Looking up the <a href="http://msdn.microsoft.com/en-us/library/dd997305.aspx">MSDN article on thread-safe collections</a>, you&#8217;ll notice the following paragraph describes how the standard Dictionary collections are not thread-safe:</p>

<blockquote>The collection classes introduced in the .NET Framework 2.0 are found in the System.Collections.Generic namespace. These include List<T>, Dictionary<TKey, TValue>, and so on. These classes provide improved type safety and performance compared to the .NET Framework 1.0 classes. However, the .NET Framework 2.0 collection classes do not provide any thread synchronization; user code must provide all synchronization when items are added or removed on multiple threads concurrently.</blockquote>

<p>But is this the issue we&#8217;re running into? As there are two dictionaries in action, either one of them could potentially be the culprit. If the partnerConfig.PartnerID value was the same there would be a somewhat higher chance of this really being the issue &#8211; but how can find out what PartnerID values were being passed in to the methods?


<h2>Analyzing Method Parameters Using Windbg</h2>

<p>Back in Windbg, for each of the threads we can run the !CLRStack command once again, but with the -p parameter. This doesn&#8217;t just list the stack trace, but also all of the parameters for each frame.</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="csharp"><pre class="de1">~232s
<span class="sy0">!</span>CLRStack <span class="sy0">-</span>p</pre></div></div></div></div></div></div></div>




<div class='imgwrapper'><div><a href="http://improve.dk/wp-content/uploads/2013/04/Windbg5.png"><img src="http://improve.dk/wp-content/uploads/2013/04/Windbg5.png" alt="Windbg5" width="1024" height="728" class="alignnone size-full wp-image-3251" /></a></div></div>

<p>In the fifth frame, there&#8217;s a value for the IPartnerConfig parameter:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="csharp"><pre class="de1">iPaper<span class="sy0">.</span><span class="me1">BL</span><span class="sy0">.</span><span class="me1">Backend</span><span class="sy0">.</span><span class="me1">Modules</span><span class="sy0">.</span><span class="me1">Paper</span><span class="sy0">.</span><span class="me1">Settings</span><span class="sy0">.</span><span class="me1">SettingDescriptionCache</span><span class="sy0">.</span><span class="me1">GetAllDescriptions</span><span class="br0">&#40;</span>iPaper<span class="sy0">.</span><span class="me1">BL</span><span class="sy0">.</span><span class="me1">Backend</span><span class="sy0">.</span><span class="me1">Infrastructure</span><span class="sy0">.</span><span class="me1">PartnerConfiguration</span><span class="sy0">.</span><span class="me1">IPartnerConfig</span><span class="br0">&#41;</span>
	PARAMETERS<span class="sy0">:</span>
		partnerConfig <span class="br0">&#40;</span>0x00000000543ac650<span class="br0">&#41;</span> <span class="sy0">=</span> 0x0000000260a7bd98</pre></div></div></div></div></div></div></div>




<p>The left side value is the local memory address of the pointer itself whilst the right side is the memory location where the actual PartnerConfig instance is stored. By issuing the do (dump object) command, we can inspect the value itself:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="csharp"><pre class="de1"><span class="sy0">!</span><span class="kw1">do</span> 0x0000000260a7bd98</pre></div></div></div></div></div></div></div>




<div class='imgwrapper'><div><a href="http://improve.dk/wp-content/uploads/2013/04/Windbg6.png"><img src="http://improve.dk/wp-content/uploads/2013/04/Windbg6.png" alt="Windbg6" width="1024" height="728" class="alignnone size-full wp-image-3252" /></a></div></div>

<p>If you look under the Name column then you&#8217;ll be able to pinpoint the individual fields in the PartnerConfiguration instance. In the Value column you can see that the PartnerID field has a value of 230. Doing this for the other four threads yields the same result &#8211; all of them are trying to access the cache value belonging to the PartnerID value of 230!</p>

<p>At this point I can quite confidently say that I&#8217;m sure this is a threading issue related to the non thread-safe Dictionary usage. I would&#8217;ve expected hard failures like like KeyNotFoundException, NullReferenceException and so on. But apparently, under the exact right race conditions, the dictionaries may get stuck at 100% CPU usage.</p>

<p>Stay tuned for part 3 where I&#8217;ll show how to use the Dictionaries in a safe way that avoids issues like these!</p><p>The post <a href="http://improve.dk/debugging-in-production-part-2-latent-race-condition-bugs/">Debugging in Production Part 2 &#8211; Latent Race Condition Bugs</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p><img src="http://feeds.feedburner.com/~r/Improvedk/~4/Pj7zLVs_nmM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://improve.dk/debugging-in-production-part-2-latent-race-condition-bugs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://improve.dk/debugging-in-production-part-2-latent-race-condition-bugs/</feedburner:origLink></item>
		<item>
		<title>Last Chance to Register for SQLSaturday #196 in Copenhagen</title>
		<link>http://feedproxy.google.com/~r/Improvedk/~3/D_e1cTBuZMw/</link>
		<comments>http://improve.dk/last-chance-to-register-for-sqlsaturday-196-in-copenhagen/#comments</comments>
		<pubDate>Tue, 09 Apr 2013 07:33:49 +0000</pubDate>
		<dc:creator>Mark S. Rasmussen</dc:creator>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[Copenhagen]]></category>
		<category><![CDATA[SQLSaturday]]></category>
		<category><![CDATA[SQLSaturday196]]></category>

		<guid isPermaLink="false">http://improve.dk/?p=3332</guid>
		<description><![CDATA[<p>In just a couple of weeks SQLSaturday #196 will be happening on April 20th in Copenhagen, Denmark. This is a free day smack-filled with great speakers, many of them international! Just check out the schedule. I cannot recommend attending SQLSaturdays enough, especially so if they&#8217;re close to you. Whether you&#8217;re a SQL Server or .NET developer, DBA or a BI person, there&#8217;s relevant content for you. Looking beyond the schedule, SQLSaturdays are excellent networking opportunities where people from very different [...]</p><p>The post <a href="http://improve.dk/last-chance-to-register-for-sqlsaturday-196-in-copenhagen/">Last Chance to Register for SQLSaturday #196 in Copenhagen</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>In just a couple of weeks <a href="http://www.sqlsaturday.com/196/eventhome.aspx">SQLSaturday #196</a> will be happening on April 20th in Copenhagen, Denmark. This is a <b>free</b> day smack-filled with great speakers, many of them international! <a href="http://www.sqlsaturday.com/196/schedule.aspx">Just check out the schedule.</a></p>

<p>I cannot recommend attending SQLSaturdays enough, especially so if they&#8217;re close to you. Whether you&#8217;re a SQL Server or .NET developer, DBA or a BI person, there&#8217;s relevant content for you. Looking beyond the schedule, SQLSaturdays are excellent networking opportunities where people from very different business areas meet and mingle.</p>

<p>If you want to go all in, there&#8217;s even three precons on Friday the 19th of April &#8211; one of which I&#8217;m presenting, the other two by <a href="http://mrdenny.com/">Denny Cherry</a> and <a href="http://www.jenstirrup.com/">Jen Stirrup</a>. You can <a href="http://sqlsat196precon.eventbrite.com/">see the lineup and register here</a>.</p><p>The post <a href="http://improve.dk/last-chance-to-register-for-sqlsaturday-196-in-copenhagen/">Last Chance to Register for SQLSaturday #196 in Copenhagen</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p><img src="http://feeds.feedburner.com/~r/Improvedk/~4/D_e1cTBuZMw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://improve.dk/last-chance-to-register-for-sqlsaturday-196-in-copenhagen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://improve.dk/last-chance-to-register-for-sqlsaturday-196-in-copenhagen/</feedburner:origLink></item>
		<item>
		<title>Debugging in Production Part 1 – Analyzing 100% CPU Usage Using Windbg</title>
		<link>http://feedproxy.google.com/~r/Improvedk/~3/TxcdKVbRm3k/</link>
		<comments>http://improve.dk/debugging-in-production-part-1-analyzing-100-cpu-usage-using-windbg/#comments</comments>
		<pubDate>Mon, 08 Apr 2013 09:24:09 +0000</pubDate>
		<dc:creator>Mark S. Rasmussen</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[Tools of the Trade]]></category>
		<category><![CDATA[Windbg]]></category>
		<category><![CDATA[CPU Usage]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Dump]]></category>
		<category><![CDATA[iis]]></category>

		<guid isPermaLink="false">http://improve.dk/?p=3222</guid>
		<description><![CDATA[<p>This is the story of how a simple oversight resulted in a tough to catch bug. As is often the case, it worked on my machine and only manifested itself in production on a live site. In this series we will look at analyzing 100% CPU usage using Windbg. The Symptom Some HTTP requests were being rejected by one of our servers with status 503 indicating that the request queue limit had been reached. Looking at the CPU usage, it [...]</p><p>The post <a href="http://improve.dk/debugging-in-production-part-1-analyzing-100-cpu-usage-using-windbg/">Debugging in Production Part 1 &#8211; Analyzing 100% CPU Usage Using Windbg</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>This is the story of how a simple oversight resulted in a tough to catch bug. As is often the case, it worked on my machine and only manifested itself in production on a live site. In this series we will look at analyzing 100% CPU usage using Windbg.</p>


<h2>The Symptom</h2>

<p>Some HTTP requests were being rejected by one of our servers with status 503 indicating that the request queue limit had been reached. Looking at the CPU usage, it was clear why this was happening.</p>

<div class='imgwrapper'><div><a href="http://improve.dk/wp-content/uploads/2013/04/CPU-Usage.png"><img src="http://improve.dk/wp-content/uploads/2013/04/CPU-Usage.png" alt="CPU Usage" width="801" height="222" class="alignnone size-full wp-image-3223" /></a></div></div>

<p>Initially I <i>fixed</i> the issue by issuing an iisreset, clearing the queue and getting back to normal. But when this started occurring on multiple servers at random times, I knew there was something odd going on.</p>


<h2>Isolating the Server and Creating a Dump</h2>

<p>To analyze what&#8217;s happening, I needed to debug the process on the server while it was going on. So I sat around and waited for the next server to act up, and sure enough, within a couple of hours another one of our servers seemed to be stuck at 100% CPU. Immediately I pulled it out of our load balancers so it wasn&#8217;t being served any new requests, allowing me to do my work without causing trouble for the end users.</p>

<p>In server 2008 it&#8217;s quite easy to create a dump file. Simply fire up the task manager, right click the process and choose &#8220;Create Dump File&#8221;.</p>

<div class='imgwrapper'><div><a href="http://improve.dk/wp-content/uploads/2013/04/Task-Manager.png"><img src="http://improve.dk/wp-content/uploads/2013/04/Task-Manager.png" alt="Task Manager" width="666" height="520" class="alignnone size-full wp-image-3225" /></a></div></div>

<p>Do note that task manager comes in both an x64 and an x86 version. If you run the x64 version and make a dump of an x86 process, it&#8217;ll still create an x64 dump, making it unusable. As such, make sure you use whatever task manager that matches the architecture of the process you want to dump. On an x64 machine (with Windows on the C: drive) you can find the x86 task manager here: C:\Windows\SysWOW64\taskmgr.exe. Note that you can&#8217;t run both at the same time, so make sure to close the x64 taskmgr.exe process before starting the x86 one.</p>

<p>Once the dump has been created, a message will tell you the location of the .DMP file. This is roughly twice the size of the process at the time of the dump, so make sure you have enough space on your C: drive.</p>

<div class='imgwrapper'><div><a href="http://improve.dk/wp-content/uploads/2013/04/Dump.png"><img src="http://improve.dk/wp-content/uploads/2013/04/Dump.png" alt="Dump" width="784" height="305" class="alignnone size-full wp-image-3226" /></a></div></div>


<h2>Finding the Root Cause Using Windbg</h2>

<p>Now that we have the dump, we can open it up in Windbg and look around. You&#8217;ll need to have Windbg installed in the correct version (it comes in both x86 and x64 versions). While Windbg can only officially be installed as part of the whole Windows SDK, Windbg itself is xcopy deploy-able, and is <a href="http://www.windbg.org/">available for download here</a>.</p>

<p>To make things simple, I just run Windbg on the server itself. That way I won&#8217;t run into issues with differing CLR versions being installed on the machine, making debugging quite difficult.</p>

<p>Once Windbg is running, press Ctrl+D and open the .DMP file.</p>

<div class='imgwrapper'><div><a href="http://improve.dk/wp-content/uploads/2013/04/Windbg1.png"><img src="http://improve.dk/wp-content/uploads/2013/04/Windbg1.png" alt="Windbg1" width="1024" height="728" class="alignnone size-full wp-image-3229" /></a></div></div>

<p>The first command you&#8217;ll want to execute is this:</p>

<pre>!loadby sos clr</pre>

<p>This loads in the <a href="http://msdn.microsoft.com/en-us/library/bb190764.aspx">Son of Strike extension</a> that contains a lot of useful methods for debugging .NET code.</p>


<h3>Identifying Runaway Threads</h3>

<p>As we seem to have a runaway code issue, let&#8217;s start out by issuing the following command:</p>

<pre>!runaway</pre>

<div class='imgwrapper'><div><a href="http://improve.dk/wp-content/uploads/2013/04/Windbg2.png"><img src="http://improve.dk/wp-content/uploads/2013/04/Windbg2.png" alt="Windbg2" width="1024" height="728" class="alignnone size-full wp-image-3231" /></a></div></div>

<p>This lists all the threads as well as the time spent executing user mode code. When dealing with a 100% CPU issue, you&#8217;ll generally see  some threads chugging away all the time. In this case it&#8217;s easy to see that looking at just the top four threads, we&#8217;ve already spent over 20 (effective) minutes executing user mode code &#8211; these threads would probably be worth investigating.</p>


<h3>Analyzing CLR Stacks</h3>

<p>Now that we&#8217;ve identified some of the most interesting threads, we can select them one by one like so:<p>

<pre>~Xs</pre>

<p>Switching X out with a thread number (e.g. 234, 232, 238, 259, 328, etc.) allows us to <i>select</i> the thread. Notice how the lower left corner indicates the currently selected thread:</p>

<div class='imgwrapper'><div><a href="http://improve.dk/wp-content/uploads/2013/04/Windbg3.png"><img src="http://improve.dk/wp-content/uploads/2013/04/Windbg3.png" alt="Windbg3" width="1024" height="728" class="alignnone size-full wp-image-3234" /></a></div></div>

<p>Once selected, we can see what the thread is currently doing by executing the following command:</p>

<pre>!CLRStack</pre>

<div class='imgwrapper'><div><a href="http://improve.dk/wp-content/uploads/2013/04/Windbg4.png"><img src="http://improve.dk/wp-content/uploads/2013/04/Windbg4.png" alt="Windbg4" width="1024" height="728" class="alignnone size-full wp-image-3235" /></a></div></div>

<p>Looking at the top frame in the call stack, it seems the thread is stuck in the BCL Dictionary.FindEntry() method:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="csharp"><pre class="de1"><span class="kw5">System.<span class="me1">Collections</span></span><span class="sy0">.</span><span class="me1">Generic</span><span class="sy0">.</span><span class="me1">Dictionary</span>`<span class="nu0">2</span><span class="br0">&#91;</span><span class="br0">&#91;</span><span class="kw5">System</span><span class="sy0">.</span><span class="me1">Int16</span>, mscorlib<span class="br0">&#93;</span>,<span class="br0">&#91;</span><span class="kw5">System</span><span class="sy0">.</span>__Canon, mscorlib<span class="br0">&#93;</span><span class="br0">&#93;</span><span class="sy0">.</span><span class="me1">FindEntry</span><span class="br0">&#40;</span>Int16<span class="br0">&#41;</span></pre></div></div></div></div></div></div></div>




<p>Tracing back just a few more frames, this seems to be invoked from the following user function:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="csharp"><pre class="de1">iPaper<span class="sy0">.</span><span class="me1">BL</span><span class="sy0">.</span><span class="me1">Backend</span><span class="sy0">.</span><span class="me1">Modules</span><span class="sy0">.</span><span class="me1">Paper</span><span class="sy0">.</span><span class="me1">Settings</span><span class="sy0">.</span><span class="me1">SettingDescriptionCache</span><span class="sy0">.</span><span class="me1">GetAllDescriptions</span><span class="br0">&#40;</span><span class="br0">&#41;</span></pre></div></div></div></div></div></div></div>




<p>Performing the same act for the top five threads yields a rather clear unanimous picture:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="csharp"><pre class="de1"><span class="nu0">234</span><span class="sy0">:</span>
<span class="kw5">System.<span class="me1">Collections</span></span><span class="sy0">.</span><span class="me1">Generic</span><span class="sy0">.</span><span class="me1">Dictionary</span>`<span class="nu0">2</span><span class="br0">&#91;</span><span class="br0">&#91;</span><span class="kw5">System</span><span class="sy0">.</span><span class="me1">Int16</span>, mscorlib<span class="br0">&#93;</span>,<span class="br0">&#91;</span><span class="kw5">System</span><span class="sy0">.</span>__Canon, mscorlib<span class="br0">&#93;</span><span class="br0">&#93;</span><span class="sy0">.</span><span class="me1">FindEntry</span><span class="br0">&#40;</span>Int16<span class="br0">&#41;</span>
<span class="sy0">...</span>
<span class="me1">iPaper</span><span class="sy0">.</span><span class="me1">BL</span><span class="sy0">.</span><span class="me1">Backend</span><span class="sy0">.</span><span class="me1">Modules</span><span class="sy0">.</span><span class="me1">Paper</span><span class="sy0">.</span><span class="me1">Settings</span><span class="sy0">.</span><span class="me1">SettingDescriptionCache</span><span class="sy0">.</span><span class="me1">GetAllDescriptions</span><span class="br0">&#40;</span>iPaper<span class="sy0">.</span><span class="me1">BL</span><span class="sy0">.</span><span class="me1">Backend</span><span class="sy0">.</span><span class="me1">Infrastructure</span><span class="sy0">.</span><span class="me1">PartnerConfiguration</span><span class="sy0">.</span><span class="me1">IPartnerConfig</span><span class="br0">&#41;</span>
&nbsp;
<span class="nu0">232</span><span class="sy0">:</span>
<span class="kw5">System.<span class="me1">Collections</span></span><span class="sy0">.</span><span class="me1">Generic</span><span class="sy0">.</span><span class="me1">Dictionary</span>`<span class="nu0">2</span><span class="br0">&#91;</span><span class="br0">&#91;</span><span class="kw5">System</span><span class="sy0">.</span><span class="me1">Int16</span>, mscorlib<span class="br0">&#93;</span>,<span class="br0">&#91;</span><span class="kw5">System</span><span class="sy0">.</span>__Canon, mscorlib<span class="br0">&#93;</span><span class="br0">&#93;</span><span class="sy0">.</span><span class="me1">Insert</span><span class="br0">&#40;</span>Int16, <span class="kw5">System</span><span class="sy0">.</span>__Canon, Boolean<span class="br0">&#41;</span>
<span class="sy0">...</span>
<span class="me1">iPaper</span><span class="sy0">.</span><span class="me1">BL</span><span class="sy0">.</span><span class="me1">Backend</span><span class="sy0">.</span><span class="me1">Modules</span><span class="sy0">.</span><span class="me1">Paper</span><span class="sy0">.</span><span class="me1">Settings</span><span class="sy0">.</span><span class="me1">SettingDescriptionCache</span><span class="sy0">.</span><span class="me1">init</span><span class="br0">&#40;</span>iPaper<span class="sy0">.</span><span class="me1">BL</span><span class="sy0">.</span><span class="me1">Backend</span><span class="sy0">.</span><span class="me1">Infrastructure</span><span class="sy0">.</span><span class="me1">PartnerConfiguration</span><span class="sy0">.</span><span class="me1">IPartnerConfig</span><span class="br0">&#41;</span>
&nbsp;
<span class="nu0">238</span><span class="sy0">:</span>
<span class="kw5">System.<span class="me1">Collections</span></span><span class="sy0">.</span><span class="me1">Generic</span><span class="sy0">.</span><span class="me1">Dictionary</span>`<span class="nu0">2</span><span class="br0">&#91;</span><span class="br0">&#91;</span><span class="kw5">System</span><span class="sy0">.</span><span class="me1">Int16</span>, mscorlib<span class="br0">&#93;</span>,<span class="br0">&#91;</span><span class="kw5">System</span><span class="sy0">.</span>__Canon, mscorlib<span class="br0">&#93;</span><span class="br0">&#93;</span><span class="sy0">.</span><span class="me1">FindEntry</span><span class="br0">&#40;</span>Int16<span class="br0">&#41;</span>
<span class="sy0">...</span>
<span class="me1">iPaper</span><span class="sy0">.</span><span class="me1">BL</span><span class="sy0">.</span><span class="me1">Backend</span><span class="sy0">.</span><span class="me1">Modules</span><span class="sy0">.</span><span class="me1">Paper</span><span class="sy0">.</span><span class="me1">Settings</span><span class="sy0">.</span><span class="me1">SettingDescriptionCache</span><span class="sy0">.</span><span class="me1">GetAllDescriptions</span><span class="br0">&#40;</span>iPaper<span class="sy0">.</span><span class="me1">BL</span><span class="sy0">.</span><span class="me1">Backend</span><span class="sy0">.</span><span class="me1">Infrastructure</span><span class="sy0">.</span><span class="me1">PartnerConfiguration</span><span class="sy0">.</span><span class="me1">IPartnerConfig</span><span class="br0">&#41;</span>
&nbsp;
<span class="nu0">259</span><span class="sy0">:</span>
<span class="kw5">System.<span class="me1">Collections</span></span><span class="sy0">.</span><span class="me1">Generic</span><span class="sy0">.</span><span class="me1">Dictionary</span>`<span class="nu0">2</span><span class="br0">&#91;</span><span class="br0">&#91;</span><span class="kw5">System</span><span class="sy0">.</span><span class="me1">Int16</span>, mscorlib<span class="br0">&#93;</span>,<span class="br0">&#91;</span><span class="kw5">System</span><span class="sy0">.</span>__Canon, mscorlib<span class="br0">&#93;</span><span class="br0">&#93;</span><span class="sy0">.</span><span class="me1">FindEntry</span><span class="br0">&#40;</span>Int16<span class="br0">&#41;</span>
<span class="sy0">...</span>
<span class="me1">iPaper</span><span class="sy0">.</span><span class="me1">BL</span><span class="sy0">.</span><span class="me1">Backend</span><span class="sy0">.</span><span class="me1">Modules</span><span class="sy0">.</span><span class="me1">Paper</span><span class="sy0">.</span><span class="me1">Settings</span><span class="sy0">.</span><span class="me1">SettingDescriptionCache</span><span class="sy0">.</span><span class="me1">GetAllDescriptions</span><span class="br0">&#40;</span>iPaper<span class="sy0">.</span><span class="me1">BL</span><span class="sy0">.</span><span class="me1">Backend</span><span class="sy0">.</span><span class="me1">Infrastructure</span><span class="sy0">.</span><span class="me1">PartnerConfiguration</span><span class="sy0">.</span><span class="me1">IPartnerConfig</span><span class="br0">&#41;</span>
&nbsp;
<span class="nu0">328</span><span class="sy0">:</span>
<span class="kw5">System.<span class="me1">Collections</span></span><span class="sy0">.</span><span class="me1">Generic</span><span class="sy0">.</span><span class="me1">Dictionary</span>`<span class="nu0">2</span><span class="br0">&#91;</span><span class="br0">&#91;</span><span class="kw5">System</span><span class="sy0">.</span><span class="me1">Int16</span>, mscorlib<span class="br0">&#93;</span>,<span class="br0">&#91;</span><span class="kw5">System</span><span class="sy0">.</span>__Canon, mscorlib<span class="br0">&#93;</span><span class="br0">&#93;</span><span class="sy0">.</span><span class="me1">FindEntry</span><span class="br0">&#40;</span>Int16<span class="br0">&#41;</span>
<span class="sy0">...</span>
<span class="me1">iPaper</span><span class="sy0">.</span><span class="me1">BL</span><span class="sy0">.</span><span class="me1">Backend</span><span class="sy0">.</span><span class="me1">Modules</span><span class="sy0">.</span><span class="me1">Paper</span><span class="sy0">.</span><span class="me1">Settings</span><span class="sy0">.</span><span class="me1">SettingDescriptionCache</span><span class="sy0">.</span><span class="me1">GetAllDescriptionsAsDictionary</span><span class="br0">&#40;</span>iPaper<span class="sy0">.</span><span class="me1">BL</span><span class="sy0">.</span><span class="me1">Backend</span><span class="sy0">.</span><span class="me1">Infrastructure</span><span class="sy0">.</span><span class="me1">PartnerConfiguration</span><span class="sy0">.</span><span class="me1">IPartnerConfig</span><span class="br0">&#41;</span></pre></div></div></div></div></div></div></div>




<p>Interestingly, all of the threads are stuck inside internal methods in the base class library Dictionary class. All of them are invoked from the user SettingDescriptionCache class, though from different methods.</p>

<p>Stay tuned for <a href="/debugging-in-production-part-2-latent-race-condition-bugs/">part 2 where we&#8217;ll dive into the user code and determine what&#8217;s happening</a>!</p><p>The post <a href="http://improve.dk/debugging-in-production-part-1-analyzing-100-cpu-usage-using-windbg/">Debugging in Production Part 1 &#8211; Analyzing 100% CPU Usage Using Windbg</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p><img src="http://feeds.feedburner.com/~r/Improvedk/~4/TxcdKVbRm3k" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://improve.dk/debugging-in-production-part-1-analyzing-100-cpu-usage-using-windbg/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://improve.dk/debugging-in-production-part-1-analyzing-100-cpu-usage-using-windbg/</feedburner:origLink></item>
		<item>
		<title>Native Chrome Flash Player Disabled by Itself All of a Sudden</title>
		<link>http://feedproxy.google.com/~r/Improvedk/~3/i1HUUL3cto4/</link>
		<comments>http://improve.dk/native-chrome-flash-player-disabled-by-itself/#comments</comments>
		<pubDate>Wed, 27 Feb 2013 14:52:25 +0000</pubDate>
		<dc:creator>Mark S. Rasmussen</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[Plugin]]></category>

		<guid isPermaLink="false">http://improve.dk/?p=3178</guid>
		<description><![CDATA[<p>At my job we&#8217;ve got a product that relies heavily on Flash. The last couple of days I&#8217;ve had a number of users complain that, all of a sudden, they couldn&#8217;t view Flash content any more. Common for all of them were their browser &#8211; Chrome. It would seem that, somehow, the native Chrome Flash player got disabled by itself all of a sudden. What&#8217;s especially unusual about this is that Chrome has a built-in Flash player, so if anyone, [...]</p><p>The post <a href="http://improve.dk/native-chrome-flash-player-disabled-by-itself/">Native Chrome Flash Player Disabled by Itself All of a Sudden</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>At my job we&#8217;ve got a product that relies heavily on Flash. The last couple of days I&#8217;ve had a number of users complain that, all of a sudden, they couldn&#8217;t view Flash content any more. Common for all of them were their browser &#8211; Chrome. It would seem that, somehow, the native Chrome Flash player got disabled by itself all of a sudden.</p>

<p>What&#8217;s especially unusual about this is that Chrome has a built-in Flash player, so if anyone, Chrome users should be able to view Flash content. Digging deeper I found that the built-in Flash player extension had been disabled. To check if that&#8217;s the case, see here:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="tsql"><pre class="de1">Chrome Settings <span class="sy0">=&gt;</span> Show advanced settings... <span class="sy0">=&gt;</span> Privacy <span class="sy0">=&gt;</span> Content settings... <span class="sy0">=&gt;</span> Plug<span class="sy0">-</span>ins <span class="sy0">=&gt;</span> Disable individual plug<span class="sy0">-</span>ins...</pre></div></div></div></div></div></div></div>




<div class='imgwrapper'><div><a href="http://improve.dk/wp-content/uploads/2013/02/Flash.png"><img src="http://improve.dk/wp-content/uploads/2013/02/Flash.png" alt="Flash" width="545" height="255" class="alignnone size-full wp-image-3181" /></a></div></div>

<p>By just clicking &#8220;Enable&#8221;, everything is working again. But how did it get disabled? This is such a convoluted place to find that I know the users haven&#8217;t done so themselves. Looking at Twitter, it seems we&#8217;re not alone in seeing this:</p>

<blockquote class="twitter-tweet" width="500" lang="da"><p>I wonder why my Chrome Flash Player plugin suddenly disabled itself whilst I was listening to the radio; very odd. Enabled &amp; all seems fine.</p>&mdash; Gill (@AnandaWoW) <a href="https://twitter.com/AnandaWoW/status/306751670258388992">27. feb. 2013</a></blockquote><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>


<blockquote class="twitter-tweet" width="500" lang="da"><p>but sorted it out :3 stupid chrome had adobe flash player listed as &#8216;disabled&#8217; -.- which is stupid cause flash player runs everything D:</p>&mdash; BazingaofSuburbia (@RachofSuburbia) <a href="https://twitter.com/RachofSuburbia/status/306426446438617088">26. feb. 2013</a></blockquote><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>


<blockquote class="twitter-tweet" width="500" lang="da"><p>Crisis averted. Turns out the flash player in Chrome had been disabled. Video watching can now commence :)</p>&mdash; Lin (@linnysvault) <a href="https://twitter.com/linnysvault/status/306420799550660608">26. feb. 2013</a></blockquote><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>


<blockquote class="twitter-tweet" width="500" lang="da"><p>@<a href="https://twitter.com/astracius">astracius</a> And all sorted thanks to Chrome being awesome (no idea how Flash was disabled though).</p>&mdash; David Wilson (@Astracius) <a href="https://twitter.com/Astracius/status/306351364710219776">26. feb. 2013</a></blockquote><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>


<blockquote class="twitter-tweet" width="500" lang="da"><p>@<a href="https://twitter.com/kevinmenzel">kevinmenzel</a> nah, just realized flash somehow got disabled in google chrome. but thank you</p>&mdash; junctionette (@junctionette) <a href="https://twitter.com/junctionette/status/306230350131130370">26. feb. 2013</a></blockquote><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>


<blockquote class="twitter-tweet" width="500" lang="da"><p>Who the fuck went on the computer and disabled Flash on Google Chrome? Why would someone do that? That was annoying.</p>&mdash; Nathan. (@envyonthetoast) <a href="https://twitter.com/envyonthetoast/status/306210978201219073">26. feb. 2013</a></blockquote><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>

<p>&#8230; I think you get the picture. It seems that all of our users had just had their Flash player auto update itself. I&#8217;m wondering, could the Internet Explorer Flash plugin perhaps updated itself and, by mistake, disabled the Chrome plugin? If the built-in Chrome Flash player is disabled, Chrome will try to use the regular Flash plugin. However, the Internet Explorer version won&#8217;t work in Chrome, so that won&#8217;t work.</p>

<p>Anyone else experienced this? Any tips on what&#8217;s causing it? The fix is simple, but I&#8217;d really like to understand what&#8217;s causing this, as well as knowing how widespread the issue is.</p><p>The post <a href="http://improve.dk/native-chrome-flash-player-disabled-by-itself/">Native Chrome Flash Player Disabled by Itself All of a Sudden</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p><img src="http://feeds.feedburner.com/~r/Improvedk/~4/i1HUUL3cto4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://improve.dk/native-chrome-flash-player-disabled-by-itself/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://improve.dk/native-chrome-flash-player-disabled-by-itself/</feedburner:origLink></item>
		<item>
		<title>SQLSaturday #196 – Presenting a Precon</title>
		<link>http://feedproxy.google.com/~r/Improvedk/~3/VBKUigv5oBU/</link>
		<comments>http://improve.dk/sqlsaturday-196-presenting-a-precon/#comments</comments>
		<pubDate>Thu, 21 Feb 2013 10:11:51 +0000</pubDate>
		<dc:creator>Mark S. Rasmussen</dc:creator>
				<category><![CDATA[Conferences & Presenting]]></category>
		<category><![CDATA[Denmark]]></category>
		<category><![CDATA[Precon]]></category>
		<category><![CDATA[Presenting]]></category>
		<category><![CDATA[SQLSaturday]]></category>

		<guid isPermaLink="false">http://improve.dk/?p=3159</guid>
		<description><![CDATA[<p>Seeing SQLSaturday events sprawling up all over the world makes me all warm and fuzzy inside. Long have I been considering whether one might happen in Denmark, but to be honest, I didn&#8217;t think the audience would be big enough. I&#8217;m biased though as I&#8217;ve mainly attended events outside of Denmark, and thus most of my acquaintances have been non-Danish. But lo and behold, Régis Baccaro just announced that SQLSaturday #196 now has 101 registered attendees! And best of all, [...]</p><p>The post <a href="http://improve.dk/sqlsaturday-196-presenting-a-precon/">SQLSaturday #196 &#8211; Presenting a Precon</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Seeing SQLSaturday events sprawling up all over the world makes me all warm and fuzzy inside. Long have I been considering whether one might happen in Denmark, but to be honest, I didn&#8217;t think the audience would be big enough. I&#8217;m biased though as I&#8217;ve mainly attended events outside of Denmark, and thus most of my acquaintances have been non-Danish. But lo and behold, Régis Baccaro just announced that <a href="http://www.sqlsaturday.com/196/eventhome.aspx">SQLSaturday #196</a> now has <a href="https://twitter.com/regbac/status/304320528095793154">101 registered attendees</a>! And best of all, it&#8217;s held in Copenhagen on the 20th of April.</p>

<div class='imgwrapper right'><div><a href="http://improve.dk/wp-content/uploads/2013/02/logo.png"><img src="http://improve.dk/wp-content/uploads/2013/02/logo.png" alt="logo" width="236" height="115" class="alignnone size-full wp-image-3164" /></a></div></div>

<p>Having just about 100 people attend my <a href="http://warmcrocconf.net/Marksr.aspx">Top X SQL Server Developer Mistakes session at Warm Crocodile</a> recently made me realize just how popular SQL Server really is. Nosql might be the hype, but when it comes to business, quite a lot of developers are &#8220;stuck&#8221; with SQL Server on a daily basis. For the same reason, I absolutely cannot recommend going to SQLSaturday #196 enough! It&#8217;s free, it&#8217;s an excellent networking opportunity and it&#8217;s sure to be full of great speakers and content. Go ahead &#8211; <a href="http://www.sqlsaturday.com/196/register.aspx">register here</a>!</p>

<div class='imgwrapper right'><div><a href="http://improve.dk/wp-content/uploads/2013/02/392531_496414643720736_540150277_n.jpg" title="Presenting the precon at SQLSaturday #162 in Cambridge"><img src="http://improve.dk/wp-content/uploads/2013/02/392531_496414643720736_540150277_n-250x166.jpg" alt="392531_496414643720736_540150277_n" width="250" height="166" class="alignnone size-small wp-image-3168" /></a></div></div>

<p>I&#8217;ll have the pleasure and honor of presenting my <a href="http://sqlsat196precon.eventbrite.com/">A Deep Dive Into the Depths of the SQL Server Storage Engine and MDF File Format</a> precon on the 19th of April, the day before the SQLSaturday event itself. It&#8217;s not the first time I&#8217;m presenting this precon, in fact, this&#8217;ll be my fifth time. This means I&#8217;ve now had a number of chances to test my content and optimize the format to ensure you get maximum value out of the day. If you&#8217;re planning on attending and have any special requests or questions regarding the content, please do let me know in the comments here!</p>

<p>If storage internals isn&#8217;t your thing, there are two other top notch presenters &#8211; <a href="http://www.jenstirrup.com/">Jen Stirrup</a> and <a href="http://itknowledgeexchange.techtarget.com/sql-server/">Denny Cherry</a>. Jen will be presenting a <a href="http://sqlsat196precon.eventbrite.com/">Data Visualisation Deep-Dive using SQL Server 2012</a> while Denny will present on <a href="http://sqlsat196precon.eventbrite.com/">SQL Server 2012 in a Highly Available World</a>.</p><p>The post <a href="http://improve.dk/sqlsaturday-196-presenting-a-precon/">SQLSaturday #196 &#8211; Presenting a Precon</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p><img src="http://feeds.feedburner.com/~r/Improvedk/~4/VBKUigv5oBU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://improve.dk/sqlsaturday-196-presenting-a-precon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://improve.dk/sqlsaturday-196-presenting-a-precon/</feedburner:origLink></item>
		<item>
		<title>Blog Revamp</title>
		<link>http://feedproxy.google.com/~r/Improvedk/~3/5tASYDAe0TY/</link>
		<comments>http://improve.dk/blog-revamp/#comments</comments>
		<pubDate>Wed, 20 Feb 2013 10:13:45 +0000</pubDate>
		<dc:creator>Mark S. Rasmussen</dc:creator>
				<category><![CDATA[Life]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Github]]></category>
		<category><![CDATA[Subtext]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[Windows Live Writer]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[WXR]]></category>

		<guid isPermaLink="false">http://improve.dk/?p=3139</guid>
		<description><![CDATA[<p>Having been at it for almost 11 years, I&#8217;ve been through a number of blog revamps through the time. And here we are, once again. I first launched the blog back in 2002, though it was in Danish back then. In 2006 I decided to start over, removed all my Danish content and began blogging in English &#8211; at that time, I wrote my own blog engine in a couple of days on a couch in Henderson, Nevada, anxiously waiting [...]</p><p>The post <a href="http://improve.dk/blog-revamp/">Blog Revamp</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Having been at it for almost 11 years, I&#8217;ve been through a number of blog revamps through the time. And here we are, once again.</p>

<p><a href="http://web.archive.org/web/20020929133654/http://www.improve.dk/">I first launched the blog back in 2002</a>, though it was in Danish back then. In 2006 I decided to start over, removed all my Danish content and began blogging in English &#8211; at that time, I wrote my own blog engine in a couple of days on a couch in Henderson, Nevada, anxiously waiting to turn 21 so I could participate in the World Series of Poker.</a></p>

<p>Back in 2011 I chose to migrate all my content onto <a href="http://subtextproject.com/">Subtext</a>. What I failed to notice was that the project was pretty much dead, so it was a migration doomed to be still born. It did however allow me access to <a href="http://en.wikipedia.org/wiki/Windows_Live_Writer">Windows Live Writer</a> which served its purpose &#8211; it got me blogging again due to its simplicity in use. However, I quickly started to struggle with Subtext as templating was beyond difficult and I had to resort to ugly hacks to make it work the best I could.</p>

<div class='imgwrapper right'><div><a href="http://improve.dk/wp-content/uploads/2013/02/wp-blue-640x9601.png"><img src="http://improve.dk/wp-content/uploads/2013/02/wp-blue-640x9601-133x200.png" alt="wp-blue-640x960" width="133" height="200" class="alignnone size-small wp-image-3151" /></a></div></div>

<p>And so it was time for yet another revamp, this time, hopefully the last. Converting everything into WordPress ought to be a simple task, if it wasn&#8217;t for the fact that I had almost 250 posts and 700 comments. Most of them stemming from my homebrewed system, later haphazardly migrated to Subtext, and now lying before WordPress. I had to write a custom exporter to get most of my content from Subtext into the <a href="http://ipggi.wordpress.com/2011/03/16/the-wordpress-extended-rss-wxr-exportimport-xml-document-format-decoded-and-explained/">WordPress WXR format</a>. Dealing with attachments, encoding and comments was a major pain. Once I had everything into WordPress, I had to go through each and every post and manually format the contents &#8211; having seven years of legacy left little to no structure, making it impossible to style.</p>

<p>At this point, all I needed to do was to find a good theme and I was up and running. Unfortunately I tend to be quite picky, so I couldn&#8217;t find anything I really liked. In the end, I ended up writing my own theme, <a href="https://github.com/improvedk/improve.dk">which I&#8217;ve just published to Github</a>. My main priority has been to create a very simplistic theme that worked great across devices, while allowing me to post easily readable code snippets. If you have any suggestions for improvements, I&#8217;d love to hear them!</p><p>The post <a href="http://improve.dk/blog-revamp/">Blog Revamp</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p><img src="http://feeds.feedburner.com/~r/Improvedk/~4/5tASYDAe0TY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://improve.dk/blog-revamp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://improve.dk/blog-revamp/</feedburner:origLink></item>
		<item>
		<title>Top X SQL Server Developer Mistakes</title>
		<link>http://feedproxy.google.com/~r/Improvedk/~3/--31rQGwjaM/</link>
		<comments>http://improve.dk/top-x-sql-server-developer-mistakes/#comments</comments>
		<pubDate>Thu, 17 Jan 2013 21:05:42 +0000</pubDate>
		<dc:creator>Mark S. Rasmussen</dc:creator>
				<category><![CDATA[Conferences & Presenting]]></category>
		<category><![CDATA[Warm Crocodile]]></category>

		<guid isPermaLink="false">http://improve.dk/archive/2013/01/17/top-x-sql-server-developer-mistakes.aspx</guid>
		<description><![CDATA[<p>It&#8217;s been a long day, and I&#8217;m finally on my way home from Copenhagen to Aarhus. Unfortunately I wasn&#8217;t able to attend the first day of the Warm Crocodile conference yesterday. Thankfully I was able to attend today, and even better, I got a chance to present my &#8220;Top X SQL Server Developer Mistakes&#8221; session today, and I&#8217;d like to thank everybody who showed up and helped fill the room to its limit. I got a lot of excellent questions [...]</p><p>The post <a href="http://improve.dk/top-x-sql-server-developer-mistakes/">Top X SQL Server Developer Mistakes</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>It&#8217;s been a long day, and I&#8217;m finally on my way home from Copenhagen to Aarhus. Unfortunately I wasn&#8217;t able to attend the first day of the Warm Crocodile conference yesterday. Thankfully I was able to attend today, and even better, I got a chance to present my &#8220;Top X SQL Server Developer Mistakes&#8221; session today, and I&#8217;d like to thank everybody who showed up and helped fill the room to its limit. I got a lot of excellent questions during, as well as after, the session. If I missed yours, please do <a href="mailto:mark@improve.dk">get in touch</a>.</p>

<p>Both slides, demos and source samples are available on Github:<br />
<a href="https://github.com/improvedk/Presentation-TopXSQLServerDeveloperMIstakes" target="_blank">https://github.com/improvedk/Presentation-TopXSQLServerDeveloperMIstakes</a></p><p>The post <a href="http://improve.dk/top-x-sql-server-developer-mistakes/">Top X SQL Server Developer Mistakes</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p><img src="http://feeds.feedburner.com/~r/Improvedk/~4/--31rQGwjaM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://improve.dk/top-x-sql-server-developer-mistakes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://improve.dk/top-x-sql-server-developer-mistakes/</feedburner:origLink></item>
		<item>
		<title>And Thus I Lost My Introduction</title>
		<link>http://feedproxy.google.com/~r/Improvedk/~3/2tSHHgiTlPs/</link>
		<comments>http://improve.dk/and-thus-i-lost-my-introduction/#comments</comments>
		<pubDate>Tue, 01 Jan 2013 19:20:28 +0000</pubDate>
		<dc:creator>Mark S. Rasmussen</dc:creator>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[Misc]]></category>
		<category><![CDATA[MVP]]></category>

		<guid isPermaLink="false">http://improve.dk/archive/2013/01/01/and-thus-i-lost-my-introduction.aspx</guid>
		<description><![CDATA[<p>Seeing as most of my presentations are rather technical, I like to start by pointing out the fact that I have no finished higher education (though in progress), no major certifications or recognitions/awards. This leaves a perfect opportunity for me to explain, from the ground up, why I still feel qualified to be standing in front of the audience. Today I can no longer use that introduction, as I’ve been awarded as a Microsoft MVP (SQL Server) for 2013. I’m [...]</p><p>The post <a href="http://improve.dk/and-thus-i-lost-my-introduction/">And Thus I Lost My Introduction</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Seeing as most of my presentations are rather technical, I like to start by pointing out the fact that I have no finished higher education (though in progress), no major certifications or recognitions/awards. This leaves a perfect opportunity for me to explain, from the ground up, why I still feel qualified to be standing in front of the audience.</p>

<p>Today I can no longer use that introduction, as I’ve been awarded as a Microsoft MVP (SQL Server) for 2013. I’m honored to receive the award, but mostly, I’m thankful to my friends in the SQL Family.</p>

<p>The last couple of years have been busy, 2012 definitely taking the cake, by my standards. Through my SQL Server engagement I’ve made countless of friends across the world &#8211; The Netherlands, Slovenia, Denmark, Germany, Austria, Sweden, all over the US, South Africa, UK, and many more. I remember how my parents worried about how you couldn’t make friends through the computer… While generally being right, on this point, they were not.</p>

<p>As 2012 neared its end, I also promised myself that I would slow down a tad in 2013. I will still try to keep that promise. I simply cannot afford to travel around as much as I did last year, and I really want to trade just a bit of conference travel for pure leisure travel time. However, this doesn’t mean I’ll go into hibernation for the duration of 2012. Currently I’m scheduled to be presenting at the <a href="http://warmcrocconf.net/" target="_blank">Warm Crocodile</a> conference in Copenhagen on January 17th and I know I’ll do my utmost to attend the PASS Summit this year, having missed it in 2012. What else 2013 will bring, time will tell :)</p><p>The post <a href="http://improve.dk/and-thus-i-lost-my-introduction/">And Thus I Lost My Introduction</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p><img src="http://feeds.feedburner.com/~r/Improvedk/~4/2tSHHgiTlPs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://improve.dk/and-thus-i-lost-my-introduction/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://improve.dk/and-thus-i-lost-my-introduction/</feedburner:origLink></item>
		<item>
		<title>Where Does SQL Server Store the Source for Stored Procedures?</title>
		<link>http://feedproxy.google.com/~r/Improvedk/~3/NCge4qiOGbI/</link>
		<comments>http://improve.dk/where-does-sql-server-store-the-source-for-stored-procedures/#comments</comments>
		<pubDate>Mon, 27 Aug 2012 01:18:52 +0000</pubDate>
		<dc:creator>Mark S. Rasmussen</dc:creator>
				<category><![CDATA[Internals]]></category>
		<category><![CDATA[OrcaMDF]]></category>
		<category><![CDATA[DMV]]></category>
		<category><![CDATA[Stored procedures]]></category>

		<guid isPermaLink="false">http://improve.dk/archive/2012/08/26/where-does-sql-server-store-the-source-for-stored-procedures.aspx</guid>
		<description><![CDATA[<p>At the moment I’m working on extending OrcaMDF Studio to not only list base tables, DMVs and tables, but also stored procedures. That’s easy enough, we just need to query sys.procedures – or that is, the sys.sysschobjs base table, since the sys.procedures DMV isn’t available when SQL Server isn’t running. However, I don’t want to just list the stored procedures, I also want to present the source code in them. That brings up a new task – retrieving said source [...]</p><p>The post <a href="http://improve.dk/where-does-sql-server-store-the-source-for-stored-procedures/">Where Does SQL Server Store the Source for Stored Procedures?</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>At the moment I’m working on extending <a href="https://github.com/improvedk/OrcaMDF" target="_blank">OrcaMDF Studio</a> to not only list base tables, DMVs and tables, but also stored procedures. That’s easy enough, we just need to query sys.procedures – or that is, the sys.sysschobjs base table, since the sys.procedures DMV isn’t available when SQL Server isn’t running.</p>

<p>However, I don’t want to just list the stored procedures, I also want to present the source code in them. That brings up a new task – retrieving said source code. Where is it stored? I wasn’t able to find anything on Google, so let’s take a look for ourselves!</p>

<p>I’ve created a new empty database with a data file of three megabytes. In this database, I’ve created a single stored procedure like so:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="tsql"><pre class="de1"><span class="kw1">SET</span> ANSI_<span class="sy0">NULL</span>S <span class="kw1">ON</span>
GO
<span class="kw1">SET</span> QUOTED_IDENTIFIER <span class="kw1">ON</span>
GO
<span class="co1">-- =============================================</span>
<span class="co1">-- Author:		</span>
<span class="co1">-- Create date: </span>
<span class="co1">-- Description:	</span>
<span class="co1">-- =============================================</span>
<span class="kw1">CREATE</span> <span class="kw1">PROCEDURE</span> XYZ
	<span class="kw1">AS</span>
<span class="kw1">BEGIN</span>
	<span class="co1">-- SET NOCOUNT ON added to prevent extra result sets from</span>
	<span class="co1">-- interfering with SELECT statements.</span>
	<span class="kw1">SET</span> <span class="kw1">NOCOUNT</span> <span class="kw1">ON</span>;
&nbsp;
    <span class="co1">-- Insert statements for procedure here</span>
	<span class="kw1">SELECT</span> <span class="st0">'AABBCC'</span> <span class="kw1">AS</span> <span class="kw1">Output</span>
<span class="kw1">END</span></pre></div></div></div></div></div></div></div>




<p>Now when I select from sys.procedures, we can see that the procedure has object ID 2105058535:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="tsql"><pre class="de1"><span class="kw1">select</span> <span class="sy0">*</span> <span class="kw1">from</span> sys.<span class="me1">procedures</span></pre></div></div></div></div></div></div></div>




<div class="imgwrapper"><div><a href="http://improve.dk/wp-content/uploads/2012/08/image_2.png"><img class="alignnone size-full wp-image-2262" alt="image_2" src="http://improve.dk/wp-content/uploads/2012/08/image_2.png" width="349" height="64" /></a></div></div>

<p>So far so good. We can then retrieve the definition itself as an nvarchar(MAX) by querying sys.sql_modules like so:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="tsql"><pre class="de1"><span class="kw1">select</span> <span class="sy0">*</span> <span class="kw1">from</span> sys.<span class="me1">sql_modules</span> <span class="kw1">where</span> <span class="kw2">object_id</span> <span class="sy0">=</span> <span class="nu0">2105058535</span></pre></div></div></div></div></div></div></div>




<div class="imgwrapper"><div><a href="http://improve.dk/wp-content/uploads/2012/08/image_4.png"><img class="alignnone size-full wp-image-2263" alt="image_4" src="http://improve.dk/wp-content/uploads/2012/08/image_4.png" width="563" height="65" /></a></div></div>

<p>And there you have it, the source code for the XYZ procedure! But hold on a moment, while I’ve gotten the object ID for the procedure by querying the sys.sysschobjs base table, I don’t have access to sys.sql_modules yet, as that’s a view and not a base table. Let’s take a look at where sys.sql_modules gets the definition from:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="tsql"><pre class="de1"><span class="kw1">select</span> object_definition<span class="br0">&#40;</span><span class="kw2">object_id</span><span class="br0">&#40;</span><span class="st0">'sys.sql_modules'</span><span class="br0">&#41;</span><span class="br0">&#41;</span></pre></div></div></div></div></div></div></div>





<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="tsql"><pre class="de1"><span class="kw1">SELECT</span>
	<span class="kw2">object_id</span> <span class="sy0">=</span> o.<span class="me1">id</span>,
	definition <span class="sy0">=</span> Object_definition<span class="br0">&#40;</span>o.<span class="me1">id</span><span class="br0">&#41;</span>,
	uses_ansi_nulls <span class="sy0">=</span> Sysconv<span class="br0">&#40;</span><span class="kw1">bit</span>, o.<span class="me1">status</span> <span class="sy0">&amp;</span> 0x40000<span class="br0">&#41;</span>, <span class="co1">-- OBJMOD_ANSINULLS</span>
	uses_quoted_identifier <span class="sy0">=</span> sysconv<span class="br0">&#40;</span><span class="kw1">bit</span>, o.<span class="me1">status</span> <span class="sy0">&amp;</span> 0x80000<span class="br0">&#41;</span>,   <span class="co1">-- OBJMOD_QUOTEDIDENT</span>
	is_schema_bound <span class="sy0">=</span> sysconv<span class="br0">&#40;</span><span class="kw1">bit</span>, o.<span class="me1">status</span> <span class="sy0">&amp;</span> 0x20000<span class="br0">&#41;</span>,    <span class="co1">-- OBJMOD_SCHEMABOUND</span>
	uses_database_collation <span class="sy0">=</span> sysconv<span class="br0">&#40;</span><span class="kw1">bit</span>, o.<span class="me1">status</span> <span class="sy0">&amp;</span> 0x100000<span class="br0">&#41;</span>,  <span class="co1">-- OBJMOD_USESDBCOLL</span>
	is_recompiled <span class="sy0">=</span> sysconv<span class="br0">&#40;</span><span class="kw1">bit</span>, o.<span class="me1">status</span> <span class="sy0">&amp;</span> 0x400000<span class="br0">&#41;</span>,     <span class="co1">-- OBJMOD_NOCACHE</span>
	null_on_null_input <span class="sy0">=</span> sysconv<span class="br0">&#40;</span><span class="kw1">bit</span>, o.<span class="me1">status</span> <span class="sy0">&amp;</span> 0x200000<span class="br0">&#41;</span>,   <span class="co1">-- OBJMOD_NULLONNULL</span>
	execute_as_principal_id <span class="sy0">=</span> x.<span class="me1">indepid</span>
<span class="kw1">FROM</span>
	sys.<span class="me1">sysschobjs</span> o
<span class="kw1">LEFT</span> <span class="sy0">JOIN</span>
	sys.<span class="me1">syssingleobjrefs</span> x <span class="kw1">ON</span> x.<span class="me1">depid</span> <span class="sy0">=</span> o.<span class="me1">id</span> <span class="sy0">AND</span> x.<span class="kw1">class</span> <span class="sy0">=</span> <span class="nu0">22</span> <span class="sy0">AND</span> x.<span class="me1">depsubid</span> <span class="sy0">=</span> <span class="nu0">0</span> <span class="co1">-- SRC_OBJEXECASOWNER</span>
<span class="kw1">WHERE</span>
	o.<span class="me1">pclass</span> <span class="sy0">&lt;&gt;</span> <span class="nu0">100</span> <span class="sy0">AND</span>
	<span class="br0">&#40;</span>
		<span class="br0">&#40;</span>o.<span class="me1">type</span> <span class="sy0">=</span> <span class="st0">'TR'</span> <span class="sy0">AND</span> has_access<span class="br0">&#40;</span><span class="st0">'TR'</span>, o.<span class="me1">id</span>, o.<span class="me1">pid</span>, o.<span class="me1">nsclass</span><span class="br0">&#41;</span> <span class="sy0">=</span> <span class="nu0">1</span><span class="br0">&#41;</span> <span class="sy0">OR</span>
		<span class="br0">&#40;</span>type <span class="sy0">IN</span> <span class="br0">&#40;</span><span class="st0">'P'</span>,<span class="st0">'V'</span>,<span class="st0">'FN'</span>,<span class="st0">'IF'</span>,<span class="st0">'TF'</span>,<span class="st0">'RF'</span>,<span class="st0">'IS'</span><span class="br0">&#41;</span> <span class="sy0">AND</span> has_access<span class="br0">&#40;</span><span class="st0">'CO'</span>, o.<span class="me1">id</span><span class="br0">&#41;</span> <span class="sy0">=</span> <span class="nu0">1</span><span class="br0">&#41;</span> <span class="sy0">OR</span>
		<span class="br0">&#40;</span>type <span class="sy0">IN</span> <span class="br0">&#40;</span><span class="st0">'R'</span>,<span class="st0">'D'</span><span class="br0">&#41;</span> <span class="sy0">AND</span> o.<span class="me1">pid</span> <span class="sy0">=</span> <span class="nu0">0</span><span class="br0">&#41;</span>
	<span class="br0">&#41;</span></pre></div></div></div></div></div></div></div>




<p>Hmmm, so sys.sql_modules gets the source by using the object_definition system function. Unfortunately, the following doesn’t work:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="tsql"><pre class="de1"><span class="kw1">select</span> object_definition<span class="br0">&#40;</span><span class="kw2">object_id</span><span class="br0">&#40;</span><span class="st0">'object_definition'</span><span class="br0">&#41;</span><span class="br0">&#41;</span></pre></div></div></div></div></div></div></div>




<div class="imgwrapper"><div><a href="http://improve.dk/wp-content/uploads/2012/08/image_6.png"><img class="alignnone size-full wp-image-2264" alt="image_6" src="http://improve.dk/wp-content/uploads/2012/08/image_6.png" width="154" height="73" /></a></div></div>

<p>I happen to remember that sys.sql_modules is a replacement for the, now deprecated, sys.syscomments legacy view. Let’s take a look at where that one gets the source from:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="tsql"><pre class="de1"><span class="kw1">select</span> object_definition<span class="br0">&#40;</span><span class="kw2">object_id</span><span class="br0">&#40;</span><span class="st0">'sys.syscomments'</span><span class="br0">&#41;</span><span class="br0">&#41;</span></pre></div></div></div></div></div></div></div>





<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="tsql"><pre class="de1"><span class="kw1">SELECT</span>
	o.<span class="me1">id</span> <span class="kw1">AS</span> id,  
	<span class="kw1">convert</span><span class="br0">&#40;</span><span class="kw1">smallint</span>, <span class="kw1">case</span> <span class="kw1">when</span> o.<span class="me1">type</span> in <span class="br0">&#40;</span><span class="st0">'P'</span>, <span class="st0">'RF'</span><span class="br0">&#41;</span> <span class="kw1">then</span> <span class="nu0">1</span> <span class="kw1">else</span> <span class="nu0">0</span> <span class="kw1">end</span><span class="br0">&#41;</span> <span class="kw1">AS</span> number,  
	s.<span class="me1">colid</span>,
	s.<span class="me1">status</span>,  
	<span class="kw1">convert</span><span class="br0">&#40;</span><span class="kw1">varbinary</span><span class="br0">&#40;</span><span class="nu0">8000</span><span class="br0">&#41;</span>, s.<span class="kw1">text</span><span class="br0">&#41;</span> <span class="kw1">AS</span> ctext,  
	<span class="kw1">convert</span><span class="br0">&#40;</span><span class="kw1">smallint</span>, <span class="nu0">2</span> <span class="sy0">+</span> <span class="nu0">4</span> <span class="sy0">*</span> <span class="br0">&#40;</span>s.<span class="me1">status</span> <span class="sy0">&amp;</span> <span class="nu0">1</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw1">AS</span> texttype,  
	<span class="kw1">convert</span><span class="br0">&#40;</span><span class="kw1">smallint</span>, <span class="nu0">0</span><span class="br0">&#41;</span> <span class="kw1">AS</span> <span class="kw1">language</span>,  
	sysconv<span class="br0">&#40;</span><span class="kw1">bit</span>, s.<span class="me1">status</span> <span class="sy0">&amp;</span> <span class="nu0">1</span><span class="br0">&#41;</span> <span class="kw1">AS</span> encrypted,  
	sysconv<span class="br0">&#40;</span><span class="kw1">bit</span>, <span class="nu0">0</span><span class="br0">&#41;</span> <span class="kw1">AS</span> compressed,  
	s.<span class="kw1">text</span>  
<span class="kw1">FROM</span>
	sys.<span class="me1">sysschobjs</span> o
<span class="sy0">CROSS</span> APPLY
	<span class="kw1">OpenRowset</span><span class="br0">&#40;</span><span class="kw1">TABLE</span> SQLSRC, o.<span class="me1">id</span>, <span class="nu0">0</span><span class="br0">&#41;</span> s  
<span class="kw1">WHERE</span>
	o.<span class="me1">nsclass</span> <span class="sy0">=</span> <span class="nu0">0</span> <span class="sy0">AND</span>
	o.<span class="me1">pclass</span> <span class="sy0">=</span> <span class="nu0">1</span> <span class="sy0">AND</span>
	o.<span class="me1">type</span> <span class="sy0">IN</span> <span class="br0">&#40;</span><span class="st0">'C'</span>,<span class="st0">'D'</span>,<span class="st0">'P'</span>,<span class="st0">'R'</span>,<span class="st0">'V'</span>,<span class="st0">'X'</span>,<span class="st0">'FN'</span>,<span class="st0">'IF'</span>,<span class="st0">'TF'</span>,<span class="st0">'RF'</span>,<span class="st0">'IS'</span>,<span class="st0">'TR'</span><span class="br0">&#41;</span> <span class="sy0">AND</span>
	has_access<span class="br0">&#40;</span><span class="st0">'CO'</span>, o.<span class="me1">id</span><span class="br0">&#41;</span> <span class="sy0">=</span> <span class="nu0">1</span>  
&nbsp;
<span class="kw1">UNION</span> <span class="sy0">ALL</span>  
&nbsp;
<span class="kw1">SELECT</span>
	c.<span class="kw2">object_id</span> <span class="kw1">AS</span> id,  
	<span class="kw1">convert</span><span class="br0">&#40;</span><span class="kw1">smallint</span>, c.<span class="me1">column_id</span><span class="br0">&#41;</span> <span class="kw1">AS</span> number,  
	s.<span class="me1">colid</span>,
	s.<span class="me1">status</span>,  
	<span class="kw1">convert</span><span class="br0">&#40;</span><span class="kw1">varbinary</span><span class="br0">&#40;</span><span class="nu0">8000</span><span class="br0">&#41;</span>, s.<span class="kw1">text</span><span class="br0">&#41;</span> <span class="kw1">AS</span> ctext,  
	<span class="kw1">convert</span><span class="br0">&#40;</span><span class="kw1">smallint</span>, <span class="nu0">2</span> <span class="sy0">+</span> <span class="nu0">4</span> <span class="sy0">*</span> <span class="br0">&#40;</span>s.<span class="me1">status</span> <span class="sy0">&amp;</span> <span class="nu0">1</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw1">AS</span> texttype,  
	<span class="kw1">convert</span><span class="br0">&#40;</span><span class="kw1">smallint</span>, <span class="nu0">0</span><span class="br0">&#41;</span> <span class="kw1">AS</span> <span class="kw1">language</span>,  
	sysconv<span class="br0">&#40;</span><span class="kw1">bit</span>, s.<span class="me1">status</span> <span class="sy0">&amp;</span> <span class="nu0">1</span><span class="br0">&#41;</span> <span class="kw1">AS</span> encrypted,  
	sysconv<span class="br0">&#40;</span><span class="kw1">bit</span>, <span class="nu0">0</span><span class="br0">&#41;</span> <span class="kw1">AS</span> compressed,  
	s.<span class="kw1">text</span>  
<span class="kw1">FROM</span>
	sys.<span class="me1">computed_columns</span> c
<span class="sy0">CROSS</span> APPLY
	<span class="kw1">OpenRowset</span><span class="br0">&#40;</span><span class="kw1">TABLE</span> SQLSRC, c.<span class="kw2">object_id</span>, c.<span class="me1">column_id</span><span class="br0">&#41;</span> s  
&nbsp;
<span class="kw1">UNION</span> <span class="sy0">ALL</span>  
&nbsp;
<span class="kw1">SELECT</span>
	p.<span class="kw2">object_id</span> <span class="kw1">AS</span> id,  
	<span class="kw1">convert</span><span class="br0">&#40;</span><span class="kw1">smallint</span>, p.<span class="me1">procedure_number</span><span class="br0">&#41;</span> <span class="kw1">AS</span> number,  
	s.<span class="me1">colid</span>,
	s.<span class="me1">status</span>,  
	<span class="kw1">convert</span><span class="br0">&#40;</span><span class="kw1">varbinary</span><span class="br0">&#40;</span><span class="nu0">8000</span><span class="br0">&#41;</span>, s.<span class="kw1">text</span><span class="br0">&#41;</span> <span class="kw1">AS</span> ctext,  
	<span class="kw1">convert</span><span class="br0">&#40;</span><span class="kw1">smallint</span>, <span class="nu0">2</span> <span class="sy0">+</span> <span class="nu0">4</span> <span class="sy0">*</span> <span class="br0">&#40;</span>s.<span class="me1">status</span> <span class="sy0">&amp;</span> <span class="nu0">1</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw1">AS</span> texttype,  
	<span class="kw1">convert</span><span class="br0">&#40;</span><span class="kw1">smallint</span>, <span class="nu0">0</span><span class="br0">&#41;</span> <span class="kw1">AS</span> <span class="kw1">language</span>,  
	sysconv<span class="br0">&#40;</span><span class="kw1">bit</span>, s.<span class="me1">status</span> <span class="sy0">&amp;</span> <span class="nu0">1</span><span class="br0">&#41;</span> <span class="kw1">AS</span> encrypted,  
	sysconv<span class="br0">&#40;</span><span class="kw1">bit</span>, <span class="nu0">0</span><span class="br0">&#41;</span> <span class="kw1">AS</span> compressed,  
	s.<span class="kw1">text</span>  
<span class="kw1">FROM</span>
	sys.<span class="me1">numbered_procedures</span> p
<span class="sy0">CROSS</span> APPLY
	<span class="kw1">OpenRowset</span><span class="br0">&#40;</span><span class="kw1">TABLE</span> SQLSRC, p.<span class="kw2">object_id</span>, p.<span class="me1">procedure_number</span><span class="br0">&#41;</span> s  
&nbsp;
<span class="kw1">UNION</span> <span class="sy0">ALL</span>  
&nbsp;
<span class="kw1">SELECT</span>
	o.<span class="me1">id</span> <span class="kw1">AS</span> id,  
	<span class="kw1">convert</span><span class="br0">&#40;</span><span class="kw1">smallint</span>, <span class="kw1">case</span> <span class="kw1">when</span> o.<span class="me1">type</span> in <span class="br0">&#40;</span><span class="st0">'P'</span>, <span class="st0">'RF'</span><span class="br0">&#41;</span> <span class="kw1">then</span> <span class="nu0">1</span> <span class="kw1">else</span> <span class="nu0">0</span> <span class="kw1">end</span><span class="br0">&#41;</span> <span class="kw1">AS</span> number,  
	s.<span class="me1">colid</span>,
	s.<span class="me1">status</span>,  
	<span class="kw1">convert</span><span class="br0">&#40;</span><span class="kw1">varbinary</span><span class="br0">&#40;</span><span class="nu0">8000</span><span class="br0">&#41;</span>, s.<span class="kw1">text</span><span class="br0">&#41;</span> <span class="kw1">AS</span> ctext,  
	<span class="kw1">convert</span><span class="br0">&#40;</span><span class="kw1">smallint</span>, <span class="nu0">2</span><span class="br0">&#41;</span> <span class="kw1">AS</span> texttype,  
	<span class="kw1">convert</span><span class="br0">&#40;</span><span class="kw1">smallint</span>, <span class="nu0">0</span><span class="br0">&#41;</span> <span class="kw1">AS</span> <span class="kw1">language</span>,  
	sysconv<span class="br0">&#40;</span><span class="kw1">bit</span>, <span class="nu0">0</span><span class="br0">&#41;</span> <span class="kw1">AS</span> encrypted,  
	sysconv<span class="br0">&#40;</span><span class="kw1">bit</span>, <span class="nu0">0</span><span class="br0">&#41;</span> <span class="kw1">AS</span> compressed,  
	s.<span class="kw1">text</span>  
<span class="kw1">FROM</span>
	sys.<span class="me1">sysobjrdb</span> o
<span class="sy0">CROSS</span> APPLY
	<span class="kw1">OpenRowset</span><span class="br0">&#40;</span><span class="kw1">TABLE</span> SQLSRC, o.<span class="me1">id</span>, <span class="nu0">0</span><span class="br0">&#41;</span> s  
<span class="kw1">WHERE</span>
	<span class="kw2">db_id</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">=</span> <span class="nu0">1</span> <span class="sy0">AND</span> 
	o.<span class="me1">type</span> <span class="sy0">IN</span> <span class="br0">&#40;</span><span class="st0">'P'</span>,<span class="st0">'V'</span>,<span class="st0">'X'</span>,<span class="st0">'FN'</span>,<span class="st0">'IF'</span>,<span class="st0">'TF'</span><span class="br0">&#41;</span></pre></div></div></div></div></div></div></div>




<p>Bummer. It doesn’t use object_definition, but instead another internal function in the form of OpenRowset(TABLE SQLSRC, o.id, 0). I’m not one to give up easily though – I’ve previously <a href="http://improve.dk/archive/2011/07/13/exploring-the-sys-system_internals_partition_columns-ti-field.aspx" target="_blank">reverse engineered the OpenRowset(TABLE RSCPROP)</a> function.</p>

<p>Let’s take a different approach to the problem. Everything in SQL Server is stored on 8KB pages in a fixed format. As the procedures aren’t encrypted, they must be stored in clear text somewhere in the database – we just don’t know where. Let’s detach the database and crack open a hex editor (I highly recommend HxD):</p>

<div class="imgwrapper"><div><a href="http://improve.dk/wp-content/uploads/2012/08/image_10.png"><img class="alignnone size-full wp-image-2265" alt="image_10" src="http://improve.dk/wp-content/uploads/2012/08/image_10.png" width="655" height="592" /></a></div></div>

<p>Now let’s see if we can find the procedure. On purpose I made it return “SELECT ‘AABBCC’ AS Output” as that would be easy to search for:</p>

<div class="imgwrapper"><div><a href="http://improve.dk/wp-content/uploads/2012/08/image_12.png"><img class="alignnone size-full wp-image-2266" alt="image_12" src="http://improve.dk/wp-content/uploads/2012/08/image_12.png" width="361" height="230" /></a></div></div>

<p>And whadda ya know, there it is:</p>

<div class="imgwrapper"><div><a href="http://improve.dk/wp-content/uploads/2012/08/image_14.png"><img class="alignnone size-full wp-image-2267" alt="image_14" src="http://improve.dk/wp-content/uploads/2012/08/image_14.png" width="655" height="592" /></a></div></div>

<p>OK, so now we know that the source is stored in the database, just not where specifically. The data is stored at offset 0x00101AF0 in the data file. In decimal, that’s offset 01055472. As each data page is exactly 8KB, we can calculate the ID of the data page that this is stored on (using integer math):</p>

<p>01055472 / 8192 = 128</p>

<p>Aha! At this point we know that the source is stored on page 128 – how about we take a look at that page using DBCC PAGE? After reattaching the database, run:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="tsql"><pre class="de1"><span class="kw1">dbcc</span> traceon <span class="br0">&#40;</span><span class="nu0">3604</span><span class="br0">&#41;</span>
<span class="kw1">dbcc</span> page<span class="br0">&#40;</span>Test2, <span class="nu0">1</span>, <span class="nu0">128</span>, <span class="nu0">0</span><span class="br0">&#41;</span></pre></div></div></div></div></div></div></div>




<p>Note that I’m using style 0 for the DBCC PAGE command. At this point, I just want to see the header – there just might be something interesting in there:</p>

<div class="imgwrapper"><div><a href="http://improve.dk/wp-content/uploads/2012/08/image_22.png"><img class="alignnone size-full wp-image-2268" alt="image_22" src="http://improve.dk/wp-content/uploads/2012/08/image_22.png" width="548" height="142" /></a></div></div>

<p>As expected, it’s a normal data page, as indicated by the m_type field having a value of 1 (which is the internal page type ID for a data page). More interesting though, we can see that the page belongs to object ID 60! Let’s have a look at what lies behind that object ID:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="tsql"><pre class="de1"><span class="kw1">select</span> <span class="sy0">*</span> <span class="kw1">from</span> sys.<span class="me1">sysobjects</span> <span class="kw1">where</span> id <span class="sy0">=</span> <span class="nu0">60</span></pre></div></div></div></div></div></div></div>




<div class="imgwrapper"><div><a href="http://improve.dk/wp-content/uploads/2012/08/image_24.png"><img class="alignnone size-full wp-image-2269" alt="image_24" src="http://improve.dk/wp-content/uploads/2012/08/image_24.png" width="367" height="78" /></a></div></div>

<p>And all of a sudden, the hunt is on! Let’s have a look at the contents of sys.sysobjvalues. Note that before you can select from this table, you’ll have to connect using a <a href="http://msdn.microsoft.com/en-us/library/ms189595.aspx" target="_blank">dedicated administrator connection</a>, seeing as it’s an internal base table:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="tsql"><pre class="de1"><span class="kw1">select</span> <span class="sy0">*</span> <span class="kw1">from</span> sys.<span class="me1">sysobjvalues</span></pre></div></div></div></div></div></div></div>




<div class="imgwrapper"><div><a href="http://improve.dk/wp-content/uploads/2012/08/image_28.png"><img class="alignnone size-full wp-image-2270" alt="image_28" src="http://improve.dk/wp-content/uploads/2012/08/image_28.png" width="517" height="223" /></a></div></div>

<p>There’s obviously a lot of stuff in here we don’t care about, but let’s try and filter that objid column down to the object ID of our procedure – 2105058535:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="tsql"><pre class="de1"><span class="kw1">select</span> <span class="sy0">*</span> <span class="kw1">from</span> sys.<span class="me1">sysobjvalues</span> <span class="kw1">where</span> objid <span class="sy0">=</span> <span class="nu0">2105058535</span></pre></div></div></div></div></div></div></div>




<div class="imgwrapper"><div><a href="http://improve.dk/wp-content/uploads/2012/08/image_30.png"><img class="alignnone size-full wp-image-2271" alt="image_30" src="http://improve.dk/wp-content/uploads/2012/08/image_30.png" width="536" height="79" /></a></div></div>

<p>I wonder what that imageval column contains, if I remember correctly 0x2D2D would be “&#8211;“ in ASCII, which reminds me quite a lot of the beginning of the XYZ procedure. Let’s try and convert that column into human:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="tsql"><pre class="de1"><span class="kw1">select</span> <span class="kw1">convert</span><span class="br0">&#40;</span><span class="kw1">varchar</span><span class="br0">&#40;</span><span class="kw2">max</span><span class="br0">&#41;</span>, imageval<span class="br0">&#41;</span> <span class="kw1">from</span> sys.<span class="me1">sysobjvalues</span> <span class="kw1">where</span> objid <span class="sy0">=</span> <span class="nu0">2105058535</span></pre></div></div></div></div></div></div></div>




<div class="imgwrapper"><div><a href="http://improve.dk/wp-content/uploads/2012/08/image_32.png"><img class="alignnone size-full wp-image-2272" alt="image_32" src="http://improve.dk/wp-content/uploads/2012/08/image_32.png" width="593" height="67" /></a></div></div>

<p>And there you have it my dear reader; the source code for the XYZ stored procedure, as stored in the sys.sysobjvalues base table. As a final example, here’s how you’d retrieve a list of user stored procedures with their source code, without using neither object_definition nor sys.sql_modules:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="tsql"><pre class="de1"><span class="kw1">select</span>
	p.<span class="me1">name</span>,
	<span class="kw1">cast</span><span class="br0">&#40;</span>v.<span class="me1">imageval</span> <span class="kw1">as</span> <span class="kw1">varchar</span><span class="br0">&#40;</span><span class="kw2">MAX</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
<span class="kw1">from</span>
	sys.<span class="me1">procedures</span> p
<span class="kw1">inner</span> join
	sys.<span class="me1">sysobjvalues</span> v <span class="kw1">on</span> p.<span class="kw2">object_id</span> <span class="sy0">=</span> v.<span class="me1">objid</span></pre></div></div></div></div></div></div></div>




<div class="imgwrapper"><div><a href="http://improve.dk/wp-content/uploads/2012/08/image_34.png"><img class="alignnone size-full wp-image-2273" alt="image_34" src="http://improve.dk/wp-content/uploads/2012/08/image_34.png" width="500" height="69" /></a></div></div>

<p>Want to see more stuff like this? Don&#8217;t miss my <a href="http://improve.dk/archive/2012/07/18/presenting-at-sqlsaturday-162-in-cambridge.aspx" target="_blank">full-day precon at SQL Saturday #162 in Cambridge, UK</a> (Friday, September 7th), or my <a href="http://improve.dk/archive/2012/08/26/presenting-at-bleeding-edge-in-slovenia.aspx" target="_blank">Revealing the Magic session at Bleeding Edge 2012</a> in Laško, Slovenia (October 23-24th)!</p><p>The post <a href="http://improve.dk/where-does-sql-server-store-the-source-for-stored-procedures/">Where Does SQL Server Store the Source for Stored Procedures?</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p><img src="http://feeds.feedburner.com/~r/Improvedk/~4/NCge4qiOGbI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://improve.dk/where-does-sql-server-store-the-source-for-stored-procedures/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://improve.dk/where-does-sql-server-store-the-source-for-stored-procedures/</feedburner:origLink></item>
		<item>
		<title>Presenting at Bleeding Edge in Slovenia</title>
		<link>http://feedproxy.google.com/~r/Improvedk/~3/VwNH8VQ5Ht8/</link>
		<comments>http://improve.dk/presenting-at-bleeding-edge-in-slovenia/#comments</comments>
		<pubDate>Sun, 26 Aug 2012 16:04:50 +0000</pubDate>
		<dc:creator>Mark S. Rasmussen</dc:creator>
				<category><![CDATA[Conferences & Presenting]]></category>
		<category><![CDATA[Bleeding Edge]]></category>

		<guid isPermaLink="false">http://improve.dk/archive/2012/08/26/presenting-at-bleeding-edge-in-slovenia.aspx</guid>
		<description><![CDATA[<p>I’ve been to Slovenia many times, though only recently in a professional context, as I presented at NT Konferenca earlier this year. Several times, and from multiple people, I’ve heard about a local conference named Bleeding Edge, and how it was put together with nothing but level 400+ content with top quality speakers. This summer, I happened to drop by Ljubljana to visit some friends of mine, as I was in the area on vacation. At some point in the [...]</p><p>The post <a href="http://improve.dk/presenting-at-bleeding-edge-in-slovenia/">Presenting at Bleeding Edge in Slovenia</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>I’ve been to Slovenia many times, though only recently in a professional context, as I presented at <a href="http://improve.dk/archive/2012/06/01/2012-nt-konferenca-slides-demos.aspx" target="_blank">NT Konferenca earlier this year</a>. Several times, and from multiple people, I’ve heard about a local conference named Bleeding Edge, and how it was put together with nothing but level 400+ content with top quality speakers.</p>

<p>This summer, I happened to drop by Ljubljana to visit some friends of mine, as I was in the area on vacation. At some point in the evening, the talk turned to Bleeding Edge again, and before I knew it, <a href="http://weblogs.sqlteam.com/mladenp/default.aspx" target="_blank">Mladen Prajdić</a> said he’d introduce me to one of the organizers, <a href="http://milambda.blogspot.dk/" target="_blank">Matija Lah</a>.</p>

<p>Today, I’m excited to announce that I’ll be presenting my <a href="http://www.bleedingedge.si/Conference/Predavanja#rasmussen" target="_blank">Revealing the Magic</a> session at <a href="http://www.bleedingedge.si/Conference" target="_blank">Bleeding Edge 2012</a> on the 23-24th of October in Laško, Slovenia.</p>

<p>I’ve presented the session before at other venues, and this one will follow the usual fast and furious format. There are 10 hours of content compressed into just one hour. I will be showing the latest <a href="https://github.com/improvedk/OrcaMDF" target="_blank">OrcaMDF</a> bits during the session and my usual warning goes: This session is not meant to teach as much as it’s meant to inspire you. Inspire you to realize how simple SQL Server really is at its core, once you master the immediate complexity. For a full description of the session, I recommend you go to the <a href="http://www.bleedingedge.si/Conference/Predavanja#rasmussen" target="_blank">Bleeding Edge site</a>.</p><p>The post <a href="http://improve.dk/presenting-at-bleeding-edge-in-slovenia/">Presenting at Bleeding Edge in Slovenia</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p><img src="http://feeds.feedburner.com/~r/Improvedk/~4/VwNH8VQ5Ht8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://improve.dk/presenting-at-bleeding-edge-in-slovenia/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://improve.dk/presenting-at-bleeding-edge-in-slovenia/</feedburner:origLink></item>
		<item>
		<title>Presenting at SQLSaturday #162 in Cambridge</title>
		<link>http://feedproxy.google.com/~r/Improvedk/~3/8oe0tLkWsAw/</link>
		<comments>http://improve.dk/presenting-at-sqlsaturday-162-in-cambridge/#comments</comments>
		<pubDate>Wed, 18 Jul 2012 07:22:55 +0000</pubDate>
		<dc:creator>Mark S. Rasmussen</dc:creator>
				<category><![CDATA[Conferences & Presenting]]></category>
		<category><![CDATA[Cambridge]]></category>
		<category><![CDATA[SQLSaturday]]></category>

		<guid isPermaLink="false">http://improve.dk/archive/2012/07/18/presenting-at-sqlsaturday-162-in-cambridge.aspx</guid>
		<description><![CDATA[<p>The official announcement was made a couple of days ago and I’m embarassingly late to follow up myself. “Unfortunately” this is what I’m doing right now, and I must say that achieving a proper 3G connection in the middle of the Dolomites has proven rather difficult&#8230; Anyways, I’m happy and honored to say that I’ll be presenting my A Deep-Dive into the depths of the SQL Server storage engine and MDF file format  precon at SQLSaturday #162 in Cambridge. I’ll [...]</p><p>The post <a href="http://improve.dk/presenting-at-sqlsaturday-162-in-cambridge/">Presenting at SQLSaturday #162 in Cambridge</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<div class="imgwrapper"><div><a href="http://improve.dk/wp-content/uploads/2012/07/image_4.png"><img class=" wp-image-2275 alignright" alt="image_4" src="http://improve.dk/wp-content/uploads/2012/07/image_4.png" width="445" height="249" /></a></div></div>

<p>The official announcement was made a couple of days ago and I’m embarassingly late to follow up myself. “Unfortunately” this is what I’m doing right now, and I must say that achieving a proper 3G connection in the middle of the <a href="http://en.wikipedia.org/wiki/Dolomites" target="_blank">Dolomites</a> has proven rather difficult&#8230;</p>

<p>Anyways, I’m happy and honored to say that I’ll be presenting my <em>A Deep-Dive into the depths of the SQL Server storage engine and MDF file format  </em>precon at SQLSaturday #162 in Cambridge. I’ll be presenting my precon alongside SQL Server authorities like Jen Stirrup and Buck Woody, not to mention all of the regular session speakers, which have yet to be announced.</p>

<p>Allow me to present some of the feedback I got on my <em>Revealing the Magic</em> session, which is a 1-hour version of my precon, at the last SQLBits:</p>

<blockquote>It was perhaps too much detail to cram into a 1 hour session.</blockquote>

<blockquote>A bit rushed. I can say it is probably the first time I felt my knowledge was not
enough to keep up with mark&#8217;s content.</blockquote>

<blockquote>Great pace of session &#8211; very fast, no messing about &#8211; excellent &#8211; more sessions
should get on with it, like this. Loved the session and very technical &#8211; exactly
what the benefit of having this stuff delivered face-to-face.</blockquote>

<blockquote>I know he said it at the beginning. but at times it was just too fast. Maybe let the
people digest what was said.</blockquote>

<p>I love receiving constructive feedback, and this is so spot on! I definitely need to weed out a bit of content from my 1-hour session as there’s simply too much to go through in just one hour. Having a full day to present the same content is a much more fitting format, and it will allow me to go at a somewhat more normal pace, as well as leaving plenty of time for Q&amp;A during the presentation.</p>

<p>I will however still warn you that this is a level 500 precon. I will go very in depth and there will be plenty of bits and bytes to show – documented as well as undocumented.</p>

<p>Please check out the <a href="http://sqlcambs.org.uk/" target="_blank">Cambridgeshire SQL Server User Group page</a> for more information on mine, Jen Stirrup and Buck Woodys precons. Make sure to register, if not for mine then for one of the other excellent precons!</p><p>The post <a href="http://improve.dk/presenting-at-sqlsaturday-162-in-cambridge/">Presenting at SQLSaturday #162 in Cambridge</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p><img src="http://feeds.feedburner.com/~r/Improvedk/~4/8oe0tLkWsAw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://improve.dk/presenting-at-sqlsaturday-162-in-cambridge/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://improve.dk/presenting-at-sqlsaturday-162-in-cambridge/</feedburner:origLink></item>
		<item>
		<title>Video From NDC 2012: Revealing the SQL Server Magic</title>
		<link>http://feedproxy.google.com/~r/Improvedk/~3/5Iuv7t-xcQU/</link>
		<comments>http://improve.dk/video-from-ndc-2012-revealing-the-sql-server-magic/#comments</comments>
		<pubDate>Tue, 19 Jun 2012 17:21:56 +0000</pubDate>
		<dc:creator>Mark S. Rasmussen</dc:creator>
				<category><![CDATA[Conferences & Presenting]]></category>
		<category><![CDATA[Internals]]></category>
		<category><![CDATA[OrcaMDF]]></category>
		<category><![CDATA[NDC]]></category>

		<guid isPermaLink="false">http://improve.dk/archive/2012/06/18/video-from-ndc-2012-revealing-the-sql-server-magic.aspx</guid>
		<description><![CDATA[<p>I’m really lagging behind on my blogging – life is busy as the moment! Just a couple of weeks ago I presented my Revealing the Magic session at the Norwegian Developers Conference in Oslo. I was quite excited to give my SQL Server oriented session to a crowd of developers – a 500 level session, at SQL Server events that is. I just got the feedback today – 0 reds, 3 yellows and 15 greens – very happy with that, [...]</p><p>The post <a href="http://improve.dk/video-from-ndc-2012-revealing-the-sql-server-magic/">Video From NDC 2012: Revealing the SQL Server Magic</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>I’m really lagging behind on my blogging – life is busy as the moment! Just a couple of weeks ago I presented my Revealing the Magic session at the Norwegian Developers Conference in Oslo. I was quite excited to give my SQL Server oriented session to a crowd of developers – a 500 level session, at SQL Server events that is.</p>

<p>I just got the feedback today – 0 reds, 3 yellows and 15 greens – very happy with that, especially when taking the audience into account. To those of you who haven’t seen my session before, here it is:</p>

<iframe src="http://player.vimeo.com/video/43659054" height="281" width="500" allowfullscreen="allowfullscreen" frameborder="0"></iframe>

<p><a href="http://vimeo.com/43659054">Mark S. Rasmussen &#8211; Revealing the SQL Server Magic</a> from <a href="http://vimeo.com/ndcoslo">NDCOslo</a> on <a href="http://vimeo.com">Vimeo</a>.</p><p>The post <a href="http://improve.dk/video-from-ndc-2012-revealing-the-sql-server-magic/">Video From NDC 2012: Revealing the SQL Server Magic</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p><img src="http://feeds.feedburner.com/~r/Improvedk/~4/5Iuv7t-xcQU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://improve.dk/video-from-ndc-2012-revealing-the-sql-server-magic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://improve.dk/video-from-ndc-2012-revealing-the-sql-server-magic/</feedburner:origLink></item>
		<item>
		<title>2012 NT Konferenca Slides + Demos</title>
		<link>http://feedproxy.google.com/~r/Improvedk/~3/4Bh50VlZQ1I/</link>
		<comments>http://improve.dk/2012-nt-konferenca-slides-demos/#comments</comments>
		<pubDate>Fri, 01 Jun 2012 20:04:07 +0000</pubDate>
		<dc:creator>Mark S. Rasmussen</dc:creator>
				<category><![CDATA[Conferences & Presenting]]></category>
		<category><![CDATA[NTK]]></category>

		<guid isPermaLink="false">http://improve.dk/archive/2012/05/31/2012-nt-konferenca-slides-demos.aspx</guid>
		<description><![CDATA[<p>I presented two sessions at this years NT Konferenca. It was my first NTK, and what an NTK it was! I’m really hoping I’ll be back to present again – I’ve been to Slovenia many times before on non-technical visits, and now I’ve been able to confirm that they sure know how to run their conferences and cater for the attendees and speakers :) Optimizing Storage and Performance Using Page and Row Compression.rar &#8211; Slides &#38; demos Storing Character Data [...]</p><p>The post <a href="http://improve.dk/2012-nt-konferenca-slides-demos/">2012 NT Konferenca Slides + Demos</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>I presented two sessions at this years <a href="http://www.ntk.si/" target="_blank">NT Konferenca</a>. It was my first NTK, and what an NTK it was! I’m really hoping I’ll be back to present again – I’ve been to Slovenia many times before on non-technical visits, and now I’ve been able to confirm that they sure know how to run their conferences and cater for the attendees and speakers :)</p>

<p><a href="http://improve.dk/wp-content/uploads/2012/05/2012-05-24-NTK-Optimizing-Storage-and-Performance-Using-Page-and-Row-Compression-60-minutes.rar">Optimizing Storage and Performance Using Page and Row Compression.rar &#8211; Slides &amp; demos</a></p>

<p><a href="http://improve.dk/wp-content/uploads/2012/05/2012-05-24-NTK-Storing-Character-Data-Optimally-60-minutes.rar">Storing Character Data Optimally.rar &#8211; Slides &amp; demos
</a></p><p>The post <a href="http://improve.dk/2012-nt-konferenca-slides-demos/">2012 NT Konferenca Slides + Demos</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p><img src="http://feeds.feedburner.com/~r/Improvedk/~4/4Bh50VlZQ1I" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://improve.dk/2012-nt-konferenca-slides-demos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://improve.dk/2012-nt-konferenca-slides-demos/</feedburner:origLink></item>
		<item>
		<title>In the Nick of Time: Band Aid Solution for Umbraco 5.1 Performance</title>
		<link>http://feedproxy.google.com/~r/Improvedk/~3/zBIToK3GrrA/</link>
		<comments>http://improve.dk/in-the-nick-of-time-band-aid-solution-for-umbraco/#comments</comments>
		<pubDate>Mon, 14 May 2012 12:35:26 +0000</pubDate>
		<dc:creator>Mark S. Rasmussen</dc:creator>
				<category><![CDATA[Umbraco]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://improve.dk/archive/2012/05/13/in-the-nick-of-time-band-aid-solution-for-umbraco-5-1-performance.aspx</guid>
		<description><![CDATA[<p>As I write this I’m finishing the last details on a new website project I’m working on for a client. A couple of months ago I made the easy decision of going with Umbraco as the underlying CMS. I’ve had excellent experiences with Umbraco previously and the community is amazing. Umbraco was at a split road however, version 4.7 being a widely deployed and tested version, while the brand new 5.0 rewrite had just been released as a release candidate. [...]</p><p>The post <a href="http://improve.dk/in-the-nick-of-time-band-aid-solution-for-umbraco/">In the Nick of Time: Band Aid Solution for Umbraco 5.1 Performance</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>As I write this I’m finishing the last details on a new website project I’m working on for a client. A couple of months ago I made the easy decision of going with <a href="http://umbraco.org/" target="_blank">Umbraco</a> as the underlying CMS. I’ve had excellent experiences with Umbraco previously and the <a href="http://our.umbraco.org/" target="_blank">community</a> is amazing.</p>

<p>Umbraco was at a split road however, version 4.7 being a widely deployed and tested version, while the brand new 5.0 rewrite had just been released as a release candidate. It was made clear that 5.0 would not be upgradable from previous versions, so I could basically go with 4.7 and be stuck, or go with a release candidate version. To my luck, 5.0 was finally released as RTM before I had to make the decision, rendering my following decision easy – 5.0 was heralded as being production ready.</p>

<h2>Performance, oh my</h2>

<p>Fast forward a month or so, development well underway. It was clear that there were performance issues. The forums were full of <a href="http://our.umbraco.org/forum/core/umbraco-5-general-discussion/28565-Umbraco-5-Performance-issues" target="_blank">posts</a> asking how to get performance equivalent to what people were used to in 4.7. Unfortunately, there wasn’t really a solution yet. Thankfully 5.1 was released, promising better performance. After spending a couple of days fighting a <a href="http://our.umbraco.org/forum/core/umbraco-5-general-discussion/31197-Failing-to-upgrade-from-501-to-51RC" target="_blank">5.0 –&gt; 5.1 upgrade bug</a>, I finally got 5.1 running. Much to my dismay, performance was still dismal.</p>

<p>This is me requesting the front page of the website:</p>

<div class="imgwrapper"><div><a href="http://improve.dk/wp-content/uploads/2012/05/image_2.png"><img class="alignnone size-full wp-image-2284" alt="image_2" src="http://improve.dk/wp-content/uploads/2012/05/image_2.png" width="671" height="519" /></a></div></div>

<p>1780 individual requests to the database, with several interesting queries like the following:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="csharp"><pre class="de1"><span class="kw1">SELECT</span> this_<span class="sy0">.</span><span class="me1">Id</span> <span class="kw1">as</span> Id16_7_, this_<span class="sy0">.</span><span class="me1">DateCreated</span> <span class="kw1">as</span> DateCrea2_16_7_, this_<span class="sy0">.</span><span class="me1">DefaultName</span> <span class="kw1">as</span> DefaultN3_16_7_,
this_<span class="sy0">.</span><span class="me1">AttributeSchemaDefinition_id</span> <span class="kw1">as</span> Attribut4_16_7_, this_<span class="sy0">.</span><span class="me1">NodeId</span> <span class="kw1">as</span> NodeId16_7_, attribalia1_<span class="sy0">.</span><span class="me1">NodeVersionId</span>
<span class="kw1">as</span> NodeVers3_9_, attribalia1_<span class="sy0">.</span><span class="me1">Id</span> <span class="kw1">as</span> Id9_, attribalia1_<span class="sy0">.</span><span class="me1">Id</span> <span class="kw1">as</span> Id5_0_, attribalia1_<span class="sy0">.</span><span class="me1">AttributeDefinitionId</span> <span class="kw1">as</span>
Attribut2_5_0_, attribalia1_<span class="sy0">.</span><span class="me1">NodeVersionId</span> <span class="kw1">as</span> NodeVers3_5_0_, attributed5_<span class="sy0">.</span><span class="me1">AttributeId</span> <span class="kw1">as</span> Attribut4_10_,
attributed5_<span class="sy0">.</span><span class="me1">Id</span> <span class="kw1">as</span> Id10_, attributed5_<span class="sy0">.</span><span class="me1">Id</span> <span class="kw1">as</span> Id1_1_, attributed5_<span class="sy0">.</span><span class="kw1">Value</span> <span class="kw1">as</span> Value1_1_, attributed5_<span class="sy0">.</span><span class="me1">ValueKey</span>
<span class="kw1">as</span> ValueKey1_1_, attributed5_<span class="sy0">.</span><span class="me1">AttributeId</span> <span class="kw1">as</span> Attribut4_1_1_, attributed5_<span class="sy0">.</span><span class="me1">LocaleId</span> <span class="kw1">as</span> LocaleId1_1_,
attributed6_<span class="sy0">.</span><span class="me1">AttributeId</span> <span class="kw1">as</span> Attribut4_11_, attributed6_<span class="sy0">.</span><span class="me1">Id</span> <span class="kw1">as</span> Id11_, attributed6_<span class="sy0">.</span><span class="me1">Id</span> <span class="kw1">as</span> Id0_2_, attributed6_<span class="sy0">.</span><span class="kw1">Value</span>
<span class="kw1">as</span> Value0_2_, attributed6_<span class="sy0">.</span><span class="me1">ValueKey</span> <span class="kw1">as</span> ValueKey0_2_, attributed6_<span class="sy0">.</span><span class="me1">AttributeId</span> <span class="kw1">as</span> Attribut4_0_2_, attributed6_<span class="sy0">.</span><span class="me1">LocaleId</span>
<span class="kw1">as</span> LocaleId0_2_, attributei4_<span class="sy0">.</span><span class="me1">AttributeId</span> <span class="kw1">as</span> Attribut4_12_, attributei4_<span class="sy0">.</span><span class="me1">Id</span> <span class="kw1">as</span> Id12_, attributei4_<span class="sy0">.</span><span class="me1">Id</span> <span class="kw1">as</span>
Id3_3_, attributei4_<span class="sy0">.</span><span class="kw1">Value</span> <span class="kw1">as</span> Value3_3_, attributei4_<span class="sy0">.</span><span class="me1">ValueKey</span> <span class="kw1">as</span> ValueKey3_3_, attributei4_<span class="sy0">.</span><span class="me1">AttributeId</span>
<span class="kw1">as</span> Attribut4_3_3_, attributei4_<span class="sy0">.</span><span class="me1">LocaleId</span> <span class="kw1">as</span> LocaleId3_3_, attributel3_<span class="sy0">.</span><span class="me1">AttributeId</span> <span class="kw1">as</span> Attribut4_13_,
attributel3_<span class="sy0">.</span><span class="me1">Id</span> <span class="kw1">as</span> Id13_, attributel3_<span class="sy0">.</span><span class="me1">Id</span> <span class="kw1">as</span> Id4_4_, attributel3_<span class="sy0">.</span><span class="kw1">Value</span> <span class="kw1">as</span> Value4_4_, attributel3_<span class="sy0">.</span><span class="me1">ValueKey</span> <span class="kw1">as</span>
ValueKey4_4_, attributel3_<span class="sy0">.</span><span class="me1">AttributeId</span> <span class="kw1">as</span> Attribut4_4_4_, attributel3_<span class="sy0">.</span><span class="me1">LocaleId</span> <span class="kw1">as</span> LocaleId4_4_,
attributes2_<span class="sy0">.</span><span class="me1">AttributeId</span> <span class="kw1">as</span> Attribut4_14_, attributes2_<span class="sy0">.</span><span class="me1">Id</span> <span class="kw1">as</span> Id14_, attributes2_<span class="sy0">.</span><span class="me1">Id</span> <span class="kw1">as</span> Id6_5_, attributes2_<span class="sy0">.</span><span class="kw1">Value</span>
<span class="kw1">as</span> Value6_5_, attributes2_<span class="sy0">.</span><span class="me1">ValueKey</span> <span class="kw1">as</span> ValueKey6_5_, attributes2_<span class="sy0">.</span><span class="me1">AttributeId</span> <span class="kw1">as</span> Attribut4_6_5_,
attributes2_<span class="sy0">.</span><span class="me1">LocaleId</span> <span class="kw1">as</span> LocaleId6_5_, node14_<span class="sy0">.</span><span class="me1">Id</span> <span class="kw1">as</span> Id9_6_, node14_<span class="sy0">.</span><span class="me1">DateCreated</span> <span class="kw1">as</span> DateCrea2_9_6_,
node14_<span class="sy0">.</span><span class="me1">IsDisabled</span> <span class="kw1">as</span> IsDisabled9_6_, node14_1_<span class="sy0">.</span><span class="me1">Alias</span> <span class="kw1">as</span> Alias10_6_, node14_1_<span class="sy0">.</span><span class="me1">Description</span> <span class="kw1">as</span> Descript3_10_6_,
node14_1_<span class="sy0">.</span><span class="me1">Name</span> <span class="kw1">as</span> Name10_6_, node14_1_<span class="sy0">.</span><span class="me1">Ordinal</span> <span class="kw1">as</span> Ordinal10_6_, node14_1_<span class="sy0">.</span><span class="me1">AttributeSchemaDefinitionId</span> <span class="kw1">as</span>
Attribut6_10_6_, node14_2_<span class="sy0">.</span><span class="me1">Alias</span> <span class="kw1">as</span> Alias11_6_, node14_2_<span class="sy0">.</span><span class="me1">Description</span> <span class="kw1">as</span> Descript3_11_6_, node14_2_<span class="sy0">.</span><span class="me1">Name</span> <span class="kw1">as</span>
Name11_6_, node14_2_<span class="sy0">.</span><span class="me1">SchemaType</span> <span class="kw1">as</span> SchemaType11_6_, node14_2_<span class="sy0">.</span><span class="me1">XmlConfiguration</span> <span class="kw1">as</span> XmlConfi6_11_6_, <span class="kw1">case</span> when
node14_1_<span class="sy0">.</span><span class="me1">NodeId</span> <span class="kw3">is</span> not <span class="kw1">null</span> then <span class="nu0">1</span> when node14_2_<span class="sy0">.</span><span class="me1">NodeId</span> <span class="kw3">is</span> not <span class="kw1">null</span> then <span class="nu0">2</span> when node14_<span class="sy0">.</span><span class="me1">Id</span> <span class="kw3">is</span> not <span class="kw1">null</span> then
<span class="nu0">0</span> end <span class="kw1">as</span> clazz_6_ <span class="kw1">FROM</span> dbo<span class="sy0">.</span><span class="me1">NodeVersion</span> this_ left outer <span class="kw1">join</span> dbo<span class="sy0">.</span><span class="me1">Attribute</span> attribalia1_ on this_<span class="sy0">.</span><span class="me1">Id</span><span class="sy0">=</span>attribalia1_<span class="sy0">.</span><span class="me1">NodeVersionId</span>
left outer <span class="kw1">join</span> dbo<span class="sy0">.</span><span class="me1">AttributeDecimalValue</span> attributed5_ on attribalia1_<span class="sy0">.</span><span class="me1">Id</span><span class="sy0">=</span>attributed5_<span class="sy0">.</span><span class="me1">AttributeId</span> left outer <span class="kw1">join</span>
dbo<span class="sy0">.</span><span class="me1">AttributeDateValue</span> attributed6_ on attribalia1_<span class="sy0">.</span><span class="me1">Id</span><span class="sy0">=</span>attributed6_<span class="sy0">.</span><span class="me1">AttributeId</span> left outer <span class="kw1">join</span> dbo<span class="sy0">.</span><span class="me1">AttributeIntegerValue</span>
attributei4_ on attribalia1_<span class="sy0">.</span><span class="me1">Id</span><span class="sy0">=</span>attributei4_<span class="sy0">.</span><span class="me1">AttributeId</span> left outer <span class="kw1">join</span> dbo<span class="sy0">.</span><span class="me1">AttributeLongStringValue</span> attributel3_
on attribalia1_<span class="sy0">.</span><span class="me1">Id</span><span class="sy0">=</span>attributel3_<span class="sy0">.</span><span class="me1">AttributeId</span> left outer <span class="kw1">join</span> dbo<span class="sy0">.</span><span class="me1">AttributeStringValue</span> attributes2_ on
attribalia1_<span class="sy0">.</span><span class="me1">Id</span><span class="sy0">=</span>attributes2_<span class="sy0">.</span><span class="me1">AttributeId</span> inner <span class="kw1">join</span> dbo<span class="sy0">.</span><span class="me1">Node</span> node14_ on this_<span class="sy0">.</span><span class="me1">NodeId</span><span class="sy0">=</span>node14_<span class="sy0">.</span><span class="me1">Id</span> left outer
<span class="kw1">join</span> dbo<span class="sy0">.</span><span class="br0">&#91;</span>AttributeDefinitionGroup<span class="br0">&#93;</span> node14_1_ on node14_<span class="sy0">.</span><span class="me1">Id</span><span class="sy0">=</span>node14_1_<span class="sy0">.</span><span class="me1">NodeId</span> left outer <span class="kw1">join</span> dbo<span class="sy0">.</span><span class="br0">&#91;</span>AttributeSchemaDefinition<span class="br0">&#93;</span>
node14_2_ on node14_<span class="sy0">.</span><span class="me1">Id</span><span class="sy0">=</span>node14_2_<span class="sy0">.</span><span class="me1">NodeId</span> <span class="kw1">WHERE</span> this_<span class="sy0">.</span><span class="me1">Id</span> <span class="kw1">in</span> <span class="br0">&#40;</span>@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8,
@p9, @p10, @p11, @p12, @p13, @p14, @p15, @p16, @p17, @p18, @p19, @p20, @p21, @p22, @p23, @p24, @p25, @p26, @p27,
@p28, @p29, @p30, @p31, @p32, @p33, @p34, @p35, @p36, @p37, @p38, @p39, @p40, @p41, @p42, @p43, @p44, @p45, @p46,
@p47, @p48, @p49, @p50, @p51, @p52, @p53, @p54, @p55, @p56, @p57, @p58, @p59, @p60, @p61, @p62, @p63, @p64, @p65,
@p66, @p67, @p68, @p69, @p70, @p71, @p72, @p73, @p74, @p75, @p76, @p77, @p78, @p79, @p80, @p81, @p82, @p83, @p84,
@p85, @p86, @p87, @p88, @p89, @p90, @p91, @p92, @p93, @p94, @p95, @p96, @p97, @p98, @p99, @p100, @p101, @p102, @p103,
@p104, @p105, @p106, @p107, @p108, @p109, @p110, @p111, @p112, @p113, @p114, @p115, @p116, @p117, @p118, @p119, @p120,
@p121, @p122, @p123, @p124, @p125, @p126, @p127, @p128, @p129, @p130, @p131, @p132, @p133, @p134, @p135, @p136, @p137,
<span class="sy0">...</span> <span class="sy0">&lt;</span>snip<span class="sy0">:</span> some <span class="nu0">700</span> other parameters<span class="sy0">&gt;</span> <span class="sy0">...</span>
@p882, @p883, @p884, @p885, @p886, @p887, @p888, @p889, @p890, @p891, @p892, @p893, @p894, @p895, @p896, @p897, @p898,
@p899, @p900, @p901, @p902, @p903, @p904, @p905, @p906, @p907, @p908, @p909, @p910, @p911, @p912, @p913, @p914, @p915,
@p916, @p917, @p918, @p919, @p920, @p921, @p922, @p923, @p924, @p925, @p926, @p927, @p928, @p929, @p930, @p931, @p932,
@p933, @p934, @p935, @p936, @p937, @p938, @p939, @p940, @p941, @p942, @p943, @p944, @p945, @p946, @p947, @p948, @p949,
@p950, @p951, @p952, @p953, @p954, @p955, @p956<span class="br0">&#41;</span> and this_<span class="sy0">.</span><span class="me1">Id</span> <span class="kw1">in</span> <span class="br0">&#40;</span><span class="kw1">SELECT</span> this_0_<span class="sy0">.</span><span class="me1">Id</span> <span class="kw1">as</span> y0_ <span class="kw1">FROM</span> dbo<span class="sy0">.</span><span class="me1">NodeVersion</span> this_0_ <span class="kw1">WHERE</span> this_0_<span class="sy0">.</span><span class="me1">NodeId</span> <span class="sy0">=</span> @p957<span class="br0">&#41;</span></pre></div></div></div></div></div></div></div>




<p>It’s clearly obvious we’re dealing with a serious N+1 problem, made worse by a lack of set based operations as evidenced by the above query. At the same time this query is a ticking time bomb – as soon as it hits the 2100 parameter limit, problems will arise unless they’re handled. The culprit seems to be the fact that the database is queried through a LINQ provider on top of Umbracos own Hive layer, on top of NHibernate. The core team themselves have voiced that NHibernate might be exacerbating the problem as they haven’t tamed the beast completely. I <a href="http://our.umbraco.org/forum/core/umbraco-5-general-discussion/28565-Umbraco-5-Performance-issues?p=14" target="_blank">voiced my own concerns and suggestions</a> on the architecture in the main performance thread. Currently the core team seems to be working on a band aid solution; adding a Lucene based cache to the site to improve performance. In my opinion the only way to really solve the issue is to fix the underlying problem – the N+1 one.</p>

<p>Back in January the Umbraco team posted the following: <a href="http://umbraco.com/follow-us/blog-archive/2012/1/4/umbraco-5-on-performance-and-the-perils-of-premature-optimisation.aspx" target="_blank">Umbraco 5: On performance and the perils of premature optimization</a>. While I completely agree with the sentiment, avoiding N+1 issues is not premature optimization, that’s a requirement before releasing an RTM product.</p>

<p>The Umbraco team does deserve big kudos on owning up to the problem. They’re painfully aware of the issues people are dealing with, being unable to deploy due to crippling performance. I’m sure they’ll be improving on performance, I just hope it happens sooner than later. I did talk to Niels Hartvig and offered my help (regarding the database layer), should they want it. I’ve also had Alex Norcliffe look at my logs over email – a big thanks goes to the team, helping out even though they’re in a pinch themselves.</p>

<h2>Band aid solutions while waiting for 5.2</h2>

<p>As I had to get the website up and running for a trade show, I had no choice but to spin up a High-CPU Extra Large Instance on Amazon EC2. While this costs a minor fortune (compared to what hosting the site should’ve required), it gave me a temporary solution for the trade show. Startup times were still terrible but at least requesting pages went reasonably fast, even though some pages did hang for 5+ seconds, depending on the content shown.</p>

<p>Once the trade show was over, I downgraded the EC2 instance to an m1.large instance. It’s still expensive, but it’s a tad cheaper for development. However, there’s a bigger problem looming on the horizon – the site has to go live in a week or two.</p>

<p>The Umbraco team have said they expect a 5.2 performance release sometime during June, and 5.x being on par with 4.7 by the end of 2012. Unfortunately I don’t have the luxury of waiting for that.</p>

<p>What I’ve now done, to prepare for the launch, was to increase the output cache timeout to 24 hours by modifying web.config like so:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="xml"><pre class="de1"><span class="sc3"><span class="re1">&lt;caching<span class="re2">&gt;</span></span></span>
  <span class="sc3"><span class="re1">&lt;outputCacheSettings<span class="re2">&gt;</span></span></span>
    <span class="sc3"><span class="re1">&lt;outputCacheProfiles<span class="re2">&gt;</span></span></span>
      <span class="sc3"><span class="re1">&lt;add</span> <span class="re0">name</span>=<span class="st0">&quot;umbraco-default&quot;</span> <span class="re0">duration</span>=<span class="st0">&quot;86400&quot;</span> <span class="re0">varyByParam</span>=<span class="st0">&quot;*&quot;</span> <span class="re0">location</span>=<span class="st0">&quot;ServerAndClient&quot;</span><span class="re2">/&gt;</span></span>
    <span class="sc3"><span class="re1">&lt;/outputCacheProfiles<span class="re2">&gt;</span></span></span>
  <span class="sc3"><span class="re1">&lt;/outputCacheSettings<span class="re2">&gt;</span></span></span>
<span class="sc3"><span class="re1">&lt;/caching<span class="re2">&gt;</span></span></span></pre></div></div></div></div></div></div></div>




<p>This essentially turns the website into a statically cached copy. Doing this results in each page being cached for 24 hours after it’s been visited last. While this is great, it still means those first visitors (for each page on the website) will be suffering from long waits. To fix that, I turn to <a href="http://home.snafu.de/tilman/xenulink.html" target="_blank">Xenu’s Link Sleuth</a>. Given the hostname, Xenu will crawl each page on the website, checking for broken links. As a side effect, every page on the site will be visited and thereby cached. By default, Xenu will use 30 concurrent threads to crawl the site. On my EC2 instance, that resulted in loads of timeouts as the instance simply couldn’t handle it:</p>

<div class="imgwrapper"><div><a href="http://improve.dk/wp-content/uploads/2012/05/image_10.png"><img class="alignnone size-full wp-image-2285" alt="image_10" src="http://improve.dk/wp-content/uploads/2012/05/image_10.png" width="783" height="554" /></a></div></div>

<p>Pressing Ctrl+R forces Xenu to retry all the failed links, eventually resulting in all the links being visited successfully:</p>

<div class="imgwrapper"><div><a href="http://improve.dk/wp-content/uploads/2012/05/image_8.png"><img class="alignnone size-full wp-image-2286" alt="image_8" src="http://improve.dk/wp-content/uploads/2012/05/image_8.png" width="768" height="536" /></a></div></div>

<p>(Sorry for distorting the images – the site isn’t supposed to go completely public yet). For Xenu to find all the links on the site, you’ll have to make sure you’re using &lt;a href /&gt; tags. I had to replace a couple of:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="xml"><pre class="de1"><span class="sc3"><span class="re1">&lt;div</span> <span class="re0">onclick</span>=<span class="st0">&quot;window.open('http://xyz.com')&quot;</span><span class="re2">&gt;</span></span></pre></div></div></div></div></div></div></div>




<p>With corresponding &lt;a href /&gt; implementations, otherwise Xenu blissfully ignored them.</p>

<p>Obviously fixing the performance issue like this comes with a severe cost – memory usage on the server as well as being unable to update the site from the back office. For now I can live with that as the main priority is getting the site live. When I update I’ll have to manually cycle the app pool as well as rerunning Xenu. Currently the site takes up about 500 megs of memory fully cached, so I’ve got some room to spare.</p>

<p>Thankfully there are no protected parts of the site so user-specific caching is not an issue – <a href="http://en.wiktionary.org/wiki/YMMV" target="_blank">YMMV</a>.</p><p>The post <a href="http://improve.dk/in-the-nick-of-time-band-aid-solution-for-umbraco/">In the Nick of Time: Band Aid Solution for Umbraco 5.1 Performance</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p><img src="http://feeds.feedburner.com/~r/Improvedk/~4/zBIToK3GrrA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://improve.dk/in-the-nick-of-time-band-aid-solution-for-umbraco/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://improve.dk/in-the-nick-of-time-band-aid-solution-for-umbraco/</feedburner:origLink></item>
		<item>
		<title>2012 Community &amp; Demo Day Materials</title>
		<link>http://feedproxy.google.com/~r/Improvedk/~3/aLZSMTuQFEM/</link>
		<comments>http://improve.dk/2012-community-amp-demo-day-materials/#comments</comments>
		<pubDate>Fri, 11 May 2012 12:33:00 +0000</pubDate>
		<dc:creator>Mark S. Rasmussen</dc:creator>
				<category><![CDATA[Conferences & Presenting]]></category>
		<category><![CDATA[Community Day]]></category>

		<guid isPermaLink="false">http://improve.dk/archive/2012/05/11/2012-community-demo-day-materials.aspx</guid>
		<description><![CDATA[<p>Yesterday I presented at Community Day. As promised, you can download my slide deck here: CommunityDay-Using-Amazon-S3-CloudFront-for-Scalable-and-Secure-Distribution.rar &#8211; Slides I also did a demo of OrcaMDF for the following Demo Day happening. You can find more on OrcaMDF here: Git repository Blog entries</p><p>The post <a href="http://improve.dk/2012-community-amp-demo-day-materials/">2012 Community &#038; Demo Day Materials</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Yesterday I presented at <a href="http://communityday2012.c1preprod01.composite.net/Community-Day" target="_blank">Community Day</a>. As promised, you can download my slide deck here:</p>

<p><a href="http://improve.dk/wp-content/uploads/2012/05/2012-05-10-CommunityDay-Using-Amazon-S3-CloudFront-for-Scalable-and-Secure-Distribution.rar">CommunityDay-Using-Amazon-S3-CloudFront-for-Scalable-and-Secure-Distribution.rar &#8211; Slides</a><a href="/Images/Files/2012-05-10-CommunityDay-Using-Amazon-S3-CloudFront-for-Scalable-and-Secure-Distribution.rar" target="_blank">
</a></p>

<p>I also did a demo of OrcaMDF for the following Demo Day happening. You can find more on OrcaMDF here:</p>

<p><a href="https://github.com/improvedk/OrcaMDF" target="_blank">Git repository</a><br />
<a href="http://improve.dk/category/79.aspx" target="_blank">Blog entries</a></p><p>The post <a href="http://improve.dk/2012-community-amp-demo-day-materials/">2012 Community &#038; Demo Day Materials</a> appeared first on <a href="http://improve.dk">Mark S. Rasmussen - Blog</a>.</p><img src="http://feeds.feedburner.com/~r/Improvedk/~4/aLZSMTuQFEM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://improve.dk/2012-community-amp-demo-day-materials/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://improve.dk/2012-community-amp-demo-day-materials/</feedburner:origLink></item>
	</channel>
</rss>
