who will benefit from this talk topics what you’ll leave with web app developers who are already...

26
www.buildwindows.com Building scalable web apps with Windows Azure Matthew Kerner Principal Program Manager Microsoft Corporation SAC-870T

Upload: scott-whitehead

Post on 23-Dec-2015

218 views

Category:

Documents


3 download

TRANSCRIPT

www.buildwindows.com

Building scalable web apps with Windows Azure

Matthew KernerPrincipal Program ManagerMicrosoft Corporation

SAC-870T

www.buildwindows.com

Agenda

WHO WILL BENEFIT FROM THIS TALK

TOPICS WHAT YOU’LL LEAVE WITH

• Web app developers

• who are already familiar with Windows Azure

• with scaling needs.

• Asynchronous patterns & techniques

• Managing data access

• Tuning application performance

• Windows Azure helps you build scalable web apps

• using the approaches that you’re already familiar with.

www.buildwindows.com

• Each thread dedicated to one outstanding request• Block on each step of “the work” done for each request,

then respond & repeat

• This approach scales poorly• Each outstanding request is stored on a thread stack• Threads block even when there is work to be done• Adding a thread enables only one additional concurrent

request

Synchronous Design Pattern

Client Request #1Web App Front End

Thread Thread

“The Work” #1SQL

Azure

WA Storage

Middle Tier

Response #1Client Response #1blocks

Time passes…Client Request #2 Waiting…

www.buildwindows.com

• Each thread picks up work whenever it is ready• A thread handling one request may handle another

before the first one completes

• This approach scales well• Client requests tracked explicitly in app’s data structures• Threads never block while there is work to be done• Each thread can handle possibly many concurrent

requests• But bookkeeping & synchronization can be

difficult…

Asynchronous Design Pattern

Client Request #1Web App Front End

Thread Thread

“The Work” #1

SQL Azure

WA Storage

Middle Tier

Response #1Client Response #1

ContextClient Request #2

Client Response #2

“The Work” #2

Response #2

Async/await support simplifies bookkeepingvoid UploadImage(Stream image, CloudBlob destBlob){ // Add image to list in SQL Azure AddImageToSQLAzure(destBlob.Uri);

// Upload image to blob storage UploadImageToBlob(image, destBlob);}

async Task UploadImageAsync(Stream image, CloudBlob destBlob){ // Add image to list in SQL Azure var t1 = AddImageToSQLAzureAsync(destBlob.Uri);

// Upload image to blob storage var 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<T> to // represent a Begin/End async invocation await Task.Factory.FromAsync<Stream>(destBlob.BeginUploadFromStream, destBlob.EndUploadFromStream, image, null);}

www.buildwindows.com

Asynchronous Cloud Support• Async language features• .NET 4.0 Async CTP works with Azure if you copy

AsyncCtpLibrary.dll• Windows Azure Storage Queues are useful for async

communication between role instances• Built-in load balancing• Handles loss of individual role instances gracefully

• Async designs may increase exposure to race conditions• Running at scale on commodity hardware means any role

instance can fail at any time• Implement retries where appropriate• External state updates must be idempotent or

transactional

www.buildwindows.com

• How to transfer data efficiently to and from clients?• There are different kinds of data; each has its own tricks

• Trick #1: Get out of the way when you can• Send clients directly to blob storage for static

content• Media (e.g. images, video)• Binaries (e.g. XAP, MSI, ZIP)• Data files (e.g. XML)

Managing Data Access

Hosted ComputeBlob

StorageHosted Compute

www.buildwindows.com

Shared Access Signatures• Trick #2: Shared access signatures provide direct

access to ACLed content• Can be time-bound or revoked on demand

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

-days

Hosted ComputeStg Key

Blob Storage

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

1. “I am Bob & I want X”

2. Service prepares a Shared Access Signature (SAS) to X using the securely stored storage account key

3. Service returns SAS (signed HTTPS URL)

4. Bob uses SAS to access X directly from Blob Storage for reduced latency & compute load

www.buildwindows.com

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

• Use the CDN if you expect multiple reads before content expiration

• Reduces latency and load on central storage account

Serve Blobs from the Edge

Blob Storage

X

Public container

CDN

X

Blob header determines time-to-live at the edge

Few hops

Possibly many hops or poor links

Closest Point of Presence

DNS name resolves to closest POP

www.buildwindows.com

Windows Azure Content Delivery Network• 24 global locations with 99.95% availability SLA• Enabling CDN access for your Windows Azure storage

account• Enable the CDN in the dev portal• It will generate a new URL for CDN-based access to your account• Same content, 2 URLs with different access patterns

• CDN 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 URLs• http://

blog.smarx.com/posts/using-the-new-windows-azure-cdn-with-a-custom-domain

• Smooth streaming is in CTP

www.buildwindows.com

Managing CDN Content Expiration• Default behavior is to fetch once and cache for up

to 72 hrs• Modify cache control blob header to control the TTL

• x-ms-blob-cache-control: public, max-age=<value in seconds>

• Think hours, days or weeks• Higher numbers reduce cost and latency via CDN &

downstream caches• Use versioned URLs to expire content on-demand

• Enables easy rollback and A/B testing

Blob Storage

logo.2011-08-01.png

logo.2011-09-16.png

CDNlogo.2011-08-

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

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

logo.2011-09-16.png

www.buildwindows.com

Windows Azure Traffic Manager

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

• CNAMEs supported• Useful for performance, business continuity, price,

compliance & tax• Not the same as CDN

• Not serving from the edge• Only DNS is cached (at client)

Traffic Manager

MonitoringPolicies

foo.cloudapp.net foo-us.cloudapp.net

foo-europe.cloudapp.net

foo-asia.cloudapp.net

1.2.3.4DNS response

www.buildwindows.com

• Multiple factors determine DNS resolution• Configured by Microsoft

• Geo-IP mapping• Periodic performance measurement

• Configured by service owner• Policy: Performance, Failover, Geo, Ratio• Monitoring

• Currently in CTP• Only works in “production” slot but not yet intended for production

use• No SLA or billing, and the Traffic Manager domain name will

change

Traffic Manager Details

Monitoring

foo-us.cloudapp.net

foo-europe.cloudapp.net

foo-asia.cloudapp.net

/monitoring/testme.aspx

Periodic GETs

www.buildwindows.com

• Trick #5: Cache hot data in memory to avoid slower data-tier access• Session state (e.g. shopping cart) & immutable reference

data (e.g. product catalog entries)

• Caching tier will help you reduce latency and cost• Lower latency/higher throughput than data tier,

especially under load

In-Memory Caching

Hosted Compute

Table Storag

e

SQL Azure

In-Memory Caching

Table Storag

e

SQL Azure

www.buildwindows.com

Windows Azure AppFabric Caching• AppFabric Caching is a hosted distributed cache as

a service• Globally provisioned and managed by Microsoft with

SLAs & pricing• Low latency, hosted per subregion for app affinity• AuthN/Z integrated with Access Control Service

• Advantages• Simple to administer• ASP.NET session state and output cache providers• Same APIs as Windows Server AppFabric Cache• Client-local near cache for hot data without

serialization costs

www.buildwindows.com

• Trick #6: Partition & shard at the data tier

• SQL Azure single DB limits• 50 GB capacity, will expand over time• Overuse of more than one node’s worth of resources may result in

throttling http://social.technet.microsoft.com/wiki/contents/articles/sql-azure-connection-management.aspx

• Windows Azure Storage scalability targets• Each account supports 100 TB capacity, 5K transactions/sec, 3

Gbps bandwidth• 500 messages/sec per queue• 500 entities/sec per table partition (multiple partitions permitted

per table)• 60 MB/sec per blob

Partitioning & Sharding

Hosted Compute

Partitioned Table

Queue

WA Storage Acct

Blob

Partitioned Table

Queue

WA Storage Acct

Blob

Partitioned Table

Queue

WA Storage Acct

Blob

www.buildwindows.com

SQL Azure Federations• Sharding is…• a pattern that scales out data tier access by partitioning

data and queries across multiple servers• a design choice that impacts the app, schema and DBA

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

• SQL Azure Federation is in CTP now, will release in 2011

• http://social.technet.microsoft.com/wiki/contents/articles/2281.aspx

www.buildwindows.com

Basic Performance Tuning• Tune Windows Azure applications just as you would

on-premises applications• Measure & optimize where it makes a difference

• Windows Azure uses Full IIS for web roles in the 1.3+ SDK• Startup admin tasks using WebPI can install up-to-date

extensions as desired• Startup admin tasks using AppCmd can configure IIS as

desired• Basic tips• Build in release mode (not debug mode) for production• Do not enable IntelliTrace or Failed Request Tracing in

production• Tune role instance counts and consider dynamic

scaling

www.buildwindows.com

Advanced Performance Tuning• Enable 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

workload• Modify default schedule to avoid peak times• http://

blog.smarx.com/posts/controlling-application-pool-idle-timeouts-in-windows-azure

• Measure and eliminate memory leaks if footprint grows over time

• Move ASP.NET cache to the resource disk for more space

• Tune Windows Azure Diagnostics settings

www.buildwindows.com

Asynchronous Hosted ComputeAsynchronous

Hosted ComputeSynchronous Hosted

Compute

Summary

• Approach WA apps like you would on-premises apps

• Use rich platform features in Windows Azure to tune for the cloud too

Blob Storage

Stg Key

Private

Public

Shared Access Signatures

CDN

Cache controlVersioned URLsPubli

c

Table Storag

e

SQL Azure

AppFabric Caching

Table Storag

e

SQL Azure

SQL Azure

Tuning

Sharding

Traffic Mgr

Web App

www.buildwindows.com

For more information

• Building Global and Highly Available Services Using Windows Azure

• Building IIS and ASP.NET Applications with the Power of Async

• Building Parallelized Applications with .NET and Visual Studio

• Optimize Your Website Using ASP.NET and IIS8

• The Zen of Async: Best Practices for Best Performance

RELATED SESSIONS DOCUMENTATION & ARTICLES

CONTACT: [email protected]

• Tutorials for improving performance on Windows Azure: http://www.microsoft.com/windowsazure/learn/improve-performance/

www.buildwindows.com

• Feedback and questions http://forums.dev.windows.com

• Session feedbackhttp://bldw.in/SessionFeedback

thank you

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