<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Brent&#039;s Notepad</title>
	<atom:link href="http://brentdacodemonkey.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://brentdacodemonkey.wordpress.com</link>
	<description>A placeholder for random thoughts on life, code, and cloud computing</description>
	<lastBuildDate>Fri, 03 May 2013 16:40:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='brentdacodemonkey.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Brent&#039;s Notepad</title>
		<link>http://brentdacodemonkey.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://brentdacodemonkey.wordpress.com/osd.xml" title="Brent&#039;s Notepad" />
	<atom:link rel='hub' href='http://brentdacodemonkey.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Aggregate SLA’s &amp; Windows Azure IaaS</title>
		<link>http://brentdacodemonkey.wordpress.com/2013/05/03/aggregate-slas-windows-azure-iaas/</link>
		<comments>http://brentdacodemonkey.wordpress.com/2013/05/03/aggregate-slas-windows-azure-iaas/#comments</comments>
		<pubDate>Fri, 03 May 2013 15:15:52 +0000</pubDate>
		<dc:creator>Brent</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://brentdacodemonkey.wordpress.com/?p=496</guid>
		<description><![CDATA[I&#8217;d been pondering this a bit anyways, and yesterday actually had a customer ask. So I was forced to dig into this a bit further. And I need for forewarn you, this news may upset a few folks. If you are using Windows Azure Virtual Machines (IaaS), you are taking two dependencies. Windows Azure Compute [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brentdacodemonkey.wordpress.com&#038;blog=16393590&#038;post=496&#038;subd=brentdacodemonkey&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I&#8217;d been pondering this a bit anyways, and yesterday actually had a customer ask. So I was forced to dig into this a bit further. And I need for forewarn you, this news may upset a few folks.
</p>
<p>If you are using Windows Azure Virtual Machines (IaaS), you are taking two dependencies. Windows Azure Compute (to run the VM&#8217;s), and Windows Azure Storage (to persist the state of those VM&#8217;s). What this means is that you don&#8217;t have a single 99.95% sla, you actually have two SLA&#8217;s. And as such, they need to be aggregated since a failure in either, could render your service temporarily unavailable.
</p>
<h2>Calculating Aggregate SLA&#8217;s<br />
</h2>
<p>Some background information before I get to far down this rabbit hole. When you have a solution that takes on multiple dependencies, the SLA you are providing is an aggregate of the underlying SLA&#8217;s. For example…
</p>
<p style="margin-left:36pt;">Two Instances of WA Compute = 99.95% uptime or approximately 263 minutes of downtime per year
</p>
<p style="margin-left:36pt;">Azure Storage = 99.9% uptime or 525 minutes of downtime per year.
</p>
<p style="margin-left:36pt;">This gives us a total possible downtime of 788 minutes or availability of approximately 99.85%.
</p>
<p>Since we have multiple dependencies, we need to take the total amount of downtime we could experience when determining what our availability is.
</p>
<h2>But what about Windows Azure&#8217;s 99.95% SLA?<br />
</h2>
<p>Now this is where things get a bit more… fuzzy. You actually need tor reference the details of the published <a href="http://www.windowsazure.com/en-us/support/legal/sla/">Windows Azure SLA&#8217;s</a>. When we look into the SLA for &#8220;Cloud Services, Virtual Machines, and Virtual Network&#8221;, we&#8217;re after three key terms that factor into the SLA.
</p>
<p style="margin-left:36pt;"><em>&#8220;External Connectivity&#8221; is bi-directional network traffic over supported protocols such as UDP and TCP that can be sent and received from a public IP address.<br />
</em></p>
<p style="margin-left:36pt;"><em> &#8220;Maximum Connectivity Minutes&#8221; is the total accumulated minutes during a billing month for all Internet facing Virtual Machines that have two or more instances deployed in the same Availability Set.  Maximum Connectivity Minutes is measured from when at least two Virtual Machines in the same Availability Set have both been started resultant from action initiated by Customer to the time Customer has initiated an action that would result in stopping or deleting the Virtual Machines.<br />
</em></p>
<p style="margin-left:36pt;"><em>&#8220;Connectivity Downtime&#8221; is the total accumulated minutes that are part of the Maximum Connectivity Minutes that have no External Connectivity.<br />
</em></p>
<p>So what these three items say is that IF you have two <strong>started</strong> virtual machines that are in an availability set, you will be able to connect to them 99.95% of the time or we owe you money back. Note I&#8217;ve highlighted the word &#8216;started&#8217;. Because if you take an external dependency that causes your virtual machine to stop/crash (aka the dependency on Azure Storage for the VM disks), when an instance of your VM stops, it&#8217;s no longer subject to the 99.95% SLA.
</p>
<h2>So where does this leave us<br />
</h2>
<p>Ultimately, exactly where we&#8217;ve always been. In most cases, your solution is going to take multiple dependencies. And as a result, this simple example get compounded. It also doesn&#8217;t change our commitment to you as a customer of Windows Azure. This issue has always been here, even before cloud computing. And for the majority, that extra 0.1% isn&#8217;t going to make much of a difference.
</p>
<p>Now, if you need really high uptime, you have the math above to help you really understand what level of risk your solution may be taking on. And hopefully can leverage that knowledge to help you design resilient solution architectures that are capable of adjusting to these outages and continuing (even if in a degraded state) to delivery functionality to the end users of those solutions.
</p>
<p>
 </p>
<p>
 </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brentdacodemonkey.wordpress.com/496/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brentdacodemonkey.wordpress.com/496/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brentdacodemonkey.wordpress.com&#038;blog=16393590&#038;post=496&#038;subd=brentdacodemonkey&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brentdacodemonkey.wordpress.com/2013/05/03/aggregate-slas-windows-azure-iaas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6b9db6386dfb619649eda05c07f30359?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">brentstineman</media:title>
		</media:content>
	</item>
		<item>
		<title>IaaS – The changing face of Windows Azure</title>
		<link>http://brentdacodemonkey.wordpress.com/2013/03/06/iaas-the-changing-face-of-windows-azure/</link>
		<comments>http://brentdacodemonkey.wordpress.com/2013/03/06/iaas-the-changing-face-of-windows-azure/#comments</comments>
		<pubDate>Wed, 06 Mar 2013 21:27:32 +0000</pubDate>
		<dc:creator>Brent</dc:creator>
				<category><![CDATA[Windows Azure Platform]]></category>

		<guid isPermaLink="false">http://brentdacodemonkey.wordpress.com/?p=484</guid>
		<description><![CDATA[I need to preface this post by saying I should not be considered, by any stretch of imagination, a &#8220;network guy&#8221;. I know JUST enough to plug in an Ethernet cable, not to fall for the old &#8220;the token fell out of the network ring&#8221; gag, and know how to tracert connectivity issues. Thanks mainly [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brentdacodemonkey.wordpress.com&#038;blog=16393590&#038;post=484&#038;subd=brentdacodemonkey&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p style="text-align:center;"><em>I need to preface this post by saying I should not be considered, by any stretch of imagination, a &#8220;network guy&#8221;. I know JUST enough to plug in an Ethernet cable, not to fall for the old &#8220;<a href="http://dilbert.com/strips/comic/1996-05-02/">the token fell out of the network ring</a>&#8221; gag, and know how to tracert connectivity issues. Thanks mainly to my past overindulgence in online role playing games.<br />
</em></p>
<p>In June of 2012, we announced that we would be adding Infrastructure as a Service (IaaS) features to the Windows Azure Platform. While many believe that Platform as a Service (PaaS) is still the ultimate &#8220;sweet spot&#8221; with regards to cost/benefit ratios, the reality is that PaaS adoption is… well… challenging. After 25+ years of buying, installing, configuring, and maintaining hardware, nearly everyone in the IT industry tends to think of terms of servers, both physical and virtual. So the idea of having applications and data float around within a datacenter and not tied to specific locations is just alien for many. This created a barrier to the adoption of PaaS, a barrier that we are hoping our IaaS services will help bridge (not sure about &#8220;bridging barriers&#8221; as a metaphor since I always visualize barriers as those concrete fence things on the side of highway construction sites for but we&#8217;ll just go with it).</p>
<p>Unfortunately, there&#8217;s still a lot of confusion about what our IaaS solution is and how to work with this. Over the last few months, I&#8217;ve run into this several times with partners so I wanted to pull together some of my learnings into a single blog post. As much for my own personal reference as for me to be able to easily share it with all of you.</p>
<h2>Some terminology</h2>
<p>So I&#8217;d like to start by explaining a few terms as they are used within the Windows Azure Platform&#8230;</p>
<p><strong>Cloud Service</strong> – This is a collection of virtual machines (either PaaS role instances or IaaS virtual machines) representing an isolation boundary that contains computational workloads. A Cloud Service can contain either PaaS compute instances, or IaaS Virtual Machines, but not both. (<strong>UPDATE 4/16/2013:</strong> A IaaS VM hosting Cloud Service will only appear in the cloud service tab of the management portal after at second VM has been added to it. Once visible, it will remain so until it is deleted).</p>
<p><strong>Availability Set</strong> – For PaaS solutions, the Windows Azure Fabric already knows to distribute the same workload across different physical hardware within the datacenter. But for IaaS, I need to tell it to do this with the specific virtual machines I&#8217;m creating. We do this by placing the virtual machines into an availability set.</p>
<p><strong>Virtual Network</strong> &#8211; Because addressability to the PaaS or IaaS instances within Cloud Services is limited to only those ports that you declare (by configuring endpoints), it&#8217;s sometimes helpful to have a way to create bridges between those boundaries or even between them and on-premises networks. This is where Windows Azure Virtual Networks come into play.</p>
<p>The reason these items are important is that in Windows Azure you&#8217;re going to use them to define your solution. Each piece represents a way to group, or arrange resources and how they can be addressed.</p>
<h2>You control the infrastructure, mostly…</h2>
<p>Platform as a Service, or PaaS, handles a lot for you (no surprise as that&#8217;s part of the value proposition). But in Infrastructure as a Service, IaaS, you take on some of that responsibility. The problem is that we are used to taking care of traditional datacenter deployments and either a) don&#8217;t understand what IaaS still does for us and b) just aren&#8217;t sure how this cloud stuff is supposed to be used. So we, through no fault of our own try to do things the way we always have. And who could really blame us?</p>
<p>So let&#8217;s start with what Windows Azure IaaS still does for you. It obviously handles the physical hardware and hypervisor management. This includes provisioning the locations for our Virtual Machines, getting them deployed, and of course moving them around the data center in the case of a hardware failure or host OS (the server that&#8217;s hosting our virtual machine) upgrades. The Azure Fabric, our secret sauce as it were, also controls basic datacenter firewall configuration (what ports are exposed to the internet), load balancing, and addressability/visibility isolation (that Cloud Service thing I was talking about). This covers everything right up to the virtual machine itself. But that&#8217;s not where it stops. To help secure Windows Azure, we control how all the virtual machines talk to our network. This means that the Azure Fabric also has control of the virtual NIC that is installed into your VM&#8217;s!</p>
<p>Now the reason this is important is that there are some things you&#8217;d normally try to do if you were creating a network in a traditional datacenter. Like possibly providing fixed IP&#8217;s to the servers so you can easily do name resolution. Fixed IPs in a cloud environment is generally a bad idea. Especially so if that cloud is built on the concept of having the flexibility to move stuff around the datacenter for you if it needs too. And if this happens in Windows Azure, it&#8217;s pretty much assured that the virtual NIC will get torn down and rebuilt and in the process lose any customizations you made to it. This is also a frequent cause for folks losing the ability to connect to their VMs (something that&#8217;s usually fixable by re-sizing/kicking the VM via the management portal). It also highlights one key, but not often thought of feature that Windows Azure provides for you, <a href="http://msdn.microsoft.com/en-us/library/windowsazure/jj156088.aspx">server name resolution</a>.</p>
<h2>Virtual Machine Name Resolution</h2>
<p>The link I just dropped does a pretty good job of explaining what&#8217;s available to you with Windows Azure. You can either <a href="http://msdn.microsoft.com/en-us/library/windowsazure/jj156088.aspx">let Windows Azure do it for you</a> and leverage the names you provided for the virtual machines when you created them, or you can use Virtual Networking to <a href="http://msdn.microsoft.com/en-us/library/windowsazure/jj156088.aspx">bring your own DNS</a>. Both work well, so it&#8217;s really a matter of selecting the right option. The primary constraint is that the Windows Azure provided name resolution will only work for virtual machines (be they IaaS machines or PaaS role instances) hosted in Windows Azure. If you need to provide name resolution between cloud and on-premises, you&#8217;re going to want to likely use your own DNS server.</p>
<p>The key here again is to not hardcode IP address. Pick the appropriate solution and let it do the work for you.</p>
<h2>Load Balanced Servers</h2>
<p><img class="alignright" alt="" src="http://brentdacodemonkey.files.wordpress.com/2013/03/030613_2129_iaasthechan1.png?w=630" />The next big task is how to load balance virtual machines in IaaS. For the most part, this isn&#8217;t really any different than how you&#8217;d do it for PaaS Cloud Services, create the VM, and &#8220;attach&#8221; it to an existing Virtual Machine (this places both virtual machines within the same cloud service). Then, as long as both machines are watching the same ports, the traffic will be balanced between the two by the Windows Azure Fabric.</p>
<p>If you&#8217;re using the portal to create the VM, you&#8217;ll need to make sure you use the &#8220;create from gallery&#8221; option and not quick create. Then as you progress through the wizard, you&#8217;ll hit the step where it asks you if you want to join the new virtual machine to an existing virtual machine or leave it as standalone.</p>
<p>Now once they are both part of the same cloud service, we simply edit the available endpoints. In the management portal, you&#8217;ll select a Virtual Machine, and either add or edit the endpoint using the tools menu across the bottom. Then you set the endpoint attributes manually (if it&#8217;s a new endpoint that&#8217;s not already load balanced), or choose to load balance it with a previously defined endpoint. Easy-peasy. <span style="font-family:Wingdings;">J</span></p>
<h2>High Availability</h2>
<p>Now that we have load balanced endpoints, the next step is to make sure that if one of our load balanced virtual machines goes offline (say a host OS upgrade or hardware failure), that the service doesn&#8217;t become entirely unavailable. In Windows Azure Cloud Services, the Fabric would automatically distribute the running instances across multiple <a href="http://blogs.msdn.com/b/gonzalorc/archive/2010/01/19/update-and-upgrade-domains.aspx">fault domains</a>. To put it simply, fault domains try to help ensure that workloads are spread across multiple pieces of hardware, this way if there is a hardware failure on a &#8216;rack&#8217;, it won&#8217;t take down both machines. When working with IaaS, we still have this as an option but we need to tell the Azure Fabric that we want to take advantage of this by placing our virtual machines into an Availability Set so the Azure Fabric knows it should distribute them.</p>
<p>You configure a virtual machine that&#8217;s already deployed to join it to an Availability Set, or we can assign a new one to a set when we create/deploy it (providing we&#8217;re not using Quick Create which you hopefully aren&#8217;t anyways because you can&#8217;t place a quick create VM into an existing cloud service). Both options work equally well and we can create multiple Availability Sets within a Cloud Service.</p>
<h2>Virtual Networks</h2>
<p>So you might ask, this is all find and dandy if the virtual machines are deployed as part of a single cloud service. But I can&#8217;t combine PaaS and IaaS into a single cloud service, and I also can&#8217;t do direct machine addressing if the machine I&#8217;m connecting to exists in another cloud service, or even on-premises. So how do I fix that? The answer is <a href="http://msdn.microsoft.com/en-us/library/windowsazure/jj156007.aspx">Windows Azure Virtual Networks</a>.</p>
<p>In Windows Azure, the Cloud Service is an isolation boundary, fronted by a gatekeeper layer that serves as a combination load balancer and NAT. The items inside the cloud service can address each other directly and any communication that comes in from outside of the cloud service boundary has to come through the gatekeeper. Think of the cloud service as a private network branch. This is good because it provides a certain level of network security, but bad in that we now have challenges if we&#8217;re trying to communication across the boundary.</p>
<p>Virtual Network allows you to join resources across cloud service boundaries, or by leveraging an on-premises VPN gateway to join cloud services and on-premises services. Acting as a bridge across the isolation boundaries and enabling direct addressability (providing there&#8217;s appropriate domain resolution) without the need to publically expose the individual servers/instances to the internet.</p>
<h2>Bringing it all together</h2>
<p>So if we bring this all together, we now have a way to create complex solutions that mix and match different compute resources (we cannot currently join things like Service Bus, Azure Storage, etc… via Virtual Network). One such example might be the following diagram…</p>
<p style="text-align:center;"><img alt="" src="http://brentdacodemonkey.files.wordpress.com/2013/03/030613_2129_iaasthechan2.png?w=630" /></p>
<p>A single Windows Azure Virtual Network that combines an on-premises server, a PaaS Cloud Service, and both singular and load balanced virtual machines. Now I can&#8217;t really speculate on where this could go next, but I think we have a fairly solid starting point for some exciting scenarios. And if we do for IaaS what we&#8217;ve done for the PaaS offering over the last few years… continuing to improve the tooling, expanding the feature set, and generally just make things more awesome, I think there&#8217;s a very bright future here.</p>
<p>But enough chest thumping/flag waving. Like many topics here, I created this to help me better understand these capabilities and hopefully some of you may benefit from it as well. If not, I&#8217;ll at least share with you a few links I found handy:</p>
<p>Mike Washam – <a href="http://michaelwasham.com/2012/06/08/understanding-windows-azure-virtual-machines/">Windows Azure Virtual Machines</a></p>
<p>MSDN – <a href="http://msdn.microsoft.com/en-us/library/windowsazure/jj156088.aspx">Windows Azure Name Resolution</a></p>
<p>WindowsAzure.com – <a href="http://www.windowsazure.com/en-us/manage/windows/common-tasks/how-to-load-balance-virtual-machines/">Load Balancing Virtual Machines</a></p>
<p>WindowsAzure.com – <a href="http://www.windowsazure.com/en-us/manage/windows/common-tasks/manage-vm-availability/">Manage the Availability of Virtual Machines</a></p>
<p>Until next time!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brentdacodemonkey.wordpress.com/484/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brentdacodemonkey.wordpress.com/484/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brentdacodemonkey.wordpress.com&#038;blog=16393590&#038;post=484&#038;subd=brentdacodemonkey&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brentdacodemonkey.wordpress.com/2013/03/06/iaas-the-changing-face-of-windows-azure/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6b9db6386dfb619649eda05c07f30359?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">brentstineman</media:title>
		</media:content>

		<media:content url="http://brentdacodemonkey.files.wordpress.com/2013/03/030613_2129_iaasthechan1.png" medium="image" />

		<media:content url="http://brentdacodemonkey.files.wordpress.com/2013/03/030613_2129_iaasthechan2.png" medium="image" />
	</item>
		<item>
		<title>Windows Azure Web Sites – Quotas, Scaling, and Pricing</title>
		<link>http://brentdacodemonkey.wordpress.com/2012/12/11/windows-azure-web-sites-quotas-scaling-and-pricing/</link>
		<comments>http://brentdacodemonkey.wordpress.com/2012/12/11/windows-azure-web-sites-quotas-scaling-and-pricing/#comments</comments>
		<pubDate>Tue, 11 Dec 2012 16:58:56 +0000</pubDate>
		<dc:creator>Brent</dc:creator>
				<category><![CDATA[Windows Azure Platform]]></category>

		<guid isPermaLink="false">http://brentdacodemonkey.wordpress.com/?p=475</guid>
		<description><![CDATA[It hasn&#8217;t been easy making the transition from a consultant to someone that for lack of a better explanation is a cross between pre-sales and technical support. But I&#8217;ve come to love two aspects of this job. First off, I get to talk to many different people and I&#8217;m constantly learning as much from their [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brentdacodemonkey.wordpress.com&#038;blog=16393590&#038;post=475&#038;subd=brentdacodemonkey&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>It hasn&#8217;t been easy making the transition from a consultant to someone that for lack of a better explanation is a cross between pre-sales and technical support. But I&#8217;ve come to love two aspects of this job. First off, I get to talk to many different people and I&#8217;m constantly learning as much from their questions as I&#8217;m helping teach them about the platform. Secondly, when not talking with partners about the platform, I&#8217;m digging up answers to questions. This gives me the perfect excuse… er… reason to dig into some of the features and learn more about them. I had to do this as a consultant, but the issue there is that since I&#8217;d be asked to do this by paying clients, they would own the results. But now I do this work on behalf of Microsoft, it&#8217;s much easier to share these findings with the community (providing it doesn&#8217;t violate non-disclosure agreements of course). And since this blog has always been a way for me to document things so I can refer back to them, it&#8217;s a perfect opportunity to start sharing this research.</p>
<p>Today&#8217;s topic is Windows Azure Web Sites quotas and pricing. Currently we (Microsoft) doesn&#8217;t IMHO do a very good job of making this information real clear. Some of it is available over on the pricing page, but for the rest you&#8217;ve got to dig it out of blog posts or from the Web Site dashboard&#8217;s usage overview details in the management portal. So I decided it was time to consolidate a few things.</p>
<h2>Usage Quotas</h2>
<p>A key aspect of the use of any service is to understand the limits. And nowhere is this truer then the often complex/confusing world of cloud computing services. But when someone slaps a &#8220;free&#8221; in front of a service, we tend to forget this. Well here I am to remind you. Windows Azure Web Sites has several dials that we need to be aware of when selecting the level/scale of Windows Azure Web Sites (Free, Shared, and Reserved).</p>
<p><strong>File System/Storage:</strong> This is the total amount of space you have to store your site and content. There&#8217;s no timeframe on this one. If you reach the quota limit, you simply can&#8217;t write any new content to the system.</p>
<p><strong>Egress Bandwidth:</strong> This is the amount of content that is served up by your web site. If you exceed this quota, your site will be temporarily suspended (no further requests) until the quota timeframe (1 day) resets.</p>
<p><strong>CPU Time:</strong> This is the amount of time that is spent processing requests for your web site. Like the bandwidth quota, if you exceed the quota, your site will be temporarily suspended until the quota timeframe resets. There are two quota timeframes, a 5 minute limit, and a daily limit.</p>
<p><strong>Memory:</strong> is the amount of RAM that the site can use at one shot (there&#8217;s no timeframe). If you exceed the quota, a long running or abusive process will be terminated. And if this occurs often enough, your site may be suspended. Which is pretty good encouragement to rethink that process.</p>
<p><strong>Database:</strong> There&#8217;s also up to 20mb for database support for your related database (MySQL or Windows Azure SQL Database currently). I can&#8217;t find any details but I&#8217;m hoping/guessing this will work much like the File Storage quota.</p>
<p>Now for the real meat of this. What are the quotas for each tier? For that I&#8217;ve created the following table.</p>
<div>
<table style="border-collapse:collapse;" border="0">
<col style="width:156px;" />
<col style="width:156px;" />
<col style="width:156px;" />
<col style="width:156px;" />
<tbody valign="top">
<tr style="background:#d0cece;">
<td style="padding-left:7px;padding-right:7px;border:solid .5pt;">
<p style="text-align:center;"><strong>Quota Resource</strong></p>
</td>
<td style="padding-left:7px;padding-right:7px;border-top:solid .5pt;border-left:none;border-bottom:solid .5pt;border-right:solid .5pt;">
<p style="text-align:center;"><strong>Free Tier</strong></p>
</td>
<td style="padding-left:7px;padding-right:7px;border-top:solid .5pt;border-left:none;border-bottom:solid .5pt;border-right:solid .5pt;">
<p style="text-align:center;"><strong>Shared Tier<br />
</strong></p>
<p style="text-align:center;"><strong>(per web site)</strong></p>
</td>
<td style="padding-left:7px;padding-right:7px;border-top:solid .5pt;border-left:none;border-bottom:solid .5pt;border-right:solid .5pt;">
<p style="text-align:center;"><strong>Reserved Tier<br />
</strong></p>
<p style="text-align:center;"><strong>(up to 100 sites)</strong></p>
</td>
</tr>
<tr>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:solid .5pt;border-bottom:solid .5pt;border-right:solid .5pt;">File Storage</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:none;border-bottom:solid .5pt;border-right:solid .5pt;">1024mb for all sites</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:none;border-bottom:solid .5pt;border-right:solid .5pt;">1024mb</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:none;border-bottom:solid .5pt;border-right:solid .5pt;">10gb</td>
</tr>
<tr>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:solid .5pt;border-bottom:solid .5pt;border-right:solid .5pt;">Egrees Bandwidth</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:none;border-bottom:solid .5pt;border-right:solid .5pt;">165mb/day per datacenter, 5gb per region</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:none;border-bottom:solid .5pt;border-right:solid .5pt;">Pay as you go, not included in base price</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:none;border-bottom:solid .5pt;border-right:solid .5pt;">Pay as you go, not included in base price</td>
</tr>
<tr>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:solid .5pt;border-bottom:solid .5pt;border-right:solid .5pt;">CPU Time</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:none;border-bottom:solid .5pt;border-right:solid .5pt;">1hr/day, 2.5 minutes of every 5</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:none;border-bottom:solid .5pt;border-right:solid .5pt;">4hrs/day, 2.5 minutes of every 5</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:none;border-bottom:solid .5pt;border-right:solid .5pt;">N/A</td>
</tr>
<tr>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:solid .5pt;border-bottom:solid .5pt;border-right:solid .5pt;">Memory</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:none;border-bottom:solid .5pt;border-right:solid .5pt;">1024mb/hr</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:none;border-bottom:solid .5pt;border-right:solid .5pt;">512mb/hr</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:none;border-bottom:solid .5pt;border-right:solid .5pt;">N/A</td>
</tr>
<tr>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:solid .5pt;border-bottom:solid .5pt;border-right:solid .5pt;">Database</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:none;border-bottom:solid .5pt;border-right:solid .5pt;">20mb</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:none;border-bottom:solid .5pt;border-right:solid .5pt;">20mb</td>
<td style="padding-left:7px;padding-right:7px;border-top:none;border-left:none;border-bottom:solid .5pt;border-right:solid .5pt;">N/A</td>
</tr>
</tbody>
</table>
</div>
<p>Now there&#8217;s an important but slightly confusing &#8220;but&#8221; to the free tier. At that level, you get a daily limit egress bandwidth quota per sub-region (aka datacenter), but there&#8217;s also a regional (US, EU, Asia) limit (5GB). The regional limit is the sum total off all web sites you&#8217;re hosting that is shared with any other services. So if you&#8217;re also using Blob storage to serve up images from your site that will count against your &#8220;free&#8221; 5 GB. But when you move to the shared/reserved tier, there&#8217;s no limit, but you pay for every gigabyte that leaves the datacenter.</p>
<p><img alt="" src="http://brentdacodemonkey.files.wordpress.com/2012/12/121112_1659_windowsazur1.png?w=630" align="right" /></p>
<h2>Monitoring Usage</h2>
<p>Now the next logical question is how you monitor the resources your sites are using. Fortunately, the most recent update to Windows Azure portal has a dashboard that provides a quick glance as how much you&#8217;re using of each quota. This displays just below usage grid on the &#8220;Dashboard&#8221; panel of the web site.</p>
<p>At a glance you can tell where you on any quotas which also makes it convenient for you to predict your usage. Run some common scenarios and see what they do to your numbers and extrapolate from there.</p>
<p>You can also configure the site for diagnostics (again via the management portal). This allows you to take the various performance indicators and save them to Windows Azure Storage. From there you can download the files and set up automated monitors to alert you to problems. Just keep in mind that turning this on will consume resources and incur additional charges.</p>
<p>Fortunately, there&#8217;s a pretty good article we&#8217;ve published on <a href="http://www.windowsazure.com/en-us/manage/services/web-sites/how-to-monitor-websites/">Monitoring Windows Azure Web Sites</a>.</p>
<h2>Scaling &amp; Pricing</h2>
<p>Now that we&#8217;ve covered your usage quotas and how to monitor your usage, it&#8217;s important to understand how we can scale the capacity of our web sites and the impact this has on pricing.</p>
<p>Scaling our web site is pretty straight forward. We go can go from the Free Tier, to Shared, to Reserved using the management portal. Select the web site, click on the level, and then save to &#8220;scale&#8221; your site. But before you do that, you will want to understand the pricing impacts.</p>
<p>At the Free tier, we get up to 10 web sites. When we move a web site to shared, we will pay $0.02 per hour for each web site (at general availability). Now that this point, I can mix and match free (10 per sub-region/datacenter) and shared (100 per sub-region/datacenter) web sites. But things get a bit trickier when we move to reserved. A reserved web site is a dedicated virtual machine for your needs. When you move a web site within a region to the reserved tier, all web sites in that same sub-region/datacenter (up to the limit of 100) will also be moved to reserved.</p>
<p>Now this might seem a bit confusing until you realize that at the reserved tier, you&#8217;re paying for the virtual machine and not an individual web site. So it makes sense to have all your sites hosted on that instance, maximizing your investment. Furthermore, if you are running enough shared tier web sites, it may be more cost effective to run them as reserved.</p>
<p>Back to scaling, if you scale back down to the free or shared tiers, the other sites will revert back to their old states. For example, let&#8217;s assume you have two web sites one at the free tier, one at the shared tier. I scale the free web site up to reserved and now both sites are reserved. If I scale the original free tier site back to free, the other site returns to shared. If I opted to scale the original shared site back to shared or free, then the original free site returns to its previous free tier. So it&#8217;s important when dealing with reserved sites that you remember what tier they were at previously.</p>
<p>The tiers are not our only option for scaling our web sites. We also have a slider labelled instance count if we are running a Shared or Reserved site. When running at the shared tier, this slider will change the number of processing threads that are servicing the web site allowing us between 1 and 6 threads. Of course, it we increase the threads, there&#8217;s a greater risk of hitting our cpu usage quota. But this adjustment could come in real handy if we&#8217;re experiencing a short term spike in traffic. Running at the reserved tier, the slider increases the number of virtual machine instances we (and subsequently our cost). This option allows us to run up to 10 reserved instances.</p>
<p>Also at the reserved tier, we can increase the size of our virtual machine. By default, our reserved instance will be a &#8220;small&#8221; giving us a single cpu core and 1.75 GB of memory at a cost of $0.12/hr. We can increase the size to &#8220;Medium&#8221; and even &#8220;Large&#8221; with each size increase doubling our resources and the price per hour ($0.24 and $0.48 respectively). This cost will be per virtual machine instance, so if I have opted to run 3 instances, take my cost per hour for the size and multiple it by 3.</p>
<h2>So what&#8217;s next?</h2>
<p>This pretty much hits the limits of what we can do with scaling web sites. But fortunately we&#8217;re running on a platform that&#8217;s built for scale. So it&#8217;s just a hop, skip, and jump from Web Sites to Windows Azure Cloud Services (Platform as a Service) or Windows Azure Virtual Machines (Infrastructure as a service). But that&#8217;s an article for another day. <span style="font-family:Wingdings;">J</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brentdacodemonkey.wordpress.com/475/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brentdacodemonkey.wordpress.com/475/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brentdacodemonkey.wordpress.com&#038;blog=16393590&#038;post=475&#038;subd=brentdacodemonkey&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brentdacodemonkey.wordpress.com/2012/12/11/windows-azure-web-sites-quotas-scaling-and-pricing/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6b9db6386dfb619649eda05c07f30359?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">brentstineman</media:title>
		</media:content>

		<media:content url="http://brentdacodemonkey.files.wordpress.com/2012/12/121112_1659_windowsazur1.png" medium="image" />
	</item>
		<item>
		<title>BUILD 2012 – Not just for Windows anymore</title>
		<link>http://brentdacodemonkey.wordpress.com/2012/11/05/build-2012-not-just-for-windows-anymore/</link>
		<comments>http://brentdacodemonkey.wordpress.com/2012/11/05/build-2012-not-just-for-windows-anymore/#comments</comments>
		<pubDate>Mon, 05 Nov 2012 16:58:46 +0000</pubDate>
		<dc:creator>Brent</dc:creator>
				<category><![CDATA[Windows Azure Platform]]></category>

		<guid isPermaLink="false">http://brentdacodemonkey.wordpress.com/?p=470</guid>
		<description><![CDATA[Last week marked the second BUILD conference. In 2011, BUILD replaced the Microsoft PDC conference in an event that was so heavily Windows 8 focused that it was even host at buildwindows.com. While the URL didn&#8217;t change for 2012, the focus sure did as this event also marked the latest round of big release news [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brentdacodemonkey.wordpress.com&#038;blog=16393590&#038;post=470&#038;subd=brentdacodemonkey&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Last week marked the second BUILD conference. In 2011, BUILD replaced the Microsoft PDC conference in an event that was so heavily Windows 8 focused that it was even host at buildwindows.com. While the URL didn&#8217;t change for 2012, the focus sure did as this event also marked the latest round of big release news for Windows Azure. In this post (which I&#8217;m publishing directly from MS Word 2013 btw), I&#8217;m going to give a quick rundown of the Windows Azure related announcements. Think of this as your <a href="http://www.cliffsnotes.com/">Cliff Notes</a> version of the conference.
</p>
<h3>Windows Azure Service Bus for Windows Server – V1 Released<br />
</h3>
<p>Previously released as a beta/preview back in June, <a href="http://blogs.msdn.com/b/windowsazure/archive/2012/10/24/announcing-public-availability-of-service-bus-for-windows-server-service-bus-1-0.aspx">this on-premise flavor of the Windows Azure Service bus is now fully released and available for download</a>. Admittedly, it&#8217;s strictly for brokered messaging for now. But it&#8217;s still a substantial step towards providing feature parity between public and private cloud solutions. Now we just need to hope that shops that opt to run this will run it as internal SaaS and not set up multiple silos. Don&#8217;t get me wrong. It&#8217;s nice to know we have the flexibility to do silos, but I&#8217;m hoping we learn from what we&#8217;ve seen in the public cloud and don&#8217;t fall back to old patterns.
</p>
<p>One thing to keep in mind with this… It&#8217;s now possible for multiple versions of the Service Bus API to be running within an organization. To date, the public service has only had two major API versions. But going forward, we may need to be able to juggle even more. And while there will be a push to keep the hosted and on-premises versions at similar versions, there&#8217;s nothing requiring someone hosting it on-premises to always upgrade to the latest version. So as solution developers/architects, we&#8217;ll want to be prepared for be accommodating here.
</p>
<h3>Windows Azure Mobile Services – Windows Phone 8 Support<br />
</h3>
<p>With Windows Phone 8 being formally launched the day before the BUILD conference, it only makes sense that we&#8217;d seen related announcements. And a key one of those was <a href="http://blogs.msdn.com/b/windowsazure/archive/2012/11/01/building-out-mobile-services-support-to-windows-phone-8.aspx">the addition of Windows Phone 8 support to Windows Azure Mobile Services</a>. This announcement makes Windows Phone 8, the 3<sup>rd</sup> supported platform (Windows Store &amp; iOS apps) for Mobile Services. This added to an announcement earlier in the month which expanded support for items like sending email, and different identity providers. So the Mobile Services team is definitely burning the midnight oil to get new features out to this great platform.
</p>
<h3>New Windows Azure Storage Scalability Targets<br />
</h3>
<p><a href="http://blogs.msdn.com/b/windowsazurestorage/archive/2012/11/04/windows-azure-s-flat-network-storage-and-2012-scalability-targets.aspx">New scale targets have been announced for storage accounts created after June 7<sup>th</sup> 2012</a>. This change has been enabled by the new &#8220;flat network&#8221; topology that&#8217;s being deployed into the Windows Azure Datacenters. In a nutshell, it allows the tps scale targets to be increased by 4x and the upper limit of a storage account to be raised to 200tb (2x). This new topology will continue to be rolled out through the end of the year <span style="text-decoration:underline;">but will only affect storage accounts created after the 07/12/2012</span> as mentioned above. These scale target improvements (which BTW are separate from the published Azure Storage SLA) will really help reduce the amount of &#8216;sharding&#8217; that needs to be done for those with higher throughput requirements.
</p>
<h3>New 1.8 SDK – Windows Server 2012, .NET 4.5, and new Storage Client<br />
</h3>
<p>BUILD also marked <a href="http://msdn.microsoft.com/en-us/library/windowsazure/ff683673.aspx">the launch of the new 1.8 Windows Azure SDK</a>. This release is IMHO the most significant update to the SDK since the 1.3 version was launched almost 2 years ago. You could write a blog post any one of the key features, but since they are all so closely related and this is supposed to be a highlight post, I&#8217;m going to bundle it up.
</p>
<p>The new SDK introduces the new &#8220;OS Family 3&#8243; to Windows Azure Cloud Services giving us support for Windows Server 2012. Now when you combine this with the added support for .NET 4.5 and IIS 8, we can start taking advantage of technology like Web Sockets. Unfortunately <a href="http://blogs.msdn.com/b/windowsazure/archive/2012/10/24/getting-started-with-windows-azure-hdinsight-service.aspx">Web Sockets are not enabled by default</a> so there is some work you&#8217;ll need to do to take advantage of it. You may also need to tweak the internal Windows Firewall. A few older Guest OS&#8217;s were also depreciated so you may want to <a href="http://msdn.microsoft.com/en-us/library/windowsazure/ee924680.aspx">refer to the latest update of the compatibility matrix</a>.
</p>
<p>The single biggest, and subsequently most confusing piece of this release has to do with the <a href="http://blogs.msdn.com/b/windowsazurestorage/archive/2012/10/29/introducing-windows-azure-storage-client-library-2-0-for-net-and-windows-runtime.aspx">new 2.0 Storage Client</a>. Now this update includes some great features including support for a preview release of the storage client toolkit for Windows Runtime (Windows Store) apps. However, there are some SIGNIFICANT changes to the client, so I&#8217;d recommend you review the list of <a href="http://blogs.msdn.com/b/windowsazurestorage/archive/2012/10/29/windows-azure-storage-client-library-2-0-breaking-changes-amp-migration-guide.aspx">Breaking Changes</a> and <a href="http://blogs.msdn.com/b/windowsazurestorage/archive/2012/11/01/known-issues-for-windows-azure-storage-client-library-2-0-for-net-and-windows-runtime.aspx">Known Issues</a> before you decide to start converting over. Fortunately, all the new features are in a new set of namespaces (Windows.AzureStorage.Storage<strong>Client</strong> has become simply Windows.Azurestorage.Storage). So this does allow you to mix and match old functionality with the new. But forewarned is forearmed as they say. So read up before you just dive into the new client headlong.
</p>
<p>For more details on some of the known issues with this SDK and the workarounds, <a href="http://msdn.microsoft.com/en-us/library/windowsazure/jj835813.aspx">refer to the October 2012 release notes</a> and you can learn about all the changes to the Visual Studio tools by checking out &#8220;<a href="http://msdn.microsoft.com/en-us/library/windowsazure/ff683673.aspx">What&#8217;s New in the Windows Azure Tools</a>&#8220;.
</p>
<h3>HDInsight – Hadoop on Windows Azure<br />
</h3>
<p>Technically, this was released the week before BUILD, but I&#8217;m going to touch on it none the less. A preview of HDInsight has been launched that allows you to help test out the new Apache™ Hadoop® on Windows Azure service. This will feature support for common frameworks such as Pig and Hive and it also includes a local developer installation of the HDInsight Server and SDK for writing jobs with .NET and Visual Studio.
</p>
<p>It&#8217;s exciting to see Microsoft embracing these highly popular open source initiatives. So if you&#8217;d doing anything with big data, you may want to <a href="http://blogs.msdn.com/b/windowsazure/archive/2012/10/24/getting-started-with-windows-azure-hdinsight-service.aspx">run over and check out the blog post for additional details</a>.
</p>
<h3>Windows Azure – coming to China<br />
</h3>
<p>Doug Hauger also announced that Microsoft has reached an agreement (Memorandum of Understanding, aka an agreement to start negotiations) which will license Windows Azure technologies to 21Vianet. This will in turn allow them to offer <a href="http://blogs.msdn.com/b/windowsazure/archive/2012/11/01/cloud-os-is-coming-to-china.aspx">Windows Azure in China from local datacenters</a>. While not yet a fully &#8220;done deal&#8221;, it&#8217;s a significant first step. So here&#8217;s hoping the discussions are concluded quickly and that this is just the first of many such deals we&#8217;ll see struck in the coming year. So all you Aussies, hold out hope! <span style="font-family:Wingdings;">J</span>
	</p>
<h3>Other news<br />
</h3>
<p>This was just the beginning. The Windows Azure team ran down a slew of <a href="http://blogs.msdn.com/b/windowsazure/archive/2012/10/31/here-s-what-s-new-with-windows-azure.aspx">other slightly less high-profile but equally important announcements on the team blog</a>. Items like a preview of the Windows Azure Store, GA (general availability) for the Windows Azure dedicated, distributed in-memory cache feature launched back in June with the 1.7 SDK, and finally the launch of the <a href="http://blogs.msdn.com/b/bharry/archive/2012/10/31/team-foundation-service-rtm.aspx">Visual Studio Team Foundation Service</a> which has been in preview for the last year.
</p>
<h3>In closing…<br />
</h3>
<p>All in all, it was a GREAT week in the cloud. Or as James Staten put it on ZDNet, &#8220;<a href="http://www.zdnet.com/youre-running-out-of-excuses-to-not-try-microsoft-windows-azure-7000006776/">You&#8217;re running out of excuses to not try Microsoft Windows Azure</a>&#8220;. And this has just been the highlights. If you&#8217;d like to learn more, I highly recommend you run over and <a href="http://channel9.msdn.com/Events/Build/2012?media=True">check out the session recordings from BUILD 2012</a> or talk to your local Microsoft representative.
</p>
<p>PS – <a href="http://www.microsoft.com/en-us/download/confirmation.aspx?id=35473">Don&#8217;t forget to snag your own copy of the great new Windows Azure poster</a>!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brentdacodemonkey.wordpress.com/470/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brentdacodemonkey.wordpress.com/470/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brentdacodemonkey.wordpress.com&#038;blog=16393590&#038;post=470&#038;subd=brentdacodemonkey&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brentdacodemonkey.wordpress.com/2012/11/05/build-2012-not-just-for-windows-anymore/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6b9db6386dfb619649eda05c07f30359?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">brentstineman</media:title>
		</media:content>
	</item>
		<item>
		<title>Joining Microsoft</title>
		<link>http://brentdacodemonkey.wordpress.com/2012/10/12/joining-microsoft/</link>
		<comments>http://brentdacodemonkey.wordpress.com/2012/10/12/joining-microsoft/#comments</comments>
		<pubDate>Fri, 12 Oct 2012 15:34:07 +0000</pubDate>
		<dc:creator>Brent</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">https://brentdacodemonkey.wordpress.com/?p=468</guid>
		<description><![CDATA[Seven years ago, I set out to take charge of my career. I’d spent the last 13 years working as an FTE for various employers both large and small. And realized that for the last 5-6 years, I’d basically been coasting along with the currents. If I wanted to go anywhere, I needed to take [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brentdacodemonkey.wordpress.com&#038;blog=16393590&#038;post=468&#038;subd=brentdacodemonkey&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Seven years ago, I set out to take charge of my career. I’d spent the last 13 years working as an FTE for various employers both large and small. And realized that for the last 5-6 years, I’d basically been coasting along with the currents. If I wanted to go anywhere, I needed to take control and find a direction. </p>
<p>With that decision, I set out to pursue a position with a consulting firm. It figured it would provide me with challenges that would help me grow.&#160; Fortunately, just as I made this decision, my brother had a coworker leave to go to work for a local firm. I shared my info and within a few days got a call. Even more fortunately, they had an immediate need for someone with my exact skills (knowing both the mainframe and .NET worlds). Things moved very rapidly and in less than a month, I joined Sogeti USA as a Senior Consultant. </p>
<p>I haven’t regretted that decision for a moment. Working at Sogeti has been a great experience. It has had its up and downs like any job. But taken on the whole, I’ve really liked it here. I have a management team that I feel honestly cares about me and my career growth. I work with some great people both locally and globally. And most of all, they provided me with the opportunity to seek out new ventures for myself and the company. In my seven years here, I’ve gone from being a local code-slinging, heads down delivery resource to a national thought leader with the organization, helping steer its future. </p>
<p>So it was a very difficult decision for me to leave this behind. Colleagues I’ve come to consider friends and even family.</p>
<p>Now over the last 3 years, I’ve been focused on this “cloud thing”. I went really deep on a technology I feel would help carry my career for the next 5-10yrs and in doing so I achieved some items I never really set out for. I gained the attention and made friends with some REALLY smart people at Microsoft. I’m talking the kinds of people that just when you think you know what you’re talking about show you that you don’t know jack. I also became a Microsoft MVP for Windows Azure. And nobody was as surprised about this as I was. </p>
<p>Over these years, I’ve also learned of opportunities to work even closer with Windows Azure. But the opportunities never felt right, especially with two kids I would really like to see graduate from the same school system they’ve been in since kindergarten. That was until back in June of this year when a position was posted on the Windows Azure ISV Incubation team. I thought long and hard on this, even talked to former Microsoft employees and family. And after weeks of reflection I applied and was ultimately offer the position. </p>
<p>So starting Monday I’m going to join Microsoft as a Technical Evangelist in the US central region. I’m both excited and nervous about this change. Sogeti is a great company to work with and I wouldn’t hesitate to go back for a moment. But I feel that at this time I’ll truly be able to pursue my passion around cloud and maybe in some small way help steer the platform into the bright future I see ahead of it. Not a short term one of “wins” and industry hype. But one that is helping organizations of all sizes build the next generation of applications and solutions. </p>
<p>I’ll still be based in Minneapolis, and still active online and at local/regional events. I do have to set aside my MVP status (which I’d just received for the 3rd time). But honestly, that pales by comparison to stepping away from my role at Sogeti. And I’ll never forget that Sogeti has been the place that most helped me grow and get to where I’m at. So this next new step in my life wouldn’t have been possible without them. </p>
<p>So today, as I look at my surroundings, is a day for mixed emotions. I have hope and excitement about the future. But sadness at the ending, well.. the changing of a great partnership. </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brentdacodemonkey.wordpress.com/468/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brentdacodemonkey.wordpress.com/468/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brentdacodemonkey.wordpress.com&#038;blog=16393590&#038;post=468&#038;subd=brentdacodemonkey&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brentdacodemonkey.wordpress.com/2012/10/12/joining-microsoft/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6b9db6386dfb619649eda05c07f30359?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">brentstineman</media:title>
		</media:content>
	</item>
		<item>
		<title>Cloud Computing News Digest for September 21st, 2012</title>
		<link>http://brentdacodemonkey.wordpress.com/2012/09/21/cloud-computing-news-digest-for-september-21st-2012/</link>
		<comments>http://brentdacodemonkey.wordpress.com/2012/09/21/cloud-computing-news-digest-for-september-21st-2012/#comments</comments>
		<pubDate>Fri, 21 Sep 2012 19:43:04 +0000</pubDate>
		<dc:creator>Brent</dc:creator>
				<category><![CDATA[Cloud Computing]]></category>

		<guid isPermaLink="false">https://brentdacodemonkey.wordpress.com/?p=466</guid>
		<description><![CDATA[I normally publish this over at my Sogeti blog at http://blogs.us.sogeti.com/ccdigest/ but that’s down at the moment so we’re going to my backup copy. I know, the self proclaimed “cloud guy” isn’t in the cloud. Well there’s an old saying that goes something like ‘the cobbler’s children have no shoes’. I’d say I’m late with [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brentdacodemonkey.wordpress.com&#038;blog=16393590&#038;post=466&#038;subd=brentdacodemonkey&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I normally publish this over at my Sogeti blog at <a title="http://blogs.us.sogeti.com/ccdigest/" href="http://blogs.us.sogeti.com/ccdigest/">http://blogs.us.sogeti.com/ccdigest/</a> but that’s down at the moment so we’re going to my backup copy. I know, the self proclaimed “cloud guy” isn’t in the cloud. Well there’s an old saying that goes something like ‘the cobbler’s children have no shoes’. <img style="border-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://brentdacodemonkey.files.wordpress.com/2012/09/wlemoticon-smile.png?w=630" /></p>
<p>I’d say I’m late with this edition but this is developing into enough of a pattern that I think I’m just going to start thinking of monthly as the new weekly J So on to the news…</p>
<p>The Cloud Security Alliance (CSA) and Fujitsu announced the launch of the <a href="http://www.eweek.com/c/a/Data-Storage/Verizon-Fujitsu-Lead-Cloud-Security-Alliance-Big-Data-Working-Group-807920/">Big Data Working Group</a>. The intent of this organization is to help the industry by bringing forth best practices for security and privacy when working with big data. They will start focused on research across several industry verticals with their first report due sometime this fall. </p>
<p>At the 2012 CloudOpen conference this past August, <a href="http://www.zdnet.com/suse-launches-openstack-based-private-cloud-for-enterprises-7000003443/">Suse announced their OpenStack based enterprise level private cloud solution</a> called amazingly enough “Suse Cloud”. This IaaS based solution would help organizations deploy and manage private clouds with self-service and workload standardization capabilities. </p>
<p>I also found <a href="http://searchcloudcomputing.techtarget.com/tip/Deep-dive-into-Eucalyptus-31-open-source-cloud">an article about a competitor to OpenStack, Eucalyptus</a>. SearchCloudComputing has published a “deep dive” into using Eucalpytus 3.1. You’ll need to register as a member (its free) to read the full article</p>
<p>In my job, I’m often asked what skills are needed for cloud. <a href="http://www.forbes.com/sites/joemckendrick/2012/08/27/the-8-most-important-skills-needed-for-cloud-computing-today/">This article by Joe McKendrick</a> does a nice job of covering the list. Not just for individuals, but for organizations as well. </p>
<p>When you talk to cloud vendors, they will eventually reference PEU (Power to Energy Utilization) statistics in some way. But as this piece by David Linthicum over at Toolbox.com explains, the <a href="http://it.toolbox.com/blogs/david-linthicum-cloud/energy-efficiency-of-cloud-computing-misunderstood-52810?reftrk=no">real savings are in the ability to adjust to changing needs and in turn, changing our consumption</a>. </p>
<p>Last month the world watched the 2012 Summer Olympics. And it turns out the cloud played a major hand in helping deliver that content around the globe. <a href="http://weblogs.asp.net/scottgu/archive/2012/08/21/windows-azure-media-services-and-the-london-2012-olympics.aspx">Windows Azure Media Services helped deliver live and on-demand video content to several broadcasters</a>. Eyes weren’t just on the games as Apica, a vendor of testing and monitoring solutions, monitored various Olympics related web sites and <a href="http://blog.apicasystem.com/2012/08/13/olympics-website-performance-2012-top-performers/">scored them for their uptime and performance</a>. </p>
<p>For this edition I also found <a href="http://www.youtube.com/watch?v=Wo-zkUH1R8A">a presentation by Adrian Cockcroft of Netflix on the Cassandra</a> (another noSQL database solution) Performance and Scalability on AWS. Even if you don’t plan to use Cassandra, I highly recommend listen to this and picking up what you can of their approach and learnings. The video lasts about an hour.</p>
<p>Pfizer (the drug…. er… pharmaceutical company), also ventured into the world of <a href="http://www.fiercebiotechit.com/story/pfizer-taps-cloud-computing-gain-control-supply-chain/2012-09-12">cloud computing to help with supply chain issues</a>. If you ever wondered about your critical delivery, what about getting lifesaving medicine to patients.</p>
<p>On the Google front, they haven’t been quite. They recently launched the <a href="http://gigaom.com/cloud/for-its-new-cloud-google-learns-old-tricks/">Google Cloud Partner Program</a>, giving them a way to help promote and leverage delivery partners not unlike the programs already in place at Amazon and Microsoft. </p>
<p>Related to topics that are close to my heart, I have a great article <a href="http://queue.acm.org/detail.cfm?id=2371297">on resilient solution engineering from Jesse Robbins at GameDay</a>. Having all this capacity for disaster recovery and failover doesn’t do us much good if we won’t create solutions that can take advantage of it. And on the subject of architecture, just yesterday I ran across <a href="http://lethain.com/introduction-to-architecting-systems-for-scale/">this great list of items for architectural principles</a> taken from Will Larson’s “Introduction to Architecting Systems for Scale”. Definitely give this a read.</p>
<p>And to close out this edition, I have an info graphics on enterprise cloud adoption. I’m not a big fan of infographics, but <a href="http://www.everestgrp.com/wp-content/uploads/2012/09/enterprise_cloud_adoption_infographic.png">I found this one useful and figured I’d share it with all of you</a>. </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brentdacodemonkey.wordpress.com/466/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brentdacodemonkey.wordpress.com/466/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brentdacodemonkey.wordpress.com&#038;blog=16393590&#038;post=466&#038;subd=brentdacodemonkey&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brentdacodemonkey.wordpress.com/2012/09/21/cloud-computing-news-digest-for-september-21st-2012/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6b9db6386dfb619649eda05c07f30359?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">brentstineman</media:title>
		</media:content>

		<media:content url="http://brentdacodemonkey.files.wordpress.com/2012/09/wlemoticon-smile.png" medium="image">
			<media:title type="html">Smile</media:title>
		</media:content>
	</item>
		<item>
		<title>Avoiding the Chaos Monkey</title>
		<link>http://brentdacodemonkey.wordpress.com/2012/09/07/avoiding-the-chaos-monkey/</link>
		<comments>http://brentdacodemonkey.wordpress.com/2012/09/07/avoiding-the-chaos-monkey/#comments</comments>
		<pubDate>Fri, 07 Sep 2012 21:59:43 +0000</pubDate>
		<dc:creator>Brent</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://brentdacodemonkey.wordpress.com/?p=463</guid>
		<description><![CDATA[Yesterday I was pleased (and nervous) to be presenting at the Heartland Developers Conference in Omaha, NE. I&#8217;ve been hoping to present at this event for a couple years and was really pleased that one of my submissions was accepted. Especially given that the topic was more architect/concept then code. It was only my second [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brentdacodemonkey.wordpress.com&#038;blog=16393590&#038;post=463&#038;subd=brentdacodemonkey&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Yesterday I was pleased (and nervous) to be presenting at the Heartland Developers Conference in Omaha, NE. I&#8217;ve been hoping to present at this event for a couple years and was really pleased that one of my submissions was accepted. Especially given that the topic was more architect/concept then code. It was only my second time presenting this material and the first time for a non-captive audiance. And given that it was the 2pm slot, and only a handful of people fell asleep or left, I&#8217;m pretty pleased with how things went.</p>
<p>I&#8217;ve posted <a href="http://filestore.stinemans.org/codesamples/Presentations/Avoiding%20the%20Chaos%20Monkey.pptx" target="_blank">the deck for my Avoiding the Chaos Monkey presentation</a> so please feel free to take and reuse. I just ask that you give proper credit and I&#8217;d love any feedback on it. I received some great feedback from HDC on the material and will be making some updates that show some real world scenarios and how applying the principles covered in this presentation can address them. I spoke to some of these during the presentation, but agreed with my colleague Eric that it would help to have more concrete and visual examples to drive the message home. I&#8217;ve already submitted the talk to two upcoming conferences and hopefully it will get accepted at one. Meanwhile, feel free to snag a copy and drop me a comment with any feedback you have!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brentdacodemonkey.wordpress.com/463/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brentdacodemonkey.wordpress.com/463/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brentdacodemonkey.wordpress.com&#038;blog=16393590&#038;post=463&#038;subd=brentdacodemonkey&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brentdacodemonkey.wordpress.com/2012/09/07/avoiding-the-chaos-monkey/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6b9db6386dfb619649eda05c07f30359?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">brentstineman</media:title>
		</media:content>
	</item>
		<item>
		<title>You don&#8217;t really want an SLA!</title>
		<link>http://brentdacodemonkey.wordpress.com/2012/09/04/you-dont-really-want-an-sla/</link>
		<comments>http://brentdacodemonkey.wordpress.com/2012/09/04/you-dont-really-want-an-sla/#comments</comments>
		<pubDate>Tue, 04 Sep 2012 16:47:29 +0000</pubDate>
		<dc:creator>Brent</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://brentdacodemonkey.wordpress.com/?p=458</guid>
		<description><![CDATA[I don’t often to editorials (and when I do, they tend to ramble), but I felt I’m due and this is a conversation I’ve been having a lot lately. I sit to talk with clients about cloud and one of the first questions I always get is “what is the SLA”? And I hate it. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brentdacodemonkey.wordpress.com&#038;blog=16393590&#038;post=458&#038;subd=brentdacodemonkey&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I don’t often to editorials (and when I do, they tend to ramble), but I felt I’m due and this is a conversation I’ve been having a lot lately. I sit to talk with clients about cloud and one of the first questions I always get is “what is the SLA”? And I hate it. </p>
<p>The fact is that an SLA is an insurance policy. If your vendor doesn’t provide a basic level of service, you get a check. Not unlike my home owners insurance. If something happens, I get a check. The problem is that most of us NEVER want to have to get that check. If my house burns down, the insurance company will replace it. But all those personal mementos, the memories, the “feel” of the house are gone. So that’s a situation I’d rather avoid. What I REALLY want is safety. So install a fire-alarm, I make sure I have an extinguisher in the kitchen, I keep candles away from drapes. I take measures to help reduce the risk that I’ll need to cash my insurance policy. </p>
<p>When building solutions, we don’t want SLA’s. What we REALLY want is availability. So we as the solution owners need to take steps to help us achieve this. We have to weight the cost vs the benefit (do I need an extinguisher or a sprinkler system?) and determine how much we’re wiling to invest in actively working to achieve our own goals. </p>
<p>This is why when I get asked the question, I usually respond by giving them the answer and immediately jump into a discussion about resiliency. What is a service degradation vs an outage? How can we leverage redundancy? Can we decouple components and absorb service disruptions? These are the types of things we as architects need to start considering, not just for cloud solutions but for everything we build. </p>
<p>I continue to tell developers that the public cloud is a stepping stone. The patterns we’re using in the public cloud are lessons learned that will eventually get applied back on premises. As the private cloud becomes less vapor and more reality, the ability to think in these new patterns is what will make the next generation of apps truly useful. If a server goes down, how quickly does your load balancer see this and take that server out of rotation? How do the servers shift workloads?</p>
<p>When working towards availability, we need to take several things in mind. </p>
<p>Failures will happen – how we deal with them is our choice. We can have the world stop, or we can figure out how to “degrade” our solution to keep anything we can going. </p>
<p>How are we going to recover – when things return to normal, how does the solution “catch up” with what happened during the disruption</p>
<p>the outage is less important than how fast we react – we need to know something has gone wrong before our clients call to tell us</p>
<p>We (aka solution/application architects) really need to start changing the conversation here. We need to steer away from SLA’s entirely and when we can’t manage that at least get to more meaningful, scenario based SLA’s. This can mean instead of saying “the email server will be 99% of the time” we switch to “99% of emails will be transmitted within 5 minutes”. This is much more meaningful for the end users and also gives s more flexibility in how we achieve it. And depending on how traffic. </p>
<p>Anyway, enough rambling for now. I need to get a deck that discusses this ready for a presentation on Thursday that only about 20 minutes ago I realized I needed to do. Fortunately, I have an earlier draft of the session and definitely have the passion and knowhow to make this happen. So time to get cracking!</p>
<p>Until next time!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brentdacodemonkey.wordpress.com/458/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brentdacodemonkey.wordpress.com/458/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brentdacodemonkey.wordpress.com&#038;blog=16393590&#038;post=458&#038;subd=brentdacodemonkey&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brentdacodemonkey.wordpress.com/2012/09/04/you-dont-really-want-an-sla/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6b9db6386dfb619649eda05c07f30359?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">brentstineman</media:title>
		</media:content>
	</item>
		<item>
		<title>Local File Cache in Windows Azure</title>
		<link>http://brentdacodemonkey.wordpress.com/2012/08/02/local-file-cache-in-windows-azure/</link>
		<comments>http://brentdacodemonkey.wordpress.com/2012/08/02/local-file-cache-in-windows-azure/#comments</comments>
		<pubDate>Thu, 02 Aug 2012 17:07:08 +0000</pubDate>
		<dc:creator>Brent</dc:creator>
				<category><![CDATA[Windows Azure]]></category>
		<category><![CDATA[Windows Azure Platform]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[cacheing]]></category>
		<category><![CDATA[local resource]]></category>
		<category><![CDATA[local storage]]></category>
		<category><![CDATA[windows azure]]></category>

		<guid isPermaLink="false">https://brentdacodemonkey.wordpress.com/?p=456</guid>
		<description><![CDATA[When creating a traditional on-premise application, it’s not uncommon to leverage the local file system as a place to store temporary files and thus increase system performance. But with Windows Azure Cloud Services, we’ve been taught that we shouldn’t write things to disk because the virtual machines that host our services aren’t durable. So we [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brentdacodemonkey.wordpress.com&#038;blog=16393590&#038;post=456&#038;subd=brentdacodemonkey&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>When creating a traditional on-premise application, it’s not uncommon to leverage the local file system as a place to store temporary files and thus increase system performance. But with Windows Azure Cloud Services, we’ve been taught that we shouldn’t write things to disk because the virtual machines that host our services aren’t durable. So we start going to remote durable storage for everything. This slows down our applications so we need to add back in some type of cache solution. </p>
<p>Previously, I discussed using the Windows Azure Caching Preview to create a distributed, in-memory cache. I love that we finally have a simple way to do to this. But there are times when I think that caching something, for example an image file that doesn’t change often, within a single instance would be fine, especially if I don’t have to use up precious RAM on my virtual machines.</p>
<p>Well there is an option! Windows Azure Cloud Services all include, at no additional cost, an allocation of non-durable local disk space called surprisingly enough “<a href="http://msdn.microsoft.com/en-us/library/windowsazure/ee758708.aspx">Local Storage</a>”. For each core you get 250gb of essentially temporary disk space. And with a bit of investment, we can leverage that space as a local, file backed cache. </p>
<h3><font color="#646b86">Extending System.Runtime.Caching</font></h3>
<p>So .NET 4.0 introduced the System.Runtime.Caching namespace along with a template base class <a href="http://msdn.microsoft.com/en-us/library/system.runtime.caching.objectcache.aspx">ObjectCache</a> that can be extended to provide caching functionality with whatever storage system we want to use. Now this namespace also provides a concrete implementation called MemoryCache, but we want to use the file system. So we’ll create our own implementation called FileCache class. </p>
<p><strong>Note: </strong>There’s already a <a href="https://fc.codeplex.com/">codeplex project</a> that provides a file based implementation of ObjectCache. But I still wanted to role my own for the sake of explaining some of the challenges that will arise.</p>
<p>So I create a class library and add a reference to System.Runtime.Caching. Next up, let’s rename the default class “Class1.cs” to “FileCache.cs”. Lastly, inside of the FileCache class, I’ll add a using statement for the Caching namespace and make sure my new class inherits from ObjectCache.</p>
<p>Now if we try to build the class library now, things wouldn’t go very well because there are 18 different abstract members we need to implement. Fortunately I’m running the Visual Studio Power Tools so it’s just a matter of right-clicking on ObjectCache where I indicated I’m inheriting from it and selecting the “Implement Abstract Class”. This gives us shells for all 18 abstract members, but until we add some real implementation in, our FileCache class won’t even be minimally useful. </p>
<p>I’ll start by fleshing out the Get method and adding a public property, CacheRootPath, to the class that designates where our file cache will be kept. </p>
<pre class="code"><span style="color:blue;">public string </span>CacheRootPath
{
    <span style="color:blue;">get </span>{ <span style="color:blue;">return </span>cacheRoot.FullName; }
    <span style="color:blue;">set
    </span>{
        cacheRoot = <span style="color:blue;">new </span><span style="color:#2b91af;">DirectoryInfo</span>(<span style="color:blue;">value</span>);
        <span style="color:blue;">if </span>(!cacheRoot.Exists) <span style="color:green;">// create if it doesn't exist
            </span>cacheRoot.Create();
    }
}

<span style="color:blue;">public override bool </span>Contains(<span style="color:blue;">string </span>key, <span style="color:blue;">string </span>regionName = <span style="color:blue;">null</span>)
{
    <span style="color:blue;">string </span>fullFileName = GetItemFileName(key,regionName);
    <span style="color:#2b91af;">FileInfo </span>fileInfo = <span style="color:blue;">null</span>;

    <span style="color:blue;">if </span>(<span style="color:#2b91af;">File</span>.Exists(fullFileName))
    {
        fileInfo = <span style="color:blue;">new </span><span style="color:#2b91af;">FileInfo</span>(fullFileName);

        <span style="color:green;">// if item has expired, don't return it
        //TODO: 
        </span><span style="color:blue;">return true</span>;
    }
    <span style="color:blue;">else
        return false</span>;
}

<span style="color:green;">// return type is an object, but we'll always return a stream
</span><span style="color:blue;">public override object </span>Get(<span style="color:blue;">string </span>key, <span style="color:blue;">string </span>regionName = <span style="color:blue;">null</span>)
{
    <span style="color:blue;">if </span>(Contains(key, regionName))
    {
        <span style="color:green;">//TODO: wrap this in some exception handling
        </span><span style="color:#2b91af;">MemoryStream </span>memStream = <span style="color:blue;">new </span><span style="color:#2b91af;">MemoryStream</span>();
        <span style="color:#2b91af;">FileStream </span>fileStream = <span style="color:blue;">new </span><span style="color:#2b91af;">FileStream</span>(GetItemFileName(key, regionName), <span style="color:#2b91af;">FileMode</span>.Open);
        fileStream.CopyTo(memStream);
        fileStream.Close();

        <span style="color:blue;">return </span>memStream;
    }
    <span style="color:blue;">else
        return null</span>;
}</pre>
<p>CacheRootPath is just a way for us to set the path to where our cache will be stored. The <a href="http://msdn.microsoft.com/en-us/library/system.runtime.caching.objectcache.contains.aspx">Contains</a> method is a way to check and see if the file exists in the cache (and ideally should also be where we check to make sure the object isn’t expired), and the <a href="http://msdn.microsoft.com/en-us/library/system.runtime.caching.objectcache.get.aspx">Get</a> method leverages Contains to see if the item exists in the cache and retrieves it if it exists.</p>
<p>Now this is where I had my fist real decision to make. Get must return an object, but what type of object should I return. In my case I opted to return a memory stream.&#160; Now I could have returned a file stream that was attached to the file on disk, but because this could lock access to file, I wanted to have explicit control of that stream. Hence I opted to copy the file stream to a memory stream and return that to the caller.</p>
<p>You may also note that I left the expiration check alone. I did this for the demo because your needs for file expiration may differ. You could base this on <a href="http://msdn.microsoft.com/en-us/library/system.io.filesysteminfo.creationtimeutc.aspx">FileInfo.CreationTimeUTC</a>, or <a href="http://msdn.microsoft.com/en-us/library/system.io.filesysteminfo.lastaccesstimeutc.aspx">FileInfo.LastAccessTimeUTC</a>. both are valid as may be any other meta data you need to base it on. I do recommend one thing, make a separate method that does the expiration check. We will use it later. </p>
<p><strong>Note: </strong>I’m specifically calling out the use of UTC. When in Windows Azure, UTC is your friend. Try to use it whenever possible. </p>
<p>Next up, we have to shell out the three overloaded versions of <a href="http://msdn.microsoft.com/en-us/library/dd988724.aspx">AddOrGetExisting</a>. These methods are important because even though I won’t be directly accessing them in my implementation, they are leveraged by base cass <a href="http://msdn.microsoft.com/en-us/library/dd780614.aspx">Add</a> method. And thus, these methods are how we add items into the cache. The first two overloaded methods will call the lowest level implementation.</p>
<pre style="width:630px;height:342px;" class="code"><span style="color:blue;">public override object </span>AddOrGetExisting(<span style="color:blue;">string </span>key, <span style="color:blue;">object </span>value, <span style="color:#2b91af;">CacheItemPolicy </span>policy, <span style="color:blue;">string </span>regionName = <span style="color:blue;">null</span>)
{
    <span style="color:blue;">if </span>(!(value <span style="color:blue;">is </span><span style="color:#2b91af;">Stream</span>))
        <span style="color:blue;">throw new </span><span style="color:#2b91af;">ArgumentException</span>(<span style="color:#a31515;">&quot;value parameter is not of type Stream&quot;</span>);

    <span style="color:blue;">return this</span>.AddOrGetExisting(key, value, policy.AbsoluteExpiration, regionName);
}

<span style="color:blue;">public override </span><span style="color:#2b91af;">CacheItem </span>AddOrGetExisting(<span style="color:#2b91af;">CacheItem </span>value, <span style="color:#2b91af;">CacheItemPolicy </span>policy)
{
    <span style="color:blue;">var </span>tmpValue = <span style="color:blue;">this</span>.AddOrGetExisting(value.Key, value.Value, policy.AbsoluteExpiration, value.RegionName);
    <span style="color:blue;">if </span>(tmpValue != <span style="color:blue;">null</span>)
        <span style="color:blue;">return new </span><span style="color:#2b91af;">CacheItem</span>(value.Key, (<span style="color:#2b91af;">Stream</span>)tmpValue);
    <span style="color:blue;">else
        return null</span>;
}</pre>
<p>The key item to note here is that in the first method, I do a check on the object to make sure I’m receiving a stream. Again, that was my design choice since I want to deal with the streams. </p>
<p>The final overload is where all the heavy work is…</p>
<pre style="width:630px;height:564px;" class="code"><span style="color:blue;">public override object </span>AddOrGetExisting(<span style="color:blue;">string </span>key, <span style="color:blue;">object </span>value, <span style="color:#2b91af;">DateTimeOffset </span>absoluteExpiration, <span style="color:blue;">string </span>regionName = <span style="color:blue;">null</span>)
{
    <span style="color:blue;">if </span>(!(value <span style="color:blue;">is </span><span style="color:#2b91af;">Stream</span>))
        <span style="color:blue;">throw new </span><span style="color:#2b91af;">ArgumentException</span>(<span style="color:#a31515;">&quot;value parameter is not of type Stream&quot;</span>);

    <span style="color:green;">// if object exists, get it
    </span><span style="color:blue;">object </span>tmpValue = <span style="color:blue;">this</span>.Get(key, regionName);
    <span style="color:blue;">if </span>(tmpValue != <span style="color:blue;">null</span>)
        <span style="color:blue;">return </span>tmpValue;
    <span style="color:blue;">else
    </span>{
        <span style="color:green;">//TODO: wrap this in some exception handling

        // create subfolder for region if it was specified
        </span><span style="color:blue;">if </span>(regionName != <span style="color:blue;">null</span>)
            cacheRoot.CreateSubdirectory(regionName);

        <span style="color:green;">// add object to cache
        </span><span style="color:#2b91af;">FileStream </span>fileStream = <span style="color:#2b91af;">File</span>.Open(GetItemFileName(key, regionName), <span style="color:#2b91af;">FileMode</span>.Create);

        ((<span style="color:#2b91af;">Stream</span>)value).CopyTo(fileStream);
        fileStream.Flush();
        fileStream.Close();

        <span style="color:blue;">return null</span>; <span style="color:green;">// successfully added
    </span>}
}</pre>
<p>We start by checking to see if the object already exists and return it if found in the cache. Then we create a subdirectory if we have a region (region implementation isn’t required). Finally, we copy the value passed in to our file and save it. There really should be some exception handling in here to make sure we’re handling things in a way that’s a little more thread save (what if the file gets created between when we check for it and start the write). And the get should be checking to make sure the file isn’t already open when doing its read. But I’m sure you can finish that out. </p>
<p>Now there’s still about a dozen other methods that need to be fleshed out eventually. But these give us our basic get and add functions. What’s still missing is handling evictions from the cache. For that we’re going to use a <a href="http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx">timer</a>. </p>
<pre style="width:630px;height:352px;" class="code"><span style="color:blue;">public </span>FileCache() : <span style="color:blue;">base</span>()
{
    System.Threading.<span style="color:#2b91af;">TimerCallback </span>TimerDelegate = <span style="color:blue;">new </span>System.Threading.<span style="color:#2b91af;">TimerCallback</span>(TimerTask);

    <span style="color:green;">// time values should be based on polling interval
    </span>timerItem = <span style="color:blue;">new </span>System.Threading.<span style="color:#2b91af;">Timer</span>(TimerDelegate, <span style="color:blue;">null</span>, 2000, 2000);
}

<span style="color:blue;">private void </span>TimerTask(<span style="color:blue;">object </span>StateObj)
{
    <span style="color:blue;">int </span>a = 1;
    <span style="color:green;">// check file system for size and if over, remove older objects


    //TODO: check polling interval and update timer if its changed
</span>}</pre>
<p>We’ll update the FileCache constructor to create a delegate using our new TimerTask method, and pass that into a Timer object. This will execute the TimeTask method and regular intervals in a separate thread. I’m using a hard-coded value, but we really should check to see we have a specific polling interval set. Course we should also put some code into this method so it actually does things like check to see how much room we have in the cache and evict expired items(by checking via the private method I suggested earlier), etc… </p>
<h3><font color="#646b86">The Implementation</font></h3>
<p>With our custom caching class done (well not done but at least to a point where its minimally functional), its time to implement it. For this, I opted to setup an MVC Web Role that allows folks to upload an image file to Windows Azure Blob storage. Then, via a WCF/REST based service, it would retrieve the images twice. The first retrieval would be without using caching, the second would be with caching. I won’t bore you with all the details of this setup, so we’ll focus on just the wiring up of our custom FileCache. </p>
<p>We start appropriately enough with the role’s Global.asax.cs file where we add public property that represents out cache (so its available anywhere in the web application):</p>
<pre class="code"><span style="color:blue;">public static </span>Caching.<span style="color:#2b91af;">FileCache </span>globalFileCache = <span style="color:blue;">new </span>Caching.<span style="color:#2b91af;">FileCache</span>();</pre>
<p>And then I update the Application_Start method to retrieve our LocalResource setting and use it to set the CacheRootPath property of our caching object. </p>
<pre style="width:630px;height:319px;" class="code"><span style="color:blue;">protected void </span>Application_Start()
{
    <span style="color:#2b91af;">AreaRegistration</span>.RegisterAllAreas();

    RegisterGlobalFilters(<span style="color:#2b91af;">GlobalFilters</span>.Filters);
    RegisterRoutes(<span style="color:#2b91af;">RouteTable</span>.Routes);

    Microsoft.WindowsAzure.<span style="color:#2b91af;">CloudStorageAccount</span>.SetConfigurationSettingPublisher(
        (configName, configSetter) =&gt;
            configSetter(<span style="color:#2b91af;">RoleEnvironment</span>.GetConfigurationSettingValue(configName))
    );

    globalFileCache.CacheRootPath = <span style="color:#2b91af;">RoleEnvironment</span>.GetLocalResource(<span style="color:#a31515;">&quot;filecache&quot;</span>).RootPath;
}</pre>
<p>Now ideally we could make it so that the CacheRootPath instead accepted the LocalResource object returned by GetLocalResource. This would then also mean that our FileCache could easily manage against the maximum size of the local storage resource. But I figured we’d keep any Windows Azure specific dependencies out of this base class and maybe later look at creating a WindowsAzureLocalResourceCache object. But that’s a task for another day. </p>
<p>Ok, now to wire up the cache into the service that will retrieve the blobs. Lets start with the basic implementation:</p>
<pre class="code"><span style="color:blue;">public </span><span style="color:#2b91af;">Stream </span>GetImage(<span style="color:blue;">string </span>Name, <span style="color:blue;">string </span>container, <span style="color:blue;">bool </span>useCache)
{
    <span style="color:#2b91af;">Stream </span>tmpStream = <span style="color:blue;">null</span>; <span style="color:green;">// could end up being a filestream or a memory stream

    </span><span style="color:blue;">var </span>account = <span style="color:#2b91af;">CloudStorageAccount</span>.FromConfigurationSetting(<span style="color:#a31515;">&quot;ImageStorage&quot;</span>); 
    <span style="color:#2b91af;">CloudBlobClient </span>blobStorage = account.CreateCloudBlobClient();
    <span style="color:#2b91af;">CloudBlob </span>blob = blobStorage.GetBlobReference(<span style="color:blue;">string</span>.Format(<span style="color:#a31515;">@&quot;{0}/{1}&quot;</span>, container, Name));
    tmpStream = <span style="color:blue;">new </span><span style="color:#2b91af;">MemoryStream</span>();
    blob.DownloadToStream(tmpStream);

    <span style="color:#2b91af;">WebOperationContext</span>.Current.OutgoingResponse.ContentType = <span style="color:#a31515;">&quot;image/jpeg&quot;</span>;
    tmpStream.Seek(0, 0); <span style="color:green;">// make sure we start the beginning
    </span><span style="color:blue;">return </span>tmpStream;
}</pre>
<p>This method takes the name of a blob and its container, as well as a useCache parameter (which we’ll implement in a moment). It uses the first two values to get the blob and download it to a stream which is then returned to the caller with a content type of “image/jpeg” so it can be rendered by the browser properly. </p>
<p>To implement our cache we just need to add a few things. Before we try to set up the CloudStorageAccount, we’ll add these lines:</p>
<pre class="code"><span style="color:green;">// if we're using the cache, lets try to get the file from there
</span><span style="color:blue;">if </span>(useCache)
    tmpStream = (<span style="color:#2b91af;">Stream</span>)<span style="color:#2b91af;">MvcApplication</span>.globalFileCache.Get(Name);

<span style="color:blue;">if </span>(tmpStream == <span style="color:blue;">null</span>)
{</pre>
<p>This code tries to use the globalFileCache object we defined n the Global.asax.cs file and retrieve the blob from the cache if it exists, providing we told the method useCache=true. If we couldn’t find the file (tmpStream == null), we’ll then fall into the block we had previously that will retrieve the blob image and return it. </p>
<p>But we still have to add in the code to add the blob to the cache. We’ll do right after we DownloadToStream:</p>
<pre style="width:630px;height:219px;" class="code">    <span style="color:green;">// &quot;fork off&quot; the adding of the object to the cache so we don't have to wait for this
    </span><span style="color:#2b91af;">Task </span>tsk = <span style="color:#2b91af;">Task</span>.Factory.StartNew(() =&gt;
    {
        <span style="color:#2b91af;">Stream </span>saveStream = <span style="color:blue;">new </span><span style="color:#2b91af;">MemoryStream</span>();
        blob.DownloadToStream(saveStream);
        saveStream.Seek(0, 0); <span style="color:green;">// make sure we start the beginning
        </span><span style="color:#2b91af;">MvcApplication</span>.globalFileCache.Add(Name, saveStream, <span style="color:blue;">new </span><span style="color:#2b91af;">DateTimeOffset</span>(<span style="color:#2b91af;">DateTime</span>.Now.AddHours(1)));
    });
}</pre>
<p>This uses an async <a href="http://msdn.microsoft.com/en-us/library/system.threading.tasks.task.aspx">task</a> to add the blob to the cache. We do this with asynchronously so that we don’t block returning the blob back to the requestor while the write to disk completes. We want this service to return the file back as quickly as possible. </p>
<p>And that does it for our implementation. Now to testing it.</p>
<h3><font color="#646b86">Fiddler is your friend</font></h3>
<p>Earlier, you may have found yourself saying “self, why did he use a service for his implementation”. I did this because I wanted to use <a href="http://www.fiddler2.com/fiddler2/">Fiddler</a> to measure the performance of calls to retrieve the blob with and without caching. And by putting it in a service and letting fiddler monitor the response times, I didn’t have to write up my own client and put timings around it. </p>
<p>To test my implementation, I fired up fiddler and then launched the service. We should see calls in Fiddler to SimpleService.svc/GetImage, one with cache=false and one with cache=true. If we select those items, and select the Statistics tab, we should see some significant differences in the “Overall Elapsed” times of each call. In my little tests, I was seeing anywhere from a 50-90% reduction in the elapsed time. </p>
<p><a href="http://brentdacodemonkey.files.wordpress.com/2012/08/image.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://brentdacodemonkey.files.wordpress.com/2012/08/image_thumb.png?w=624&#038;h=63" width="624" height="63" /></a></p>
<p>In fact, if you run the tests several times by hitting refresh on the page, you may even notice that the first time you hit Windows Azure storage for a particular blob, you may have additional delay compare to subsequent calls. Its only a guess but we may be seeing Windows Azure storage doing some of its own internal caching there.</p>
<p>So hopefully I’ve described things well enough here and you can follow what we’ve done. But if not, <a href="https://bmspublic.blob.core.windows.net/codesamples/CachingDemo.zip">I’m posting the code for you to reuse</a>. Just make sure you update the storage account settings and please please please finish the half started implementation I’m providing you. </p>
<p>Here’s to speedy responses thanks to caching. Until next time. </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brentdacodemonkey.wordpress.com/456/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brentdacodemonkey.wordpress.com/456/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brentdacodemonkey.wordpress.com&#038;blog=16393590&#038;post=456&#038;subd=brentdacodemonkey&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brentdacodemonkey.wordpress.com/2012/08/02/local-file-cache-in-windows-azure/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6b9db6386dfb619649eda05c07f30359?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">brentstineman</media:title>
		</media:content>

		<media:content url="http://brentdacodemonkey.files.wordpress.com/2012/08/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>The &#8220;traffic cop&#8221; pattern</title>
		<link>http://brentdacodemonkey.wordpress.com/2012/07/27/the-traffic-cop-pattern/</link>
		<comments>http://brentdacodemonkey.wordpress.com/2012/07/27/the-traffic-cop-pattern/#comments</comments>
		<pubDate>Sat, 28 Jul 2012 01:57:34 +0000</pubDate>
		<dc:creator>Brent</dc:creator>
				<category><![CDATA[Windows Azure Platform]]></category>
		<category><![CDATA[Azure Storage]]></category>

		<guid isPermaLink="false">https://brentdacodemonkey.wordpress.com/?p=451</guid>
		<description><![CDATA[So I like design patterns but don’t follow them closely. Problem is that there are too many names and its just so darn hard to find them. But one “pattern” I keep seeing an ask for is the ability to having something that only runs once across a group of Windows Azure instances. This can [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brentdacodemonkey.wordpress.com&#038;blog=16393590&#038;post=451&#038;subd=brentdacodemonkey&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>So I like design patterns but don’t follow them closely. Problem is that there are too many names and its just so darn hard to find them. But one “pattern” I keep seeing an ask for is the ability to having something that only runs once across a group of Windows Azure instances. This can surface as one-time startup task or it could be the need to have something that run constantly and if one instance fails, another can realize this and pick up the work. </p>
<p>This later example is often referred to as a “self-electing controller”. At the root of this is a pattern I’ve taken to calling a “traffic cop”. This mini-pattern involves having a unique resource that can be locked, and the process that gets the lock has the right of way. Hence the term “traffic cop”. In the past, aka my “mainframe days”, I used this with systems where I might be processing work in parallel and needed to make sure that a sensitive block of code could prevent a parallel process from executing it while it was already in progress. Critical when you have apps that are doing things like self-incrementing unique keys. </p>
<p>In Windows Azure, the most common way to do this is to use a Windows Azure Storage blob lease. You’d think this comes up often enough that there’d be a post on how to do it already, but I’ve never really run across one. That is until today. Keep reading!</p>
<p>But before I dig into the meat of this, a couple footnotes&#8230; First is a shout out to my buddy Neil over at the <a href="http://convective.wordpress.com/">Convective blob</a>. I used <a href="http://www.packtpub.com/microsoft-windows-azure-development-cookbook/book">Neil’s Azure Cookbook</a> for help me with the blob leasing stuff. You can never have too many reference books in your Kindle library. Secondly, the <a href="http://blogs.msdn.com/b/windowsazurestorage/archive/2012/06/12/new-blob-lease-features-infinite-leases-smaller-lease-times-and-more.aspx">Windows Azure Storage team is already working on some enhancements for the next Windows Azure .NET SDK</a> that will give us some more ‘native’ ways of doing blob leases. These include taking advantage of the newest features of the <a href="http://msdn.microsoft.com/en-us/library/windowsazure/gg441573.aspx">2012-02-12</a> storage features. So the leasing techniques I have below may change in an upcoming SDK. </p>
<h3><font color="#646b86"><font>Blob based Traffic Cop</font></font></h3>
<p>Because I want to get something that works for Windows Azure Cloud Services, I’m going to implement my traffic cop using a blob. But if you wanted to do this on-premises, you could just as easily get an exclusive lock on a file on a shared drive. So we’ll start by creating a new Cloud Service, add a worker role to it, and then add a public class to the worker role called “BlobTrafficCop”. </p>
<p>Shell this class out with a constructor that takes a <a href="http://msdn.microsoft.com/en-us/library/windowsazure/microsoft.windowsazure.storageclient.cloudpageblob.aspx">CloudPageBlob</a>, a property that we can test to see if we have control, and methods to Start and Stop control. This shell should look kind of like this:</p>
<pre class="code"><span style="color:blue;">class </span><span style="color:#2b91af;">BlobTrafficCop
</span>{
    <span style="color:blue;">public </span>BlobTrafficCop(<span style="color:#2b91af;">CloudPageBlob </span>blob)
    {
    }

    <span style="color:blue;">public bool </span>HasControl
    {
        <span style="color:blue;">get
        </span>{
            <span style="color:blue;">return true</span>;
        }
    }

    <span style="color:blue;">public void </span>Start(<span style="color:#2b91af;">TimeSpan </span>pollingInterval)
    {
    }

    <span style="color:blue;">public void </span>Stop()
    {
    }
}</pre>
<p>Note that I’m using a CloudPageBlob. I specifically chose this over a block blob because I wanted to call out something. We could create a 1tb page blob and won’t be charged for 1 byte of storage unless we put something into it. In this demo, we won’t be storing anything so I can create a million of these traffic cops and will only incur bandwidth and transaction charges. Now the amount I’m saving here isn’t even significant enough to be a rounding error. So just note this down as a piece of trivia you may want to use some day. It should also be noted that the size you set in the call to the Create method is arbitrary but MUST be a multiple of 512 (the size of a page). If you set it to anything that’s not a multiple of 512, you’ll receive an invalid argument exception. </p>
<p>I’ll start putting some buts into this by doing a null argument check in my constructor and also saving the parameter to a private variable. The real work starts when I create three private helper methods to work with the blob lease. GetLease, RenewLease, and ReleaseLease.</p>
<p>GetLease has two parts, setting up the blob, and then acquiring the lease. Here’s how I go about creating the blob using the CloudPageBlob object that was handed in:</p>
<pre class="code"><span style="color:blue;">try
</span>{
    myBlob.Create(512);
}
<span style="color:blue;">catch </span>(<span style="color:#2b91af;">StorageClientException </span>ex)
{
    <span style="color:green;">// conditionfailed will occur if there's already a lease on the blob
    </span><span style="color:blue;">if </span>(ex.ErrorCode != <span style="color:#2b91af;">StorageErrorCode</span>.ConditionFailed)
    {
        myLeaseID = <span style="color:blue;">string</span>.Empty;
        <span style="color:blue;">throw </span>ex; <span style="color:green;">// re-throw exception
    </span>}
}</pre>
<p>Now admittedly, this does require another round trip to WAS, so as a general rule, I’d make sure the blob was created when I deploy the solution and not each time I try to get a lease on it. But this is a demo and we want to make running it as simple as possible. So we’re putting this in. I’m trapping for a <a href="http://msdn.microsoft.com/en-us/library/windowsazure/microsoft.windowsazure.storageclient.storageexception.aspx">StorageClientExcpetion</a> with a specific error code of <a href="http://msdn.microsoft.com/en-us/library/windowsazure/microsoft.windowsazure.storageclient.storageerrorcode.aspx">ConditionFailed</a>. This is what you will see if you issue the Create method against a blob that has an active lease on it. So we’re handing that situation. I’ll get to myLeaseID here in a moment. </p>
<p>The next block creates a web request to lease the blob and tries to get that lease. </p>
<pre class="code"><span style="color:blue;">try
</span>{
    <span style="color:#2b91af;">HttpWebRequest </span>getRequest = <span style="color:#2b91af;">BlobRequest</span>.Lease(myBlob.Uri, 30, <span style="color:#2b91af;">LeaseAction</span>.Acquire, <span style="color:blue;">null</span>);
    myBlob.Container.ServiceClient.Credentials.SignRequest(getRequest);
    <span style="color:blue;">using </span>(<span style="color:#2b91af;">HttpWebResponse </span>response = getRequest.GetResponse() <span style="color:blue;">as </span><span style="color:#2b91af;">HttpWebResponse</span>)
    {
        myLeaseID = response.Headers[<span style="color:#a31515;">&quot;x-ms-lease-id&quot;</span>];
    }
}
<span style="color:blue;">catch </span>(System.Net.<span style="color:#2b91af;">WebException</span>)
{
    <span style="color:green;">// this will be thrown by GetResponse if theres already a lease on the blob
    </span>myLeaseID = <span style="color:blue;">string</span>.Empty;
}</pre>
<p>  BlobRequest.lease will give me a template <a href="http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx">HttpWebRequest</a> for the least. I then use the blob I received in the constructor to sign the request, and finally I execute the request and get its response. If things go well, I’ll get a response back and it will have a header with the id for the lease which I’ll put into a private variable (the myLeaseID from earlier) which I can use later when I need to renew the lease. I also trap for a <a href="http://msdn.microsoft.com/en-us/library/system.net.webexception.aspx">WebException</a> which will be thrown if my attempt to get a lease fails because there’s already a lease on the blob. </p>
<p>RenewLease and ReleaseLease are both much simpler. Renew creates a request object, signs and executes it just like we did before. We’ve just changed the LeaseAction to Renew.</p>
<pre class="code"><span style="color:#2b91af;">HttpWebRequest </span>renewRequest = <span style="color:#2b91af;">BlobRequest</span>.Lease(myBlob.Uri, 30, <span style="color:#2b91af;">LeaseAction</span>.Renew, myLeaseID);
myBlob.Container.ServiceClient.Credentials.SignRequest(renewRequest);
<span style="color:blue;">using </span>(<span style="color:#2b91af;">HttpWebResponse </span>response = renewRequest.GetResponse() <span style="color:blue;">as </span><span style="color:#2b91af;">HttpWebResponse</span>)
{
    myLeaseID = response.Headers[<span style="color:#a31515;">&quot;x-ms-lease-id&quot;</span>];
}</pre>
<p>ReleaseLease is just a bit more complicated because we check the status code to make sure we released the lease properly. But again its mainly just creating the request and executing it, this time with the LeaseAction of Release. </p>
<pre class="code"><span style="color:#2b91af;">HttpWebRequest </span>releaseRequest = <span style="color:#2b91af;">BlobRequest</span>.Lease(myBlob.Uri, 30, <span style="color:#2b91af;">LeaseAction</span>.Release, myLeaseID);
myBlob.Container.ServiceClient.Credentials.SignRequest(releaseRequest);
<span style="color:blue;">using </span>(<span style="color:#2b91af;">HttpWebResponse </span>response = releaseRequest.GetResponse() <span style="color:blue;">as </span><span style="color:#2b91af;">HttpWebResponse</span>)
{
    <span style="color:#2b91af;">HttpStatusCode </span>httpStatusCode = response.StatusCode;
    <span style="color:blue;">if </span>(httpStatusCode == <span style="color:#2b91af;">HttpStatusCode</span>.OK)
        myLeaseID = <span style="color:blue;">string</span>.Empty;
}</pre>
<p>Ideally, I’d have liked to do a bit more testing of these to make sure there weren’t any additional exceptions I should handle. But I’m short on time so I’ll leave that for another day.</p>
<h3><font color="#646b86">Starting and Stopping</font></h3>
<p>Blob leases expire after an interval if they are not renewed. So its important that I have a process that regularly renews the lease, and another that will check to see to see if I can get the lease if I don’t already have it. To that end, I’m going to use <a href="http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx">System.Threading.Timer</a> objects with a single delegate called TimerTask. This delegate is fairly simple, so we’ll start there. </p>
<pre class="code"><span style="color:blue;">private void </span>TimerTask(<span style="color:blue;">object </span>StateObj)
{
    <span style="color:green;">// if we have control, renew the lease
    </span><span style="color:blue;">if </span>(<span style="color:blue;">this</span>.HasControl)
        RenewLease();
    <span style="color:blue;">else </span><span style="color:green;">// we don't have control
        // try to get lease
        </span>GetLease();

    renewalTimer.Change((<span style="color:blue;">this</span>.HasControl ? <span style="color:#2b91af;">TimeSpan</span>.FromSeconds(45) : <span style="color:#2b91af;">TimeSpan</span>.FromMilliseconds(-1)), <span style="color:#2b91af;">TimeSpan</span>.FromSeconds(45));
    pollingTimer.Change((!<span style="color:blue;">this</span>.HasControl ? myPollingInterval : <span style="color:#2b91af;">TimeSpan</span>.FromMilliseconds(-1)), <span style="color:#2b91af;">TimeSpan</span>.FromSeconds(45));
}</pre>
<p>We start by checking that HasControl property we created in our shell. This property just checks to see if myLeaseID is a string with a length &gt; 0.&#160; If so, then we need to renew our lease. If not, then we need to try and acquire the lease. I then change the intervals on two System.Threading.Timer objects (we’ll set them up next), renewalTimer and pollingTimer. Both are private variables of our class. </p>
<p>If we have control, then the renewal timer will be set to fire again in 45 seconds(15 seconds before our lease expires), and continue to fire every 45 seconds after that. If we don’t have control, renewal will stop checking. pollingTimer works in reverse, polling if we don’t have a lease, and stopping when we do. I’m using two separate timers because the renewal timer needs to fire every minute if I’m to keep control. But the process that’s leveraging may want to control the interval at which we poll for control, so I want that on a separate timer. </p>
<p>Now lets start our traffic cop:</p>
<pre class="code"><span style="color:blue;">public void </span>Start(<span style="color:#2b91af;">TimeSpan </span>pollingInterval)
{
    <span style="color:blue;">if </span>(<span style="color:blue;">this</span>.IsRunning)
        <span style="color:blue;">throw new </span><span style="color:#2b91af;">InvalidOperationException</span>(<span style="color:#a31515;">&quot;This traffic cop is already active. You must call 'stop' first.&quot;</span>);

    <span style="color:blue;">this</span>.IsRunning = <span style="color:blue;">true</span>;

    myPollingInterval = pollingInterval;

    System.Threading.<span style="color:#2b91af;">TimerCallback </span>TimerDelegate = <span style="color:blue;">new </span>System.Threading.<span style="color:#2b91af;">TimerCallback</span>(TimerTask);

    <span style="color:green;">// start polling immediately for control
    </span>pollingTimer = <span style="color:blue;">new </span>System.Threading.<span style="color:#2b91af;">Timer</span>(TimerDelegate, <span style="color:blue;">null</span>, <span style="color:#2b91af;">TimeSpan</span>.FromMilliseconds(0), myPollingInterval);
    <span style="color:green;">// don't do any renewal polling
    </span>renewalTimer = <span style="color:blue;">new </span>System.Threading.<span style="color:#2b91af;">Timer</span>(TimerDelegate, <span style="color:blue;">null</span>, <span style="color:#2b91af;">TimeSpan</span>.FromMilliseconds(-1), <span style="color:#2b91af;">TimeSpan</span>.FromSeconds(45));
}</pre>
<p>We do a quick check to make sure we’re not already running, then set a flag to say we are (just a private boolean flag). I save off the control polling interval that was passed in and set up a TimerDelegate using the TimerTask method we set up a moment before. Now it’s just a matter of creating our Timers. </p>
<p>The polling timer will start immediately and fire again at the interval the calling process set. The renewal timer, since we’re just starting out attempts to get control, will not start, but will be set up to check every 45 seconds so we’re ready to renew the lease once we get it. </p>
<p>When we call the start method, it essentially causes our polling timer to fire immediately (asyncronously). So when TaskTimer is executed by that timer, HasControl will be false and we’ll try to get a lease. If we succeed, the polling timer will be stopped and the renewal timer will be activated. </p>
<p>Now to stop traffic:</p>
<pre class="code"><span style="color:blue;">public void </span>Stop()
{
    <span style="color:green;">// stop lease renewal
    </span><span style="color:blue;">if </span>(renewalTimer != <span style="color:blue;">null</span>)
        renewalTimer.Change(<span style="color:#2b91af;">TimeSpan</span>.FromMilliseconds(-1), <span style="color:#2b91af;">TimeSpan</span>.FromSeconds(45));
    <span style="color:green;">// start polling for new lease
    </span><span style="color:blue;">if </span>(pollingTimer != <span style="color:blue;">null</span>)
        pollingTimer.Change(<span style="color:#2b91af;">TimeSpan</span>.FromMilliseconds(-1), myPollingInterval);

    <span style="color:green;">// release a lease if we have one
    </span><span style="color:blue;">if </span>(<span style="color:blue;">this</span>.HasControl)
        ReleaseLease();

    <span style="color:blue;">this</span>.IsRunning = <span style="color:blue;">false</span>;
}</pre>
<p>We’ll stop and dispose of both timers,&#160; release any locks we have, and then reset our boolean “IsRunning” flag.</p>
<p>And that’s the basics of our TrafficCop class. Now for implementation….</p>
<h3><font color="#646b86">Controlling the flow of traffic</font></h3>
<p>Now the point of this is to give us a way to control when completely unrelated processes can perform an action. So let’s flip over to the WorkerRole.cs file and put some code to leverage the traffic copy into its Run method. We’ll start by creating an instance of the CloudPageBlog object that will be our lockable object and passed into our TrafficCop class. </p>
<p><pre class="code"><span style="color:blue;">var </span>account = <span style="color:#2b91af;">CloudStorageAccount</span>.FromConfigurationSetting(<span style="color:#a31515;">&quot;TrafficStorage&quot;</span>);

<span style="color:green;">// create blob client
</span><span style="color:#2b91af;">CloudBlobClient </span>blobStorage = account.CreateCloudBlobClient();
<span style="color:#2b91af;">CloudBlobContainer </span>container = blobStorage.GetContainerReference(<span style="color:#a31515;">&quot;trafficcopdemo&quot;</span>);
container.CreateIfNotExist(); <span style="color:green;">// adding this for safety

// use a page blog, if its empty, there's no storage costs
</span><span style="color:#2b91af;">CloudPageBlob </span>pageBlob = container.GetPageBlobReference(<span style="color:#a31515;">&quot;singleton&quot;</span>);</pre>
</p>
<p>This creates an object, but doesn’t actually create the blob. I made the conscious decision to go this route and keep any need for the TrafficCop class to have to directly manage storage credentials or the container out of things. Your individual needs may vary. The nice thing is that once this is done, starting the cop is a VERY simple process:</p>
<pre class="code">myTrafficCop = <span style="color:blue;">new </span><span style="color:#2b91af;">BlobTrafficCop</span>(pageBlob);
myTrafficCop.Start(<span style="color:#2b91af;">TimeSpan</span>.FromSeconds(60));</pre>
<p>So this will tell the copy to use a blob called “singleton” in the blob container “trafficcopdemo” as our controlling process and to check for control every 30 seconds. But that’s not really interesting. If we ran this with two instances, what we’d see is that one instance would get control and keep it until something went wrong with getting the lease. So I want to alter the infinite loop of this worker role so&#160; I can see the cop is doing its job and also that I can pass control back and forth. </p>
<p>So I’m going to alter the default loop so that it will sleep for 15 seconds every loop and each time through will write a message to the console that it either does or does not have control. Finally, I’ll use a counter so that if an instance has control, it will only keep control for 75 seconds then release it. </p>
<pre class="code"><span style="color:blue;">int </span>controlcount = 0;
<span style="color:blue;">while </span>(<span style="color:blue;">true</span>)
{
    <span style="color:blue;">if </span>(!myTrafficCop.IsRunning)
        myTrafficCop.Start(<span style="color:#2b91af;">TimeSpan</span>.FromSeconds(30));

    <span style="color:blue;">if </span>(myTrafficCop.HasControl)
    {
        <span style="color:#2b91af;">Trace</span>.WriteLine(<span style="color:blue;">string</span>.Format(<span style="color:#a31515;">&quot;Have Control: {0}&quot;</span>, controlcount.ToString()), <span style="color:#a31515;">&quot;TRAFFICCOP&quot;</span>);
        controlcount++;
    }
    <span style="color:blue;">else
        </span><span style="color:#2b91af;">Trace</span>.WriteLine(<span style="color:#a31515;">&quot;Don't Have Control&quot;</span>, <span style="color:#a31515;">&quot;TRAFFICCOP&quot;</span>);

    <span style="color:blue;">if </span>(controlcount &gt;= 4)
    {
        myTrafficCop.Stop();
        controlcount = 0;
        <span style="color:#2b91af;">Thread</span>.Sleep(<span style="color:#2b91af;">TimeSpan</span>.FromSeconds(15));
    }

    <span style="color:#2b91af;">Thread</span>.Sleep(<span style="color:#2b91af;">TimeSpan</span>.FromSeconds(15));
}</pre>
<p>Not the prettiest code I’ve ever written, but it gets the job done. </p>
<h3><font color="#646b86"><font>Looking at the results</font></font></h3>
<p>So to see the demo at work, we’re going to increase the instance count to 2, and I’m also going to disable diagnostics. Enabling diagnostics will just cause some extra messages in the console output that I want to avoid. Otherwise, you can leave it in there. Once that’s done, it’s just a matter of setting up the TrafficStorage configuration setting to point at a storage account and pressing F5 to run the demo. If everything goes well, the role should deploy, and we can see both instances running in the Windows Azure Compute Emulator UI (check the little blue flag in the tool tray to view the UI). </p>
<p>If everything is working as intended, you’ll see output sort of like this:</p>
<p><a href="http://brentdacodemonkey.files.wordpress.com/2012/07/image.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://brentdacodemonkey.files.wordpress.com/2012/07/image_thumb.png?w=630&#038;h=380" width="630" height="380" /></a></p>
<p>Notice that the role is going back and forth with having control, just as we’d hoped. You may also note that the first message was that we didn’t have control. This is because our attempts to get control is happening asynchronously in a separate thread. Now you can change that if you need to, but in out case this isn’t necessary. I just wanted to point it out. </p>
<p>Now as I mentioned, this is just a mini-pattern. So for my next post I hope to wrap this in another class that demonstrates the self-electing controller. Again leveraging async processes to execute something for our role instance in a separate thread. But done so in a way where we don’t need to monitor and manage what’s happening ourselves. Meanwhile, <a href="http://filestore.stinemans.org/codesamples/TrafficCop.zip">I’ve uploaded the code</a>. So please make use of it. </p>
<p>Until next time!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brentdacodemonkey.wordpress.com/451/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brentdacodemonkey.wordpress.com/451/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brentdacodemonkey.wordpress.com&#038;blog=16393590&#038;post=451&#038;subd=brentdacodemonkey&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brentdacodemonkey.wordpress.com/2012/07/27/the-traffic-cop-pattern/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6b9db6386dfb619649eda05c07f30359?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">brentstineman</media:title>
		</media:content>

		<media:content url="http://brentdacodemonkey.files.wordpress.com/2012/07/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
	</channel>
</rss>
