<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="https://blog.aabech.no/rss/xslt"?>
<rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Lars-Erik's blog</title>
    <link>https://blog.aabech.no/</link>
    <description>Ramblings about Umbraco, .net and JavaScript development. With a sprinkle of other stuff.</description>
    <generator>Articulate, blogging built on Umbraco</generator>
    <item>
      <guid isPermaLink="false">1107</guid>
      <link>https://blog.aabech.no/archive/how-to-kill-umbraco-with-urlrewritenet/</link>
      <title>How to kill Umbraco with UrlRewrite.Net</title>
      <description>&lt;h3&gt;The case&lt;/h3&gt;
&lt;p&gt;Recently we were contacted by another Norwegian company who inherited a custom Umbraco solution. The original developer is off chasing green fields, so they came to us when the site restarted twice an hour. Something about CPU spikes... It had been upgraded to 7.5.4 and everything, so we could just start off clicking all the shiny new buttons in the health dashboard. Most &amp;quot;known&amp;quot; Azure fixes were already in place, and the rest was applied for good measure. Yet the problem persisted, so we knew we were facing a more dire problem.&lt;/p&gt;
&lt;h3&gt;The proof&lt;/h3&gt;
&lt;p&gt;Jumping onto the Azure graphs and logs, we could see a pattern of massive memory usage as well as the CPU. Here's a nice bouncy graph of the state of the S3(!) server.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://blog.aabech.no/media/1022/spikes.png" alt="Spikes in memory and CPU" /&gt;&lt;/p&gt;
&lt;p&gt;Going through the Umbraco logs, we found several restarts due to out of memory exceptions from seemingly unrelated calls. All of them seemed to correlate with the restarts and massive resource spikes. Some of them came from cached views, so we did an attemt to remove caching from the most varied pages. After all, Umbraco already has the content in memory, so how much CPU goes into rendering it? It was quickly dismissed though, the problem persisted.  
&lt;/p&gt;
&lt;p&gt;We'd also spotted another suspect in the logs, namely UrlRewrite.Net. But at this point we were also ready to throw some profiling tools on the site. Somehow, none of JetBrains' tools worked. For some reason the views could not be rendered. I suspect it has something to do with the caching, profiling views or how the tools work. But I digress. We were able to run VS' profiler on it, and guess who turned up as our main suspect again?&lt;/p&gt;
&lt;p&gt;&lt;img src="https://blog.aabech.no/media/1020/cpuprofile.png" alt="Profiling UrlRewrite.Net with Umbraco" /&gt;&lt;/p&gt;
&lt;p&gt;I think the table speaks for it self. The upper two calls are in idling background threads.
They don't affect CPU at all. Having the system access the database for one second is within limits for several requests. But the rest of the CPU time was actually spent solely in UrlRewrite.Net and parsing of regular expressions. I could quickly verify we weren't the first seeing this after searching &lt;a href="http://our.umbraco.org"&gt;our.umbraco.org&lt;/a&gt; too.&lt;/p&gt;
&lt;h3&gt;The fix&lt;/h3&gt;
&lt;p&gt;Now don't go panic over your own UrlRewrites just yet. This site had more than 2.500 rewritten URLs buried in urlrewrite.config. After being made aware, our contractor cut it down to 150 more generalized regular expressions, and voila, there's been a steady 3% CPU usage since then.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://blog.aabech.no/media/1021/flatout.png" alt="CPU flattening out after cutting urlrewrites to 150" /&gt;&lt;/p&gt;
&lt;p&gt;I've been sceptical to people bad-mouthing UrlRewrite.Net in the past. We've never had many problems with it in our sites. But then again, we've never gone past 50 rewrite rules. (I think.) It's a great tool for its purpose, but as we've now witnessed, it can also do great harm when used wrong. It might be time for us to throw out the old IIS 6 servers and start using Microsoft's &lt;a href="https://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module"&gt;Url Rewrite Module&lt;/a&gt; instead.&lt;/p&gt;
&lt;h3&gt;Alternatives&lt;/h3&gt;
&lt;p&gt;But what should we do, then, when faced with situations where we have thousands of URLs to keep 301'ing? I'd guess you've got some kind of pattern there so you can simplify with catching regular expressions like we did here. Otherwise, you're probably better off &lt;a href="https://msdn.microsoft.com/en-us/library/ms227673.aspx"&gt;writing your own small HttpModule&lt;/a&gt; with some logic, rather than relying on generic rewriters and regex.&lt;/p&gt;
</description>
      <pubDate>Mon, 09 Jan 2017 22:03:53 Z</pubDate>
      <a10:updated>2017-01-09T22:03:53Z</a10:updated>
    </item>
  </channel>
</rss>