Azure providers - Bouvet BigOne 2011

21
Inge Henriksen IT consultant @ Bouvet Microsoft dep. in Oslo mailto:[email protected] Azure Providers Azure Cloud Web Application with memberships in 1-2-3 http://AzureProviders.codeplex.com

description

Windows Azure Cloud Web Application with memberships in 1-2-3

Transcript of Azure providers - Bouvet BigOne 2011

Page 1: Azure providers - Bouvet BigOne 2011

Inge HenriksenIT consultant @ Bouvet Microsoft dep. in Oslomailto:[email protected]

Azure ProvidersAzure Cloud Web Application with memberships in 1-2-3http://AzureProviders.codeplex.com

Page 2: Azure providers - Bouvet BigOne 2011

http://azureproviders.codeplex.com 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); the physical computer infrastructure

4/13/2011

Page 3: Azure providers - Bouvet BigOne 2011

http://azureproviders.codeplex.com 3

*Windows Azure Storage

*Tables; Structured storage in a key/value manner

*Queues; queueing mechanism with storage for reliable messaging

*Blobs; storage for large binary files

*Drives; external memory in the form of NTFS volumes

*REST or Managed API’s

4/13/2011

Page 4: Azure providers - Bouvet BigOne 2011

http://azureproviders.codeplex.com 4

*Windows Azure Tables

*Structured storage

*Scalable; automatically distributes over server instances

*Can contain billions of rows and up to 100 TB per storage

*High availability; data is replicated several times

*Use REST, or use ADO.NET Data Services with .NET classes or LINQ

4/13/2011

Page 5: Azure providers - Bouvet BigOne 2011

http://azureproviders.codeplex.com 5

*Windows Azure Tables

*Part of the NoSQL movement

*Supports declerative queries using LINQ

*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

Page 6: Azure providers - Bouvet BigOne 2011

http://azureproviders.codeplex.com 6

*Windows Azure Table Storage

Concepts

Accounts Tables Entities

Henriksen

Users

SessionState

Roles

[email protected]

[email protected]

Expires=20/2/12Key=123213123

Expires=21/3/12Key=534554335

4/13/2011

Page 7: Azure providers - Bouvet BigOne 2011

http://azureproviders.codeplex.com 7

*Windows Azure Table Entity

definition4/13/2011

Page 8: Azure providers - Bouvet BigOne 2011

http://azureproviders.codeplex.com 8

*Windows Azure Table Partitioning

*Each partition is distributed over many storage nodes

*Autmatic monitoring and balancing of load on partitions

*Use Guid as parition key for a more even spread across storage nodes

*Only partitionkey is indexed

*Rowkey is often omitted, except for versioning

4/13/2011

Page 9: Azure providers - Bouvet BigOne 2011

http://azureproviders.codeplex.com 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

Page 10: Azure providers - Bouvet BigOne 2011

http://azureproviders.codeplex.com 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

Page 11: Azure providers - Bouvet BigOne 2011

http://azureproviders.codeplex.com 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

Page 12: Azure providers - Bouvet BigOne 2011

http://azureproviders.codeplex.com 12

*Azure ProvidersSystem

Requirements

*For use:

*An Microsoft Azure account

*For development:

*Visual Studio 2010

*Azure SDK 1.4

*Azure Tools for Visual Studio 2010 V1.3

*Microsoft SQL Server Express

4/13/2011

Page 13: Azure providers - Bouvet BigOne 2011

http://azureproviders.codeplex.com 13

*Azure ProvidersGetting Started

* 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 statickey appsetting in the web.config file before going public since this is the encryption key, or use machine key instead.

4/13/2011

Page 14: Azure providers - Bouvet BigOne 2011

http://azureproviders.codeplex.com 14

*Azure ProvidersMembership

Provider

*Handles user sign in/out

*Several ASP.NET controls supports the provider

*AzureMembershipProvider.cs

*Uses Azure Table Storage and Queues for e-mail

*Web.config definition:

4/13/2011

Page 15: Azure providers - Bouvet BigOne 2011

http://azureproviders.codeplex.com 15

*Azure ProvidersAzure Queue

usage

*E-mail are placed on the queue for asyncronious work

*EmailAgent worker role processes items in the queue

*AzureQueueDataSource.cs is Queue data source

*Change mail server app.config settings in EmailAgent project:

4/13/2011

Page 16: Azure providers - Bouvet BigOne 2011

http://azureproviders.codeplex.com 16

*Azure ProvidersProfile Provider

*Handles all user profile data

*Uses Azure Table Storage and Azure Blob Storage

*AzureProfileProvider.cs

4/13/2011

Page 17: Azure providers - Bouvet BigOne 2011

http://azureproviders.codeplex.com 17

*Azure ProvidersProfile Provider

*User portraits are stored in the Azure Blob Storage

*Web.config settings:

4/13/2011

Page 18: Azure providers - Bouvet BigOne 2011

http://azureproviders.codeplex.com 18

*Azure ProvidersRole Provider

*Handles user roles

*Uses the Azure Table Storage

*AzureRoleProvider.cs

*Web.config settings:

4/13/2011

Page 19: Azure providers - Bouvet BigOne 2011

http://azureproviders.codeplex.com 19

*Azure ProvidersSession-State

Provider

*Handles session-state across server instances

*Standard ASP.NET session-state is in-process

*Uses the Azure Table Storage

*Web.config settings:

4/13/2011

Page 20: Azure providers - Bouvet BigOne 2011

http://azureproviders.codeplex.com 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

Page 21: Azure providers - Bouvet BigOne 2011

http://azureproviders.codeplex.com 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