<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>t h e D a v i d A i k e n &#187; SQL Azure</title>
	<atom:link href="http://www.davidaiken.com/category/sql-azure/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.davidaiken.com</link>
	<description>Not Statistically Significant</description>
	<lastBuildDate>Wed, 16 Nov 2011 04:04:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Implementing Windows Azure Retry Logic</title>
		<link>http://www.davidaiken.com/2011/10/10/implementing-windows-azure-retry-logic/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.davidaiken.com/2011/10/10/implementing-windows-azure-retry-logic/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 20:02:44 +0000</pubDate>
		<dc:creator>theDavidAiken</dc:creator>
				<category><![CDATA[SQL Azure]]></category>
		<category><![CDATA[Windows Azure]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Retry Logic]]></category>

		<guid isPermaLink="false">http://www.davidaiken.com/?p=220</guid>
		<description><![CDATA[Windows Azure will automatically repair itself. Can your service? In this post I’m going to show you a simple way to make your service a little more resilient by adding retry logic.
Transient Datacenter conditions
When you have to deal with external services of any type there are times when the  [...]]]></description>
			<content:encoded><![CDATA[<p>Windows Azure will automatically repair itself. Can your service? In this post I’m going to show you a simple way to make your service a little more resilient by adding retry logic.</p>
<h1>Transient Datacenter conditions</h1>
<p>When you have to deal with external services of any type there are times when the service might not respond. This could be due to any number of reasons from network connectivity &amp; service throttling, to hardware failure. Windows Azure is designed to withstand these failures, not by avoiding them, but by taking corrective action when they do occur. Windows Azure auto heals itself. These conditions are sometimes referred to as transient conditions because they are not typically long lasting.</p>
<p>As an example, SQL Azure can give you <a href="http://msdn.microsoft.com/en-us/library/4cff491e-9359-4454-bd7c-fb72c4c452ca#bkmk_throt_errors" target="_blank">connection errors</a>, and <a href="http://msdn.microsoft.com/en-us/library/4cff491e-9359-4454-bd7c-fb72c4c452ca#bkmk_throt_errors" target="_blank">throttling errors</a>, Windows Azure Storage can give you timeout and throttling errors and Service Bus has <a href="http://msdn.microsoft.com/en-us/library/microsoft.servicebus.messaging.serverbusyexception.aspx" target="_blank">ServerBusy</a> and <a href="http://msdn.microsoft.com/en-us/library/microsoft.servicebus.messaging.messagingcommunicationexception.aspx" target="_blank">MessagingCommunication</a> Exceptions.</p>
<p>Any other external dependency will also likely have similar conditions. Without defensive coding for these transient conditions, your app will suffer unnecessary outages. Fortunately the problem can be easily resolved.</p>
<h1>Retry Logic</h1>
<p>Handling these conditions is usually as easy as repeating the operation after a short delay. </p>
<p>The Windows Azure Storage Client Library that ships with the SDK already has <a href="http://blogs.msdn.com/b/windowsazurestorage/archive/2011/02/03/overview-of-retry-policies-in-the-windows-azure-storage-client-library.aspx" target="_blank">retry behavior</a> that you need to switch on. You can set this on any storage client by setting the <strong>RetryPolicy</strong> Property.</p>
<p>SQL Azure doesn’t provide a default retry mechanism out of the box, since it uses the SQL Server client libraries. Service Bus also doesn’t provide a retry mechanism.</p>
<h2>Transient Fault Handling Framework</h2>
<p>To provide an easy way to handle this, the Windows Azure Customer Advisory Team have developed a Transient Fault Handling Framework &#8211; <a title="http://windowsazurecat.com/2011/02/transient-fault-handling-framework/" href="http://windowsazurecat.com/2011/02/transient-fault-handling-framework/">http://windowsazurecat.com/2011/02/transient-fault-handling-framework/</a>. The framework provides a number of ways to handle specific SQL Azure, Storage, Service Bus and Cache conditions. </p>
<p>The most interesting aspect to me however is the <strong>ExecuteAction</strong> and <strong>ExecuteAction&lt;T&gt;</strong> methods. These methods allow you to basically wrap any user code in a retry block. Example:</p>
<pre style="width: 105.39%; height: 53px" class="csharpcode">var policy = <span class="kwrd">new</span> RetryPolicy&lt;SqlAzureTransientErrorDetectionStrategy&gt;(MaxRetries,
                    TimeSpan.FromMilliseconds(DelayMs));
policy.ExecuteAction(() =&gt; <span class="kwrd">object</span>.DoSomething());</pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
</p>
<h2>Retry Pattern</h2>
<p>What is great about these methods are they enable you to use the <a href="http://en.wikipedia.org/wiki/Decorator_pattern" target="_blank">decorator pattern</a> to add retry logic to your service. This of course assumes you built your service with extensibility in mind. </p>
<p>In my example I have a <strong>UriRepository </strong>which is defined by the <strong>IUriRepository</strong> interface. I have a <strong>SQLAzureUriRepository</strong> that implements the interface. This class however contains no retry logic. Instead I implemented a <strong>RetryUriRepository</strong> that also implements <strong>IUriRepository</strong>. <strong>RetryUriRepository</strong> allows you to specify via constructor injection, which <strong>UriRepositiory</strong> to retry.</p>
<p>Here is a snippet of the <strong>RetryUriRepository</strong>:</p>
<pre style="width: 106.32%; height: 345px" class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> RetryUriRepository : IUriRepository
{
    <span class="kwrd">private</span> <span class="kwrd">readonly</span> IUriRepository _uriRepository;
    <span class="kwrd">private</span> <span class="kwrd">const</span> <span class="kwrd">int</span> MaxRetries = 10;
    <span class="kwrd">private</span> <span class="kwrd">const</span> <span class="kwrd">double</span> DelayMs = 2000;

    <span class="kwrd">public</span> RetryUriRepository(IUriRepository uriRepository)
    {   _uriRepository = uriRepository;    }

    <span class="kwrd">public</span> <span class="kwrd">void</span> InsertUri(<span class="kwrd">string</span> shortUri, <span class="kwrd">string</span> longUri, <span class="kwrd">string</span> ipAddress)
    {
        var policy = GetRetryPolicy();
        policy.ExecuteAction(() =&gt; _uriRepository.InsertUri(shortUri, longUri, ipAddress));
    }
    <span class="kwrd">private</span> <span class="kwrd">static</span> RetryPolicy GetRetryPolicy()
    {
        <span class="kwrd">return</span> <span class="kwrd">new</span> RetryPolicy&lt;SqlAzureTransientErrorDetectionStrategy&gt;(MaxRetries,&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; TimeSpan.FromMilliseconds(DelayMs));
    }
}</pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>Using the supplied framework might be overkill, but it should give you an idea on how to implement retry logic in your service.</p>
<h1>Too Much Retry</h1>
<p>One thing that becomes interesting is when the number of retries increases. This typically indicates either a longer error condition, or you are overloading the services you are consuming. The most likely, and only one we can do anything about, is the later. The more throttling that goes on, the more retires. The more retires the less throughput. The less throughput the slower the response time. Poor response time = disgruntled users (and executives).</p>
<p>Don’t be tempted to turn off the retry logic when this happens. This will just make the problem much worse. About the only solution when dealing with overloading a service is to either scale that service out, or attempt to delay the processing using a queue/worker pattern.</p>
<h1>Conclusion</h1>
<p>Implementing retry logic is critical if you want your service to keep running. Monitoring the frequency of these retries can be a good indicator you are starting to experience scale issues. Don’t turn your retry logic off to handle scale issues.</p>
<p>THIS POSTING IS PROVIDED “AS IS” WITH NO WARRANTIES, AND CONFERS NO RIGHTS, EXCEPT ON THE THIRD SUNDAY WITH A FULL MOON</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidaiken.com/2011/10/10/implementing-windows-azure-retry-logic/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Manage Your SQL Azure databases with Project Houston</title>
		<link>http://www.davidaiken.com/2010/07/21/manage-your-sql-azure-databases-with-project-houston/#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://www.davidaiken.com/2010/07/21/manage-your-sql-azure-databases-with-project-houston/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 22:45:21 +0000</pubDate>
		<dc:creator>theDavidAiken</dc:creator>
				<category><![CDATA[SQL Azure]]></category>
		<category><![CDATA[Project Houston]]></category>

		<guid isPermaLink="false">http://www.davidaiken.com/2010/07/21/manage-your-sql-azure-databases-with-project-houston/</guid>
		<description><![CDATA[If you are working with SQL Azure at all and want to do some database management tasks, it’s always been a bit of a pain to have to download and install some SQL management tools.
Project Houston is the answer. Here is what the product team have to say about it:
Microsoft® Project Code-Named  [...]]]></description>
			<content:encoded><![CDATA[<p>If you are working with SQL Azure at all and want to do some database management tasks, it’s always been a bit of a pain to have to download and install some SQL management tools.</p>
<p>Project Houston is the answer. Here is what the product team have to say about it:</p>
<blockquote><p>Microsoft® Project Code-Named “Houston” is a lightweight and easy to use database management tool for SQL Azure databases. It is designed specifically for Web developers and other technology professionals seeking a straightforward solution to quickly develop, deploy, and manage their data-driven applications in the cloud. Project “Houston” provides a web-based database management tool for basic database management tasks like authoring and executing queries, designing and editing a database schema, and editing table data. <b>It is now available on <a href="https://www.sqlazurelabs.com/">SQL Azure Labs</a>.</b></p>
</blockquote>
<p>If you follow the link, then click on the CTP link, you will be presented with the following login screen.</p>
<p><a href="http://www.davidaiken.com/wp-content/uploads/2010/07/image7.png#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.davidaiken.com/wp-content/uploads/2010/07/image_thumb7.png" width="437" height="333" /></a> </p>
<p>Grab the details from the <a href="http://sql.azure.com">http://sql.azure.com</a> portal and feed them in and bask in the awesomeness that is Houston. </p>
<p><a href="http://www.davidaiken.com/wp-content/uploads/2010/07/image8.png#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.davidaiken.com/wp-content/uploads/2010/07/image_thumb8.png" width="644" height="349" /></a> </p>
<p>From here you can create tables, views, stored procedures, create and execute queries. It even has a cube you can spin around.</p>
<p>THIS POSTING IS PROVIDED “AS IS” WITH NO WARRANTIES, AND CONFERS NO RIGHTS</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidaiken.com/2010/07/21/manage-your-sql-azure-databases-with-project-houston/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

