1. Azure Providers Azure Cloud Web Application with memberships in 1-2-3 http://AzureProviders.codeplex.com Inge Henriksen IT consultant @ Bouvet Microsoft dep.in Oslo mailto:inge.henriksen@bouvet.no
2. What is «The Cloud»? Software as a Service (SaaS); ex. Exchange Online Platform as a Service (PaaS); ex. Azure Services Platform Infrastructure as a Service (IaaS); thephysical computer infrastructure 4/13/2011 http://azureproviders.codeplex.com 2
3. Windows Azure Storage Tables; Structuredstorage in a key/value manner Queues; queueingmechanismwithstorage for reliable messaging Blobs; storage for largebinary files Drives; externalmemory in the form of NTFS volumes REST or ManagedAPI’s 4/13/2011 http://azureproviders.codeplex.com 3
4. Windows AzureTables Structuredstorage Scalable; automaticallydistributes over server instances Cancontain billions ofrowsand up to 100 TB per storage High availability; data is replicatedseveral times Use REST, or use ADO.NET Data Services with .NET classes or LINQ 4/13/2011 http://azureproviders.codeplex.com 4
5. Windows AzureTables Part oftheNoSQLmovement Supports declerativequeriesusingLINQ Flexible entity definition but no constraints Very affordable and only gets more expensive when your application grows Distributed queries makes it really fast Big minus is having only one index per table 4/13/2011 http://azureproviders.codeplex.com 5
8. Windows AzureTablePartitioning Eachpartition is distributed over manystorage nodes Autmaticmonitoring and balancingofload on partitions Use Guid as parition key for a more evenspreadacrossstorage nodes Onlypartitionkey is indexed Rowkey is oftenomitted, except for versioning 4/13/2011 http://azureproviders.codeplex.com 8
9. Azure Providers Project Description Complete ASP.NET solution that uses the Azure Table Storage and Azure Blob storage as a data source for a custom Membership, Role, Profile, an Session-State providers 4/13/2011 http://azureproviders.codeplex.com 9
10. Azure ProvidersFeatures Complete membership provider that stores data in the Azure Table Storage Complete role provider that stores data in the Azure Table Storage Complete profile provider that stores data in the Azure Table Storage and Blob Storage Complete Session-State Provider that uses the Azure Table Storage so that you can maintain session-state between server instances in the Azure cloud (New in V1.1.6360) All e-mail sent from the application is handled by a worker role that picks e-mails from the Azure Queue (New in V1.1.6360) Register account page with e-mail confirmation and Question/Answer Sign In page with automatic locking after too many failed attempts 4/13/2011 http://azureproviders.codeplex.com 10
11. Azure ProvidersFeatures Sign Out functionality Change Password page with e-mail confirmation Reset Password page where new password is sent to e-mail account Locked account functionality where user can unlock account using link sent to users e-mail account User e-mail validation by using link sent after account validation, account is not activated before e-mail is validated User profile page where user can set his/her gender and upload a profile image that is stored as a Azure Blob (Automatic thumbnail creation added in V1.1.6360) Admin page that shows an overview of all the roles Admin page that shows some site statistics Admin page that shows an overview of all the users 4/13/2011 http://azureproviders.codeplex.com 11
12. Azure ProvidersSystem Requirements For use: An Microsoft Azureaccount For development: Visual Studio 2010 Azure SDK 1.4 Azure Tools for Visual Studio 2010 V1.3 Microsoft SQL Server Express 4/13/2011 http://azureproviders.codeplex.com 12
13. Azure ProvidersGettingStarted Make sure you have all the prerequisites Download the source and unzip it to a folder on your PC Open VS 2010 as an administrator (Azure development storage require this) Find and open the AzureProviders.sln solution from Visual Studio 2010 Change the SMTP-server to one that works for you in app.config under Email Agent -> system.net -> mailsettings -> smtp -> network Run the solution from Visual Studio 2010 You should see the Initialize Application page first time you run the solution, this creates all the Azure tables and some default content like users and roles etc Sign in with the Admin user (default user name is "Admin" and default password is "Password") You should change the statickeyappsetting in the web.config file before going public since this is the encryption key, or use machine key instead. 4/13/2011 http://azureproviders.codeplex.com 13
14. Azure ProvidersMembership Provider Handles usersign in/out Several ASP.NET controls supports the provider AzureMembershipProvider.cs UsesAzureTable Storage and Queues for e-mail Web.configdefinition: 4/13/2011 http://azureproviders.codeplex.com 14
15. Azure ProvidersAzure Queue usage E-mail areplaced on thequeue for asyncroniouswork EmailAgentworkerroleprocessesitems in thequeue AzureQueueDataSource.cs is Queue data source Change mail server app.config settings in EmailAgentproject: 4/13/2011 http://azureproviders.codeplex.com 15
16. Azure ProvidersProfile Provider Handles all userprofile data UsesAzureTable Storage and AzureBlob Storage AzureProfileProvider.cs 4/13/2011 http://azureproviders.codeplex.com 16
17. Azure ProvidersProfile Provider User portraitsarestored in theAzureBlob Storage Web.config settings: 4/13/2011 http://azureproviders.codeplex.com 17
19. Azure ProvidersSession-State Provider Handles session-state across server instances Standard ASP.NET session-state is in-process UsestheAzureTable Storage Web.config settings: 4/13/2011 http://azureproviders.codeplex.com 19
20. Lessons LearnedIn General Only one table storage index is cumbersome Use Azure Queue together with worker roles for asynchronous work like sending e-mails etc Azure really cheap for start-ups even if you plan to be big (pay-as-you-go) No table storage constraints is bad LINQ as a table storage declerative query language works great, but with some issues Table storage only support simple data types like integers, strings, booleans, doubles, datetime’s, Guids, and binaries smaller than 64 Kb Queue does not support events out-of-the box so you have to poll the queue yourself using a timer which is stupid Don’t share AzureServiceContext’s between threads, it will crash Use DataServiceContext.Detach and DataServiceContext.AttachTo before update and delete in the table storage unless you are certain that you are working on the same partition key item Always use TableServiceContext.SaveChangesWithRetires and not TableServiceContext.SaveChanges as you have no guaranties of success with optimistic locking 4/13/2011 http://azureproviders.codeplex.com 20
21. Lessons LearnedPerformance Use parallel LINQ queries rather than «OR» in your queries Bulk updates/inserts are very fast, but I still have not found a use for it Use GUID’s as partition keys to spread load RowKey should be empty to spread load Normalize table store data to 5th normal form only where needed to save storage space and to optimize queries where needed Use Azure Content Delivery Network to distribute your Azure Blob files where needed for optimal performance Never do queries that does not primerly use the partition key as a query parameter as these will trigger whole table scans Know that the Managed objects are just REST wrappers, so use tiny interchange formats like JSON and not XML. XML will take longer to transfer and cost you more money in Azure data transfer costs Check the CloudQueueMessage.DequeueCount property before staring jobs from Azure Queue messages to avoid buggy messages hanging around forever AzureServiceContext instances should have a short lifetime to avoid locking issues 4/13/2011 http://azureproviders.codeplex.com 21