1 / 25

Building Scalable Web Apps with Windows Azure

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

norina
Download Presentation

Building Scalable Web Apps with Windows Azure

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Building Scalable Web Apps with Windows Azure Name Title Microsoft Corporation

  2. 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 Tuning application performance What you’ll leave with Windows Azure helps you build scalable web apps using the approaches that you’re already familiar with

  3. Synchronous Design Pattern 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 Web App Front End SQL Azure • “The Work” #1 • Client Request #1 Middle Tier • Response #1 • Client Response #1 • Thread • Thread • blocks WA Storage • Waiting… • Client Request #2 • Time passes…

  4. Asynchronous Design Pattern Each thread picks up work whenever it is ready A thread handling one request may handle another before the first one completes Web App Front End SQL Azure • “The Work” #1 • Client Request #1 Context Middle Tier • Response #1 • Client Response #1 • Client Request #2 • Thread • Thread • “The Work” #2 WA Storage • Client Response#2 • Response#2 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…

  5. Async/await support simplifies bookkeeping • void UploadImage(Stream image, CloudBlob destBlob) • { • // Add image to list in SQL Azure • AddImageToSQLAzure(destBlob.Uri); • // Upload image to blob storage • UploadImageToBlob(image, destBlob); • } async TaskUploadImageAsync(Streamimage,CloudBlobdestBlob) { // 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?

  6. Creating async methods from begin/end pairs • void UploadImageToBlob (Stream image, CloudBlob destBlob) • { • destBlob.UploadFromStream(image); • } async TaskUploadImageToBlobAsync (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); }

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

  8. Managing Data Access How to transfer data efficiently to and from clients? There are different kinds of data; each has its own tricks Hosted Compute Hosted Compute • 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) • Trick #1: • Blob Storage • Get out of the way when you can

  9. 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 1. “I am Bob & I want X” Non-public blob (e.g. paid or ad-funded content) Hosted Compute 2. Service prepares a Shared Access Signature (SAS) to X using the securely stored storage account key Stg Key 3. Service returns SAS (signed HTTPS URL) 4. Bob uses SAS to access X directly from Blob Storage for reduced latency & compute load Blob Storage X

  10. Serve Blobs from the Edge • 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 Blob header determines time-to-live at the edge DNS name resolves to closest POP Possibly many hops or poor links Public container CDN Few hops Blob Storage Closest Point of Presence X X

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

  12. Managing CDN Content Expiration Default behaviour 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 HTML Served by App BlobStorage CDN … <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" />… logo.2011-08-01.png logo.2011-08-01.png logo.2011-09-16.png logo.2011-09-16.png • Enables easy rollback and A/B testing

  13. CDN for Web Apps CDN supports your web app as an origin Normal 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 supported http://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 CDN http://blogs.msdn.com/b/scicoria/archive/2011/07/10/hosted-service-as-a-windows-azure-cdn-origin-tips.aspx

  14. 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) 1.2.3.4 foo.cloudapp.net foo-us.cloudapp.net Traffic Manager foo-europe.cloudapp.net Policies Monitoring DNS response foo-asia.cloudapp.net

  15. Traffic Manager Details 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 foo-us.cloudapp.net foo-europe.cloudapp.net Monitoring Periodic GETs /monitoring/testme.aspx foo-asia.cloudapp.net

  16. In-Memory Caching • 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 Storage Table Storage

  17. Windows Azure Caching 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 Cache Client-local near cache for hot data without serialization costs

  18. Partitioning & Sharding • Trick #5: • 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 WA Storage Acct WA Storage Acct WA Storage Acct Partitioned Table Partitioned Table Partitioned Table Queue Queue Queue Blob Blob Blob Hosted Compute

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

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

  21. Basic Performance Tuning 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

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

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

  24. Summary Approach WA apps like you would on-premises apps Use rich platform features in Windows Azure to tune for the cloud too • Cache control Versioned URLs • Blob Storage CDN Public Web App Public Private Traffic Mgr • Caching Table Storage Table Storage • Shared Access Signatures Asynchronous Hosted Compute Asynchronous Hosted Compute Synchronous Hosted Compute Asynchronous Hosted Compute Stg Key Stg Key Stg Key Stg Key Stg Key Tuning SQLAzure SQL Azure SQL Azure • Sharding

More Related