Download
building scalable web apps with windows azure n.
Skip this Video
Loading SlideShow in 5 Seconds..
Building scalable web apps with Windows Azure PowerPoint Presentation
Download Presentation
Building scalable web apps with Windows Azure

Building scalable web apps with Windows Azure

517 Views Download Presentation
Download Presentation

Building scalable web apps with Windows Azure

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. SAC-870T Building scalable web apps with Windows Azure Matthew Kerner Principal Program Manager Microsoft Corporation

  2. Agenda WHO WILL BENEFIT FROM THIS TALK TOPICS WHAT YOU’LL LEAVE WITH • Windows Azure helps you build scalable web apps • using the approaches that you’re already familiar with. • Asynchronous patterns & techniques • Managing data access • Tuning application performance • Web app developers • who are already familiar with Windows Azure • with scaling needs.

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

  5. Async/await support simplifies bookkeeping • voidUploadImage(Stream image, CloudBlobdestBlob) • { • // Add image to list in SQL Azure • AddImageToSQLAzure(destBlob.Uri); • // Upload image to blob storage • UploadImageToBlob(image, destBlob); • } asyncTaskUploadImageAsync(Stream image, CloudBlobdestBlob) { // Add image to list in SQL Azure vart1 = AddImageToSQLAzureAsync(destBlob.Uri); // Upload image to blob storage vart2 = UploadImageToBlobAsync(image, destBlob); awaitTaskEx.WhenAll(t1, t2); } But how do we make one of these?

  6. Creating async methods from begin/end pairs asyncTaskUploadImageToBlobAsync (Stream image, CloudBlobdestBlob) { // Task.Factory.FromAsync method creates a Task or Task<T> to // represent a Begin/End async invocation awaitTask.Factory.FromAsync<Stream>(destBlob.BeginUploadFromStream, destBlob.EndUploadFromStream, image, null); } voidUploadImageToBlob (Stream image, CloudBlobdestBlob) { destBlob.UploadFromStream(image); }

  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 • 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) Blob Storage Hosted Compute Hosted Compute

  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 2. Service prepares a Shared Access Signature (SAS) to X using the securely stored storage account key 1. “I am Bob & I want X” Hosted Compute Stg Key 3. Service returns SAS (signed HTTPS URL) Blob Storage 4. Bob uses SAS to access X directly from Blob Storage for reduced latency & compute load Non-public blob (e.g. paid or ad-funded content) 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 Possibly many hops or poor links Few hops CDN Blob Storage Closest Point of Presence Public container X X Blob header determines time-to-live at the edge DNS name resolves to closest POP

  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 devportal • 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 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 HTML Served by App Blob Storage CDN … <imgsrc="http://azXXXX.vo.msecnd.net/images/logo.2011-09-16.png" />… … <imgsrc="http://azXXXX.vo.msecnd.net/images/logo.2011-08-01.png" />… logo.2011-08-01.png logo.2011-08-01.png logo.2011-09-16.png logo.2011-09-16.png

  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) foo-us.cloudapp.net Traffic Manager foo.cloudapp.net foo-europe.cloudapp.net DNS response Monitoring Policies 1.2.3.4 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 Periodic GETs Monitoring /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 SQL Azure SQL Azure Hosted Compute Table Storage Table Storage

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

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

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

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

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

  23. For more information RELATED SESSIONS DOCUMENTATION & ARTICLES Tutorials for improving performance on Windows Azure: http://www.microsoft.com/windowsazure/learn/improve-performance/ 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 CONTACT: matthew.kerner@microsoft.com

  24. thank you Feedback and questions http://forums.dev.windows.com Session feedbackhttp://bldw.in/SessionFeedback

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