building robust windows azure applications with p&p guidance @maheshkrishnan principal...
TRANSCRIPT
Building Robust Windows Azure Applications with P&P Guidance@MaheshKrishnanPrincipal Consultant, Readify
AZR323a
AgendaWhat’s covered
Auto ScalingScaling conceptsAddressing scaling using Windows Azure Scaling Application Block (WASABi)
Transient errorsThe BasicsAddressing these errors using Transient Fault Handling Application Block (TOPAZ)
Cloud benefits – a recap
Zero or low upfront costLower on-going costSeemingly infinite resourcesElasticity on demand
Scaling - Basics
Helps balance running cost with load and performanceVertical Scaling
Increase or decrease VM size(Scale up/down)
Horizontal ScalingIncrease or decrease number of instances(Scale out/in)
Manual scaling
Manual scaling useful for once-off scaling. Not good under other scenariosManual intervention = mistakes
Two types of scaling
ProactiveReactive
My auto scaling wish list
Should be built into AzureScale out/in based on time tableScale out/in based on perf. counters, queue size, etcWork to my SLAsDon’t break the bank (work within budget)Configuration not done in code
Wish list (contd)
On heavy load, start cutting back on high CPU tasks/featuresMake optimum use of my billing cyclesPreferably host in Azure on a Worker roleCover multiple sites with one App
Options for Auto scaling
Use a SaaS provider Azure Watch
Build your ownLeverage on p&p Guidance and existing framework
Windows Azure Scaling Application Block (WASABi)
WASABi Features
Supports auto-scaling of instancesThrottling Scaling options:
Can be reactive or proactiveHosting:
In Azure: worker roleOn premise: Windows service, Stand alone app
Installation
Use NuGetInstall-Package EnterpriseLibrary.WindowsAzure.Autoscaling
Install the Enterprise Library Configuration Editor
Configuration
Some additions to the App/Web.config fileTwo additional configuration files:
One for rules, such as Rules.xmlOne fore Service info, such as Services.xml
Rules and Service info configuration can be stored in Blobs
public class WorkerRole : RoleEntryPoint{ private Autoscaler _autoscaler; ... public override bool OnStart() { _autoscaler = EnterpriseLibraryContainer.Current. GetInstance<Autoscaler>(); _autoscaler.Start(); ... } public override void OnStop() { _autoscaler.Stop(); ... }}
Changes in code
Proactive scaling
Constraint RulesUsing time tablesBudget limitsRanking for overlapping rules
Overrides reactive rules
Proactive or constraint rules
<rules xmlns="http://schemas.microsoft.com/practices/2011/entlib/autoscaling/rules"> <constraintRules> <rule name="Default" rank="1"> <actions> <range min="2" max="6" target="SM.Website"/> </actions> </rule> <rule name="Peak" rank="10"> <timetable startTime="08:00:00" duration="08:00:00" utcOffset="+10:00" > <!--<weekly days="Monday Tuesday Wednesday Thursday Friday"/>--> <daily/> </timetable> <actions> ... </actions> </rule> </constraintRules></rules>
Reactive scaling
Use conditions to change instance count or perform specific actionMonitor:
Performance counters thresholdsQueue lengthsCustom business metrics thresholdsEven instance counts
Reactive rules <reactiveRules> <rule name="ScaleUpOnHighUtilization" rank="15" > <when> <greater operand="CPU" than ="60"/> </when> <actions> <scale target="SM.Website" by="1"/> </actions> </rule> <rule name="ScaleDownOnLowUtilization" rank="20" > <when> <less operand="CPU" than ="30"/> </when> <actions> <scale target="SM.Website" by="-1"/> </actions> </rule> </reactiveRules>
Operand
Can be one of the following:performanceCounterqueueLengthinstanceCount
<operands> <performanceCounter alias="CPU" performanceCounterName="\Processor(_Total)\% Processor Time" source="SM.Website" timespan="00:05:00" aggregate="Average"/> </operands>
What to monitor?
\Processor(_Total)\% Processor Time \Memory\Available Bytes \.NET CLR Memory(_Global_)\% Time in GC
Throttling
Use config settings to cut back on features (like some CPU intensive features, or only allowing paid users)Throttling is faster than generating new instances
<rule name="ThrottlingRule" rank="50" > <when> <greater operand="CPU" than ="60"/> </when> <actions> <changeSetting settingName="Throttle" target="SM.Website" value="true" /> </actions> </rule>
Stabilization
The Oscillations problemCool down settings – for both Scale up and downSettings to scale during first few minutes of hour or scale down during last few minutes of an hour
<stablizer> <role roleAlias=“SM.Website” scaleDownCooldown=“00:10:00” scaleUpCooldown=“00:10:00” scaleDownOnlyinLastMinutesOfHour=“10”
scaleUpOnlyInFirstMinutesOfHour=“30”></stablizer>
demo
NameTitleGroup
WASABi in action
Transient ErrorsHandling them using TOPAZ
Typical cloud implementation– a recap
Shared infrastructure Virtualized environmentMulti-tenanted
Transient Errors
Occurs in:Data Management - SQL Database, TablesMessaging – Queues, Service BusCaching
Examples of errors:SQL Database ThrottlingDropped/Stale connectionsInfrastructure issuesService unavailability
Some Transient Error codes
Transient Error Handling Application Block
Will detect known Transient errorsAllows you to specify Retry strategiesContains classes/methods to perform retry logic easily
Retry policies
Fixed IntervalExample – Retry 4 times at 1 second interval
Incremental IntervalExample – Retry 4 times at 1, 2, 3, and 4 second intervals
Exponential Back offExample – Retry 4 times at 2, 4, 8 and 16 seconds intervals
Installation
Use NuGetInstall-Package EnterpriseLibrary.WindowsAzure.TransientFaultHandling
Install the Enterprise Library Configuration Editor
Configuration
Allows you to configure Retry strategies
Using the App block with SQL Database
Contains ReliableSqLConnection classSQLConnectionExtension contains extension methods for SqlConnection
Ex - OpenWithRetrySQLCommandExtension contains extension methods for IDbConnection
Ex – ExecuteCommand
ReliableSqlConnection usage
//Use retry aware connectionusing (var conn = new ReliableSqlConnection (connString, retryPolicy)){ conn.Open(); var cmd = conn.CreateCommand(); cmd.CommandText = sqlStmt;
//retry aware ExecuteCommand int count = cmd.ExecuteScalar();
}
Other scenarios (LinqToSql, EF)
sqlRetryPolicy.ExecuteAction(() =>{ // Invoke a LinqToSQL query.});
return sqlRetryPolicy.ExecuteAction<IEnumerable<string>>(() =>{ // Invoke a EF LINQ query return result;});
Gotchas
Remember that queries are actually executed when they are enumeratedSimilarly, Updates/Delete/Inserts are called when SaveChanges are calledAvoid Lazy loading
demo
NameTitleGroup
TOPAZ in action
SummaryWASABi
Auto scaling can be done reactively or proactivelyCreate a separate Worker role (or use existing one)Install the NuGet packageSpecify constraint and reactive rules in configuration filesInitialise the App Block
SummaryTOPAZ
Helps handle transient errors by retryingInstall NuGet packageSpecify retry strategy in configuration filesMost common usage scenario: SQL Database
Use ReliableSqlConnection instead of SQLConnectionUse extension methods on IDbCommand when executing queries
Use ExecuteAction method on RetryPolicy for everything else (including ORMs)
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the
part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.