Transcript
Page 1: Building  Scalable Web Apps  with Windows  Azure

Building Scalable Web Apps with Windows AzureNameTitleMicrosoft Corporation

Page 2: Building  Scalable Web Apps  with Windows  Azure

AgendaWho will benefit from this talkWeb app developerswho are already familiar with Windows Azurewith scaling needs

TopicsAsynchronous patterns & techniquesManaging data accessTuning application performance

What you’ll leave withWindows Azure helps you build scalable web appsusing the approaches that you’re already familiar with

Page 3: Building  Scalable Web Apps  with Windows  Azure

Synchronous Design PatternEach thread dedicated to one outstanding requestBlock on each step of “the work” done for each request, then respond & repeat

This approach scales poorlyEach outstanding request is stored on a thread stackThreads block even when there is work to be doneAdding a thread enables only one additional concurrent request

Client Request #1Web App Front End

Client Response #1

Client Request #2

“The Work” #1

Response #1

Time passes…

Thread Thread

Waiting…blocks

Page 4: Building  Scalable Web Apps  with Windows  Azure

Asynchronous Design PatternEach thread picks up work whenever it is readyA thread handling one request may handle another before the first one completes

Client Request #1Web App Front End

Client Response #1Client Request #2

“The Work” #1

Response #1Thread Thread

Client Response #2“The Work” #2Response #2

This approach scales wellClient requests tracked explicitly in app’s data structuresThreads never block while there is work to be doneEach thread can handle possibly many concurrent requests

But bookkeeping & synchronization can be difficult…

Page 5: Building  Scalable Web Apps  with Windows  Azure

Async/await support simplifies bookkeepingvoid UploadImage(Stream image, CloudBlob destBlob){

// Add image to list in SQL AzureAddImageToSQLAzure(destBlob.Uri);

// Upload image to blob storageUploadImageToBlob(image, destBlob);

}

async Task UploadImageAsync(Stream image, CloudBlob destBlob){

// Add image to list in SQL Azurevar t1 = AddImageToSQLAzureAsync(destBlob.Uri);

// Upload image to blob storagevar t2 = UploadImageToBlobAsync(image, destBlob);

await TaskEx.WhenAll(t1, t2);}

But how do we make one of these?

Page 6: Building  Scalable Web Apps  with Windows  Azure

Creating async methods from begin/end pairsvoid UploadImageToBlob (Stream image, CloudBlob destBlob){

destBlob.UploadFromStream(image);}

async Task UploadImageToBlobAsync (Stream image, CloudBlob destBlob){

// Task.Factory.FromAsync method creates a Task or Task<T> to// represent a Begin/End async invocationawait Task.Factory.FromAsync<Stream>(destBlob.BeginUploadFromStream,

destBlob.EndUploadFromStream,image, null);

}

Page 7: Building  Scalable Web Apps  with Windows  Azure

Asynchronous Cloud SupportAsync language featuresNET 4.0 Async CTP works with Azure if you copy AsyncCtpLibrary.dll

Windows Azure Storage Queues are useful for async communication between role instancesBuilt-in load balancingHandles loss of individual role instances gracefully

Async designs may increase exposure to race conditionsRunning at scale on commodity hardware means any role instance can fail at any timeImplement retries where appropriateExternal state updates must be idempotent or transactional

Page 8: Building  Scalable Web Apps  with Windows  Azure

Managing Data AccessHow to transfer data efficiently to and from clients?There are different kinds of data; each has its own tricks

Trick #1: Blob Storage

Send clients directly to blob storage for static contentMedia (e.g. images, video)Binaries (e.g. XAP, MSI, ZIP)Data files (e.g. XML)

Get out of the way when you can

Page 9: Building  Scalable Web Apps  with Windows  Azure

Shared Access Signatures

Blob Storage

Also works for write access (e.g. user-generated content)http://blog.smarx.com/posts/shared-access-signatures-are-easy-these-days

Non-public blob(e.g. paid or ad-funded content)X

Trick #2: Shared access signatures provide direct access to ACLed contentCan be time-bound or revoked on demand

Page 10: Building  Scalable Web Apps  with Windows  Azure

Serve Blobs from the Edge

X

Blob Storage

X

Possibly many hops or poor links

Few hops

Public container

Use the CDN if you expect multiple reads before content expirationReduces latency and load on central storage account

Trick #3: Serve public blobs from the edge with the Windows Azure CDN

Page 11: Building  Scalable Web Apps  with Windows  Azure

Windows Azure Content Delivery Network24 global locations with 99.95% availability SLAEnabling CDN access for your Windows Azure storage accountEnable the CDN in the dev portalIt will generate a new URL for CDN-based access to your accountSame content, 2 URLs with different access patternsCDN URL: http://azXXXX.vo.msecnd.net/images/myimage.png WA Storage URL: http://myacct.blob.core.windows.net/images/myimage.png

CNAME mappings to CDN URLshttp://blog.smarx.com/posts/using-the-new-windows-azure-cdn-with-a-custom-domain

Smooth streaming is in CTP

Page 12: Building  Scalable Web Apps  with Windows  Azure

Managing CDN Content ExpirationDefault behaviour is to fetch once and cache for up to 72 hrsModify cache control blob header to control the TTL

x-ms-blob-cache-control: public, max-age=<value in seconds>Think hours, days or weeksHigher numbers reduce cost and latency via CDN & downstream caches

Use versioned URLs to expire content on-demand

… <img src="http://azXXXX.vo.msecnd.net/images/logo.2011-08-01.png" />…

… <img src="http://azXXXX.vo.msecnd.net/images/logo.2011-09-16.png" />…

BlobStorage

CDNHTML Served by App

2011-08-012011-09-16

2011-08-012011-09-16

Enables easy rollback and A/B testing

Page 13: Building  Scalable Web Apps  with Windows  Azure

CDN for Web AppsCDN supports your web app as an originNormal URL: http://foo.cloudapp.net/default.aspx CDN URL: http://azXXXX.vo.msecnd.net/default.aspx Cached from: http://foo.cloudapp.net/cdn/default.aspx

CNAMEs & HTTPS supportedhttp://blog.smarx.com/posts/using-the-windows-azure-cdn-for-your-web-application

You must modify cache control headers to set the ASP.NET OutputCache module to work well with the CDNhttp://blogs.msdn.com/b/scicoria/archive/2011/07/10/hosted-service-as-a-windows-azure-cdn-origin-tips.aspx

Page 14: Building  Scalable Web Apps  with Windows  Azure

Windows Azure Traffic Manager

foo-us.cloudapp.net

foo-europe.cloudapp.net

foo-asia.cloudapp.net

Policies Monitoring

foo.cloudapp.net

DNS response

1.2.3.4

Trick #4: Direct users to the service in the closest region with the Windows Azure Traffic Manager

CNAMEs supportedUseful for performance, business continuity, price, compliance & taxNot the same as CDNNot serving from the edgeOnly DNS is cached (at client)

Page 15: Building  Scalable Web Apps  with Windows  Azure

Traffic Manager DetailsMultiple factors determine DNS resolutionConfigured by MicrosoftGeo-IP mappingPeriodic performance measurementConfigured by service ownerPolicy: Performance, Failover, Geo, RatioMonitoring

Currently in CTPOnly works in “production” slot but not yet intended for production useNo SLA or billing, and the Traffic Manager domain name will change

foo-us.cloudapp.net

foo-europe.cloudapp.net

foo-asia.cloudapp.net

Monitoring Periodic GETs

Page 16: Building  Scalable Web Apps  with Windows  Azure

Table Storag

e

Table Storag

e

In-Memory Caching

Hosted Compute

In-Memory Caching

Trick #5: Cache hot data in memory to avoid slower data-tier accessSession state (e.g. shopping cart) & immutable reference data (e.g. product catalog entries)

Caching tier will help you reduce latency and costLower latency/higher throughput than data tier, especially under load

Page 17: Building  Scalable Web Apps  with Windows  Azure

Windows Azure CachingCaching is a hosted distributed cache as a serviceGlobally provisioned and managed by Microsoft with SLAs & pricingLow latency, hosted per subregion for app affinityAuthN/Z integrated with Access Control Service

AdvantagesSimple to administerASP.NET session state and output cache providersSame APIs as Windows Server CacheClient-local near cache for hot data without serialization costs

Page 18: Building  Scalable Web Apps  with Windows  Azure

WA Storage Acct

Partitioned Table

Queue

Partitioning & Sharding

Hosted Compute

WA Storage Acct

Partitioned Table

Queue

WA Storage Acct

Partitioned Table

Queue

Trick #5: Partition & shard at the data tier

SQL Azure single DB limits50 GB capacity, will expand over timeOveruse of more than one node’s worth of resources may result in throttlinghttp://social.technet.microsoft.com/wiki/contents/articles/sql-azure-connection-management.aspx

Windows Azure Storage scalability targetsEach account supports 100 TB capacity, 5K transactions/sec, 3 Gbps bandwidth500 messages/sec per queue500 entities/sec per table partition (multiple partitions permitted per table)60 MB/sec per blob

Page 19: Building  Scalable Web Apps  with Windows  Azure

SQL Azure FederationsSharding is…A pattern that scales out data tier access by partitioning data and queries across multiple serversA design choice that impacts the app, schema and DBA

Federation is SQL Azure’s new native sharding implementationDistributes data across databases (federation members)Routes queries to the correct federation membersEnables dynamic repartitioning without downtime

SQL Azure Federation is in CTP now, will release in 2011http://social.technet.microsoft.com/wiki/contents/articles/2281.aspx

Page 20: Building  Scalable Web Apps  with Windows  Azure

Basic Performance TuningTune Windows Azure applications just as you would on-premises applicationsMeasure & optimize where it makes a difference

Windows Azure uses Full IIS for web roles in the 1.3+ SDKStartup admin tasks using WebPI can install up-to-date extensions as desiredStartup admin tasks using AppCmd can configure IIS as desired

Page 21: Building  Scalable Web Apps  with Windows  Azure

Basic Performance TuningBasic tipsBuild in release mode (not debug mode) for productionDo not enable IntelliTrace or Failed Request Tracing in production

Tune role instance counts and consider dynamic scaling

Page 22: Building  Scalable Web Apps  with Windows  Azure

Advanced Performance TuningEnable compression for additional dynamic content types

<add mimeType="application/json" enabled="true" /><add mimeType="application/json; charset=utf-8" enabled="true" />Office document formats

Tune application pool recycling to suit your workloadModify default schedule to avoid peak timeshttp://blog.smarx.com/posts/controlling-application-pool-idle-timeouts-in-windows-azure Measure and eliminate memory leaks if footprint grows over time

Page 23: Building  Scalable Web Apps  with Windows  Azure

Advanced Performance TuningMove ASP.NET cache to the resource disk for more space

Tune Windows Azure Diagnostics settings

Page 24: Building  Scalable Web Apps  with Windows  Azure

SQLAzure

SQL Azure

CDN

Asynchronous Hosted Compute

Asynchronous Hosted ComputeAsynchronous Hosted Compute

SummaryApproach WA apps like you would on-premises appsUse rich platform features in Windows Azure to tune for the cloud too

Blob Storage

Table Storage

PublicPrivat

e

Sharding

Public

Shared Access Signatures

Cache control Versioned URLs

Synchronous Hosted Compute

Tuning

Table Storage

Traffic Mgr Caching

SQL Azure

Page 25: Building  Scalable Web Apps  with Windows  Azure

© 2011 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.


Recommended