Building Scalable Web Apps with Windows Azure

Download Building  Scalable Web Apps  with Windows  Azure

Post on 11-Feb-2016




0 download


Building Scalable Web Apps with Windows Azure. Name Title Microsoft Corporation. Agenda. Who will benefit from this talk Web app developers who are already familiar with Windows Azure with scaling needs Topics Asynchronous patterns & techniques Managing data access - PowerPoint PPT Presentation


Building Scalable Web Apps with Windows Azure

Building Scalable Web Apps with Windows AzureNameTitleMicrosoft CorporationAgendaWho will benefit from this talkWeb app developerswho are already familiar with Windows Azurewith scaling needsTopicsAsynchronous patterns & techniquesManaging data accessTuning application performanceWhat youll leave withWindows Azure helps you build scalable web appsusing the approaches that youre already familiar with

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 requestClient Request #1Web App Front EndSQL AzureWA StorageMiddle TierClient Response #1Client Request #2The Work #1Response #1Time passesThreadThreadWaitingblocks

Asynchronous Design PatternEach thread picks up work whenever it is readyA thread handling one request may handle another before the first one completesClient Request #1Web App Front EndSQL AzureWA StorageMiddle TierClient Response #1Client Request #2The Work #1Response #1ThreadThreadClient Response #2The Work #2Response #2ContextThis approach scales wellClient requests tracked explicitly in apps data structuresThreads never block while there is work to be doneEach thread can handle possibly many concurrent requests

But bookkeeping & synchronization can be difficultAsync/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?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 to// represent a Begin/End async invocationawait Task.Factory.FromAsync(destBlob.BeginUploadFromStream, destBlob.EndUploadFromStream,image, null);}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 transactionalHosted ComputeManaging Data AccessHow to transfer data efficiently to and from clients?There are different kinds of data; each has its own tricksHosted ComputeTrick #1: Blob StorageSend 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 canShared Access SignaturesHosted ComputeBlob StorageStg Key3. Service returns SAS (signed HTTPS URL)2. Service prepares a Shared Access Signature (SAS) to X using the securely stored storage account key4. Bob uses SAS to access X directly from Blob Storage for reduced latency & compute loadAlso works for write access (e.g. user-generated content) Non-public blob(e.g. paid or ad-funded content)X1. I am Bob & I want XTrick #2: Shared access signatures provide direct access to ACLed contentCan be time-bound or revoked on demand CDNServe Blobs from the EdgeXBlob StorageXClosest Point of PresencePossibly many hops or poor linksFew hopsBlob header determines time-to-live at the edgeDNS name resolves to closest POPPublic containerUse the CDN if you expect multiple reads before content expirationReduces latency and load on central storage accountTrick #3: Serve public blobs from the edge with the Windows Azure CDNWindows 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: WA Storage URL:

CNAME mappings to CDN URLs

Smooth streaming is in CTP11Managing CDN Content ExpirationDefault behaviour is to fetch once and cache for up to 72 hrsModify cache control blob header to control the TTLx-ms-blob-cache-control: public, max-age=Think hours, days or weeksHigher numbers reduce cost and latency via CDN & downstream caches

Use versioned URLs to expire content on-demand

BlobStorageCDNHTML Served by Applogo.2011-08-01.pnglogo.2011-09-16.pnglogo.2011-08-01.pnglogo.2011-09-16.pngEnables easy rollback and A/B testingCDN for Web AppsCDN supports your web app as an originNormal URL: CDN URL: Cached from:

CNAMEs & HTTPS supported

You must modify cache control headers to set the ASP.NET OutputCache module to work well with the CDN Windows Azure Traffic Managerfoo-us.cloudapp.netfoo-europe.cloudapp.netfoo-asia.cloudapp.netTraffic ManagerPoliciesMonitoringfoo.cloudapp.netDNS response1.2.3.4Trick #4: Direct users to the service in the closest region with the Windows Azure Traffic ManagerCNAMEs supportedUseful for performance, business continuity, price, compliance & taxNot the same as CDNNot serving from the edgeOnly DNS is cached (at client)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 changefoo-us.cloudapp.netfoo-europe.cloudapp.netfoo-asia.cloudapp.netMonitoring/monitoring/testme.aspx

Periodic GETs15Table StorageTable StorageIn-Memory CachingHosted ComputeIn-Memory CachingTrick #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 loadWindows 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 costsWA Storage AcctPartitioned TableBlobQueuePartitioning & ShardingHosted ComputeWA Storage AcctPartitioned TableBlobQueueWA Storage AcctPartitioned TableBlobQueueTrick #5: Partition & shard at the data tierSQL Azure single DB limits50 GB capacity, will expand over timeOveruse of more than one nodes worth of resources may result in throttling 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 blobSQL Azure FederationsSharding isA 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 Azures 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 2011 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 desiredBasic 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 scalingAdvanced Performance TuningEnable compression for additional dynamic content types

Office document formatsTune application pool recycling to suit your workloadModify default schedule to avoid peak times Measure and eliminate memory leaks if footprint grows over timeAdvanced Performance TuningMove ASP.NET cache to the resource disk for more space

Tune Windows Azure Diagnostics settingsSQLAzureSQL AzureCDN

Asynchronous Hosted ComputeStg KeyAsynchronous Hosted ComputeStg KeyAsynchronous Hosted ComputeStg KeySummaryApproach WA apps like you would on-premises appsUse rich platform features in Windows Azure to tune for the cloud tooBlob StorageTable StoragePublicPrivateShardingPublicWeb AppStg KeyShared Access SignaturesCache control Versioned URLsSynchronous Hosted ComputeStg KeyTuningTable StorageTraffic MgrCachingSQL 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.