24

Building High Performance Web Applications with the Windows Azure Platform

Embed Size (px)

DESCRIPTION

The Windows Azure Platform enables developers to build dynamically scalable web applications easily. Come and learn how services like the Content Delivery Network (CDN) and Windows Azure AppFabric Caching can help you build high-performance web applications in Windows Azure. In this session we’ll share some tips & tricks to improve performance when using web & worker roles in Azure, and to optimize your overall application for maximum performance.

Citation preview

Page 1: Building High Performance Web Applications with the Windows Azure Platform
Page 2: Building High Performance Web Applications with the Windows Azure Platform

Building High Performance Web Applications with the Windows Azure Platform

Wade WegnerTechnical EvangelistMicrosoft Corporation

Page 3: Building High Performance Web Applications with the Windows Azure Platform

High Performance Web Applications

What do I mean?Global user base, snappy response timesScale out to handle many concurrent requestsHeavy transaction load & bandwidth requirements

How does this apply to the cloud?Windows Azure applications are mostly like on-premises applications…… but some things are different (and even easier) in the cloud.I will assume you already know the basics of Windows Azure

AgendaAsynchronous design patternsManaging data accessTuning application performance

Page 4: Building High Performance Web Applications with the Windows Azure Platform

Synchronous Design Pattern

Handle one request at a time for each threadBlock on “the work” done for each request, then respond & repeat

Thread stacks are the data structures used to track client requestsThreads spend most of their time blocking

Increase thread count for greater throughput – heavyweight approach

Client Request #1

Web App Front End

Thread Thread

“The Work” #1SQL Azure

WA Storage

Middle Tier

Response #1Client Response #1blocks

Time passes…Client Request #2 Waiting…

Page 5: Building High Performance Web Applications with the Windows Azure Platform

Handle one request at a time for each threadQueue “the work”, then handle the next request or post back results

Client requests tracked explicitly in app’s data structuresLocal state is not durableExternal state operations must be idempotent or transactional

Threads block less so fewer threads provide greater throughput

Throughput gated primarily on duration of “The Work”

Asynchronous Design Pattern

Client Request #1

Web 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

Page 6: Building High Performance Web Applications with the Windows Azure Platform

Asynchronous Cloud AppsAsync design applies to both on-premise and cloud apps equallyWindows Azure Storage Queues are useful for async communication between role instances

Built-in load balancingHandles loss of individual role instances gracefully

SQL Azure and Windows Azure Storage both support asynchronous calls

ADO.NET Entity FrameworkWCF Data ServicesLINQ to SQLPlain old ADO.NET

Page 7: Building High Performance Web Applications with the Windows Azure Platform

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 canSend 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

Page 8: Building High Performance Web Applications with the Windows Azure Platform

Shared Access SignaturesTrick #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 Compute

Stg Key

Blob Storage

X

Non-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

Page 9: Building High Performance Web Applications with the Windows Azure Platform

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

Reduces latency and central storage loadUse the CDN when you expect multiple accesses before content expiration

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 slow/lossy links

Closest Point of Presence

DNS name resolves to closest POP

Page 10: Building High Performance Web Applications with the Windows Azure Platform

Windows Azure Content Delivery Network>20 global locations with 99.95% availability

Enabling CDN access for your Windows Azure storage account

Enable the CDN in the dev portalIt will generate a new URL for CDN-based access to your accountSame content, 2 URLs with different access patterns

CDN URL: http://azXXXX.vo.msecnd.net/images/myimage.pngWA 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

Adaptive Streaming can be made to work with the CDN toohttp://blog.smarx.com/posts/smooth-streaming-with-windows-azure-blobs-and-cdnWill not require cleverness soon

Page 11: Building High Performance Web Applications with the Windows Azure Platform

Managing CDN Content ExpirationDefault behavior is to fetch once and cache for up to 72 hrsModify max-age 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, proxy & browser caches

Use versioned URLs to expire content on-demand

Enables easy rollback and A/B testing

Blob Storage

logo.2010-08-01.png

logo.2010-10-29.png

CDN

logo.2010-08-01.png

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

HTML Served by App

… <img src="http://azXXXX.vo.msecnd.net/images/logo.2010-10-29.png" />… logo.2010-10-

29.png

Page 12: Building High Performance Web Applications with the Windows Azure Platform

Trick #4: 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 costLower latency/higher throughput than data tier, especially under load

In-Memory Caching

Hosted Compute

Table Storage

SQL Azure

In-Memory Caching

Table Storage

SQL Azure

Page 13: Building High Performance Web Applications with the Windows Azure Platform

Anatomy of A Distributed CacheCache footprint or bandwidth requirement may grow beyond a single VM

Distributed caches scale out

Unified Cache View

Multiple role instances may be

cache clients

Clients access the cache as if it was a

single large namespace

Cache layer distributes data

across the various cache instances

Page 14: Building High Performance Web Applications with the Windows Azure Platform

Windows Azure AppFabric CachingWhat is it?

Windows Server AppFabric Cache is an on-premise distributed in-memory cacheAppFabric Caching is a new, hosted in-memory caching serviceCTP release at PDCRoadmap to full parity between on-premise and cloud where it makes sense

Excellent performanceHighly scalable, 64-bit serviceLow latency, will be hosted per subregion for app affinityHighly-available

AuthN/AuthZ integrated with Access Control ServiceYou may have heard of memcached too

Latest memcached works on Windows Azure with 1.3 SDKhttp://code.msdn.microsoft.com/winazurememcached

You manage instances and pay for compute hours

Page 15: Building High Performance Web Applications with the Windows Azure Platform

AppFabric Caching AdvantagesSimple to administer

No need to manage and host a distributed cache yourself

Integrates easily into existing applicationsASP.NET session state and output cache providers enable no-code integration

Same managed interfaces as Windows Server AppFabric Cache

Caches any serializable managed objectNo object size limitsNear cache (client-local) for hot data without serialization costs

On-Premises App Windows Azure App

Core Logic

AppFa

bri

c C

ach

e

APIs

Windows Server

AppFabric Cache

Core Logic

AppFa

bri

c C

ach

e

APIs

Windows Azure

AppFabric Caching

Page 16: Building High Performance Web Applications with the Windows Azure Platform

AppFabric Caching Security Configuration

<configuration> <dataCacheClient deployment="Simple"> <hosts> <host name="<your URI>" cachePort="22233" /> </hosts> <securityProperties mode="Message"> <messageSecurity authorizationInfo="<your authentication token>" /> </securityProperties> </dataCacheClient></configuration>

Page 17: Building High Performance Web Applications with the Windows Azure Platform

AppFabric Caching Session State Provider

<configuration> <system.web> <sessionState mode="Custom" customProvider="DistributedSessionProvider" compressionEnabled="false"> <providers> <add name="DistributedSessionProvider" type="Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider,Microsoft.Web.DistributedCache" cacheName="default" applicationName="Contoso" useBlobMode="false"/> </providers> </sessionState> </system.web></configuration>

Page 18: Building High Performance Web Applications with the Windows Azure Platform

AppFabric Caching Output Provider

<system.web> <caching> <outputCache defaultProvider="DistributedCache"> <providers> <add name="DistributedCache" type="Microsoft.Web.DistributedCache.DistributedCacheOutputCacheProvider,Microsoft.Web.DistributedCache" cacheName="default" applicationName="Contoso" /> </providers> </outputCache> </caching> </system.web>

Page 19: Building High Performance Web Applications with the Windows Azure Platform

AppFabric Caching Code

// Use cache configuration from app configDataCacheFactory CacheFactory = new DataCacheFactory();

// Get cache client for cacheDataCache myCache = CacheFactory.GetDefaultCache();

// Add an object to the cache.myCache.Put(“myKey", myObject);

retrievedObject = myCache.Get("myKey");

if (retrievedObject == null){ // Cache miss}

Page 20: Building High Performance Web Applications with the Windows Azure Platform

SQL Azure & Sharding

Trick #5: Partition (or shard) your SQL Azure data across databases

Spreads load across multiple database instancesAvoid hitting database size limitsParallelized queries across more nodesImproved query performance on commodity hardware

Partitioning scheme varies per data set

Hosted Compute

A-M

N-Z

A-Z

Page 21: Building High Performance Web Applications with the Windows Azure Platform

Basic Performance TuningTune Windows Azure applications just as you would on-premises applications

MeasureOptimize where it makes a difference

Windows Azure uses Full IIS for web roles starting with the 1.3 SDK

Startup admin tasks using WebPI can install up-to-date extensions as desiredStartup admin tasks using AppCmd can configure IIS as desired

Basic tipsBuild in release mode (not debug mode) for productionDo not enable IntelliTrace or Failed Request Tracing in productionTune role instance counts and consider dynamic scaling

Page 22: Building High Performance Web Applications with the Windows Azure Platform

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 workload

Modify default schedule to avoid peak timesMeasure and eliminate memory leaks if footprint grows over timeNew IIS 7.5 module to warm up app upon init at http://www.iis.net/download/ApplicationWarmUp

Move ASP.NET cache to the resource disk for more spaceTune Windows Azure Diagnostics settings

Page 23: Building High Performance Web Applications with the Windows Azure Platform

Asynchronous Hosted Compute

Synchronous Hosted Compute

Summary

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

Blob Storage

Stg Key

Private

Public

Shared Access Signatures

CDN

Cache controlVersioned URLs

Public

Table Storag

e

SQL Azure

AppFabric Caching

Table Storag

e

SQL Azure

SQL Azure

Tuning

Sharding

Page 24: Building High Performance Web Applications with the Windows Azure Platform

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