Cloud e Web con Windows AZURE e ASP.NET MVC 3

104
Microsoft Academic Tour 2011 Cloud e Web con Windows AZURE e ASP.NET MVC 3 Speakers: Antimo Musone e Daniele Midi [email protected] [email protected] Facoltà di Ingegneria,Tor Vergata,12 Dicembre 2011

description

Facoltà di Ingegneria,Tor Vergata,12 Dicembre 2011. Cloud e Web con Windows AZURE e ASP.NET MVC 3. Speakers: Antimo Musone e Daniele Midi [email protected] [email protected]. About We. Antimo Musone Cloud Development Tour Owner Daniele Midi - PowerPoint PPT Presentation

Transcript of Cloud e Web con Windows AZURE e ASP.NET MVC 3

Page 1: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Microsoft Academic Tour 2011

Cloud e Web con Windows AZURE e ASP.NET MVC 3

Speakers: Antimo Musone e Daniele [email protected]@studentpartner.com

Facoltà di Ingegneria,Tor Vergata,12 Dicembre 2011

Page 2: Cloud e Web con Windows AZURE e ASP.NET MVC 3

About We

Antimo MusoneCloud Development Tour Owner

Daniele MidiWeb Development Tour Owner

Web Team

Page 3: Cloud e Web con Windows AZURE e ASP.NET MVC 3

AgendaCloud Platform

Why Cloud ? Windows Azure

HostingApp ModelsManagement

Demo

Hello World Windows Azure

StorageInteroperability

MVC 3 Web App

MVC 3 in AzureDemo MVC3

Page 4: Cloud e Web con Windows AZURE e ASP.NET MVC 3

START WITH : Cloud

Antimo MusoneCloud Development Tour Owner

Page 5: Cloud e Web con Windows AZURE e ASP.NET MVC 3

What is the cloud?

An approach to computing that’s about internet scale and connecting to a variety of

devices and endpoints

Page 6: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Why Cloud?Customer Requirements :• Efficency, Reliability

• Scalability , Agility

• Reduce IT Costs

IT Consultants• Don’t must be IT warriors

• Can delegate IT Problems

Page 7: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Cloud Computing Patterns

Usage

Com

pute

Time

Average

InactivityPeriod

“On and Off “

On & off workloads (e.g. batch job)

Com

pute

Time

“Unpredictable Bursting“

Average Usage

Unexpected/unplanned peak in demand

Average Usage

Com

pute

Time

“Growing Fast“

Successful services needs to grow/scale

Com

pute

Time

Average Usage

“Predictable Bursting“

Services with micro seasonality trends

Page 8: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Cloud Services

Software-as-a-Serviceconsume

“SaaS”Platform-as-a-Service

build

“PaaS”Infrastructure-as-a-Service

host

“IaaS”

Page 9: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Caso Cloud: Il Censimento • 500 000 connessione in

un solo giorno

• Carico di workload inaspettato

• In tilt dopo poche ore dal lancio

• Raddoppiata l’infrastruttura IT in una sola Notte

• Infrastuttura Cloud : Telecom Italia

Page 10: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Windows Azure PlatformScalable compute and storageAutomated service managementFamiliar tools, technologies, languages

Relational storage for the cloudConsistent development modelAutomated database management

Connect existing apps to the cloudConnect through network boundariesEasily control authorization to apps

Page 11: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Windows Azure Platform : Layers

Fabric Controller Windows Azure Networking

AppFabric Caching

AppFabric Access Control

SQL Azure

AppFabric Service Bus

“Red Dog” Front End (RDFE)Compute Services

Middleware Services

Windows Azure Storage

Windows Azure CDN

Data Services

Page 12: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Windows Azure Platform Data Centers

North America Region

Europe Region

Asia Pacific Region

6 datacenters across 3 continentsSimply select your data center of choice when deploying an application

S. Central – U.S.

W. Europe

N. Central – U.S.

N. Europe

S.E. Asia

E. Asia

Page 13: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Windows AzureCompute

Page 14: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Windows Azure PlatformComponents Horizontal View

Virtual NetworkCompute Storage

Page 15: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Windows AzureWindows Azure is a foundation of Microsoft’s Cloud Platform for Developers Operating System for the Cloud

• Runs applications in the cloud• Provides Storage• Application Management• Developer SDK

Windows Azure ideal for applications needing• Scalability• Availability• Fault Tolerance

Page 16: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Operating System

Operating System

VM

WebServer

Operating System

VM

DBMS

3) Choose image, then

create and

configure VM(s) for applicati

on

1) Choose image, then

create VM for DBMS and configure

DBMS

IaaS

Library

VM Images

Developer

Application Load Balancer

5) Configure

loadbalancer

6) Manage VMs and DBMS (e.g., deploying new OS images in

VMs)

2) Provision database, then create tables and add data

4) Install applicatio

n

Page 17: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Operating System

Operating System

VM

Operating System

VM

DBMS

PaaSDeveloper

Application

2) Deploy application

WebServer

1) Provision database, then

create tables and add data

Load Balancer

3) Manage Applications

Page 18: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Operating System

Operating System

VM

RoleApplicatio

n

Operating System

VM

DBMS

PaaS - AzureAzure Developer

ApplicationLoad

Balancer

3) Install Other application2) Deploy

application1) Provision

database, then create tables and

add data 4) Manage VM & Applications

Other Application

Page 19: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Windows Azure in 1 Slide

Desktop

VS Tools

WA SDK Stor

age

Clus

ter

MSFT Datacenters

Developer Portal

Com

pute

Clu

ster

……

Service Management Service

API REST

Cloud VM

Runtime API

VM Setup

User Code

RDP

Page 20: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Azure Role :Scale Application Archetype

Page 21: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Azure Scale Applications: LayersIntelligent Network : Load

Balancer

Stateless ‘Worker’ Machines : Worker Role

Stateless Web Application : Web Role

Async Work

Shared Filesyste

mPartitioned RDBMS

Key/Value

Datastores

Data /State Tier Queues

Page 22: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Azure Scale Applications: Roles

StorageTables

LB

Blobs

Worker ServiceWorker Service

Worker Role

Managed Interface Call

Web Site(ASPX, ASMX,

WCF)Web Site(ASPX, ASMX,

WCF)Web RoleIIS as Host

Queues

Windows Azure Data Center

LBL

B

The Internet via HTTP/TCP

Page 23: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Role

In

terfa

ce

OnStartMethods

Fabric Calls

Run

OnStop

Events

BusyStatus

StatusCheck

Stopping

Ready

Busy

StatusCheck

StatusCheck

Role Lifetime

Requests RoutedAzure Role: Application BoxRole is an application container, that run inside Azure VM, through it we can provide Web / Service / Standalone Applications and also offers an interface to manage it

Page 24: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Services,Roles and InstancesA Service is a packaged application for Azure, composed by one or more roleRoles are defined in a Service Model

• May define one or more Roles per Service• A role definition specifies

VM sizeCommunication EndpointsLocal storage resourcesEtc…

At runtime each Role will execute on one or more instances (up to 20 per subscription)

• A role instance is a set of code, configuration, and local data, deployed in a dedicated VM

Page 25: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Worker Role PatternsQueue Polling Worker

• Poll and Pop Messages within while(true) loop• E.g. Map/Reduce pattern, background image processing

Listening Worker Role• Create TcpListener or WCF Service Host• E.g. Run a .NET SMTP server or WCF Service

External Process Worker Role• OnStart or Run method executes Process.Start()• Startup Task installs or executes background/foreground process• E.g. Run a database server, web server, distributed cache

Page 26: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Web RoleAll features of a worker role + IIS 7 or 7.5MVC 3 , ASP.NET 3.5 SP1 or 4.0 – 64bitHosts

• Webforms or MVC• FastCGI applications (e.g. PHP)• Multiple Websites

Http(s)Web/Worker Hybrid

• Can optionally implement RoleEntryPoint

Page 27: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Service DefinitionDescribes the shape of your Windows Azure Service

• Defines Roles

• Ports, Certificates

• Configuration

• Startup Tasks

• IIS Configuration

Page 28: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Service ConfigurationSupplies Runtime Values, can be updated any time through Portal or API

• Scale

• Config Settings

• Certificates to use,

• VHD

• etc.

Page 29: Cloud e Web con Windows AZURE e ASP.NET MVC 3

VM Size in Windows AzureWindows Azure

• Supports Various VM Sizes• Size set on Role in Service Definition• Service can have multiple roles• Balance of Performance per node vs. High Availability from multiple

nodes• Set in Service Model definition All instances of role will be of equal size

Size CPU Cores RAM Local Storage Cost ( $/Hour)Extra Small Shared 768M 20GB .05Small 1 1.7GB 250GB .12Medium 2 3.5GB 500GB .24Large 4 7GB 1000GB .48Extra large 8 15GB 2000GB .96

Page 30: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Windows Azure Platform Portal• Web Access to : https://windows.azure.com• Supports multiple service

administrators (co-admins)• Enable and connect to

Windows Azure instances using Remote Desktop

• Built on the Windows Azure Service Management APIs

Page 31: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Hello World by Windows Azure

Demo

Page 32: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Windows Azure

Storage

Page 33: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Windows Azure StorageStorage in the Cloud

• Scalable, durable, and available• Anywhere at anytime access• Only pay for what the service uses

Exposed via RESTful Web Services• Use from anywhere on the internet

User specified globally unique account nameCan call these from any HTTP client (Flash, Silverlight )

Various storage abstractions• Tables, Blobs, Queues, Drives

100TB per account, have two independent 512 bit shared secret keys

Page 34: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Blob Storage

Page 35: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Blob Storage Concepts

BlobContainer

Account

contoso

images

PIC01.JPG

videos VID1.AVI

http://<account>.blob.core.windows.net/<container>/<blobname>

Pages/Blocks

Block/Page

Block/Page

PIC02.JPG

Page 36: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Blob DetailsMain Web Service Operations

• PutBlob,GetBlob• DeleteBlob,CopyBlob• SnapshotBlob ,LeaseBlob

Associate Metadata with Blob• Standard HTTP metadata/headers

(Cache-Control, Content-Encoding, Content-Type, etc)• Metadata is <name, value> pairs, up to 8KB per blob• Either as part of PutBlob or independently

Blob always accessed by name• Can include ‘/‘ or other delimeter in name

e.g. /<container>/myblobs/blob.jpg

Page 37: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Blob ContainersMultiple Containers per Account

• Special $root container

Blob Container• A container holds a set of blobs• Set access policies at the container level • Associate Metadata with Container• List the blobs in a container

• Including Blob Metadata and MD5 • NO search/query. i.e. no WHERE MetadataValue = ?

Blobs Throughput• Effectively in Partition of 1• Target of 60MB/s per Blob

Page 38: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Table Storage

Page 39: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Table Storage Concepts

EntityTableAccount

contoso

customersName =…Email = …

Name =…EMailAdd= …

photosPhoto ID =…

Date =…

Photo ID =…Date =…

http://<account>.table.core.windows.net/<tablename>

Page 40: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Table DetailsIt’s not an RDBMS system but it’ s a container where we can serialize a collection of objectsTable Operations :

• Create, Query, Delete• Tables can have metadata

Entities Operations :• Insert,Delete• Update

• Merge – Partial update• Replace – Update entire entity

• Query• Entity Group Transactions

• Multiple CUD Operations in a single atomic transaction

Page 41: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Entity PropertiesEntity can have up to 255 properties ( members of class )

• Up to 1MB per entity

Mandatory Properties for every entity• PartitionKey & RowKey (only indexed properties)• Uniquely identifies an entity• Defines the sort order• Timestamp • Optimistic Concurrency. Exposed as an HTTP ETag

No fixed schema for other properties• No schema stored for a table• Properties can be the standard types:

String, binary, bool, DateTime, GUID, int, int64, and double

Page 42: Cloud e Web con Windows AZURE e ASP.NET MVC 3

First Last Birthdate

Kim Akers 2/2/1981

Nancy Anderson 3/15/1965

Mark Hassall May 1, 1976

Querying

?$filter=Last eq ‘Akers’http://antimo.table.core.windows.net/Accounts

http://<account>.table.core.windows.net/<tablename>

Page 43: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Queue Storage

Page 44: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Queue Storage Concepts

MessageQueueAccount

order processing

customer ID order ID http://…

customer ID order ID http://…

adventureworks

http://<account>.queue.core.windows.net/<queuename>

Page 45: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Loosely Coupled Workflow with QueueEnables workflow between roles

• Load work in a queueProducer can forget about message once it is in queue

• Many workers consume the queue• For extreme throughput use multiple queues or multiple work items per

message

QueueInput Queue (Work Items)

Web Role

Web Role

Web Role

Worker Role

Worker Role

Worker Role

Worker Role

Page 46: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Queue DetailsSimple asynchronous dispatch queue

• No limit to queue length subject to storage limit• 8kb per message• ListQueues - List queues in account

Queue operations • CreateQueue ,DeleteQueue• Get/Set Metadata• Clear Messages

Message operations• PutMessage– Reads message and hides for time period• GetMessages – Reads one or more messages and hides them• PeekMessages – Reads one or more messages w/o hiding them• DeleteMessage – Permanently deletes messages from queue

Page 47: Cloud e Web con Windows AZURE e ASP.NET MVC 3

SQL AZUREDatabase

Page 48: Cloud e Web con Windows AZURE e ASP.NET MVC 3

SQL AzureExtending SQL Server to the Cloud

Data Sync

Database

Reporting

Page 49: Cloud e Web con Windows AZURE e ASP.NET MVC 3

SQL Azure DatabaseFamiliar SQL Server relational database model delivered as a service

• Support for existing APIs & tools• Built for the cloud with high availability & fault tolerance• Easily provision and manage databases across multiple datacenters

SQL Azure provides logical server• Gateway server that understands TDS protocol• Looks like SQL Server to TDS Client• Actual data stored on multiple backend data nodes

Logical optimizations supported• Indexes, Query plans etc..

Physical optimizations not supported• File Groups, Partitions etc…

Transparently manages physical storage

Page 50: Cloud e Web con Windows AZURE e ASP.NET MVC 3

SQL AzureSQL Azure Use & Deployment :

Web Portal(API)

SQL AzureTDS

DB Script

SQL Server Managment

Custom Tool

Page 51: Cloud e Web con Windows AZURE e ASP.NET MVC 3

SQL Azure Data SyncGeo-replication of SQL Azure data and spanning on-premises with cloud

• geo-replication• sync between SQL Server and

SQL AzureBuilds on Sync Framework

• Sync data between SQL Azure, SQL Compact and SQL Server

On-Premises

Cloud Offline Clients

Page 52: Cloud e Web con Windows AZURE e ASP.NET MVC 3

AZUREInteroperability

Page 53: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Development & InteroperabilityMicrosoft & Partners provide development tools & sdk to design/develop Web Apps & Services on Azure Platform

Windows Azure SDK & Training Kit : A step by step helper , provide a full developer local environment to develop and test Azure Apps

• Development Fabric: simulate in local Windows Azure SO• Development Storage: : simulate in local Windows Azure Storage

Not only tools for Microsoft Platform but also Windows Azure Team provide tools for Eclipse , Java and many other open source technology

C / C++Win32 VHD

Page 54: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Azure + Phone 1 / 2Phone• Connection• Smart• Marketplace

Azure• Services• Scalability

Azure Key Word : Interoperability

Page 55: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Azure + Phone 2 / 2

Azure Apps

Development Tools & Interoperability with all mobile platforms

Azure Datacenters

Page 56: Cloud e Web con Windows AZURE e ASP.NET MVC 3

SWITCH TO : Web

Daniele MidiWeb Development Tour Owner

Page 57: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Coffee break(5 min)

Page 58: Cloud e Web con Windows AZURE e ASP.NET MVC 3

PATTERNS:MVC ORIGINALE,MVC MODEL2,ASP.NET MVC.

Page 59: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Parleremo di...Pattern MVCMVC secondo MicrosoftGestione dei datiWeb Apps per il Cloud

Page 60: Cloud e Web con Windows AZURE e ASP.NET MVC 3

PATTERNS:MVC ORIGINALE,MVC MODEL2,ASP.NET MVC.

Page 61: Cloud e Web con Windows AZURE e ASP.NET MVC 3

MVC: formulazione originaleE’ un pattern architetturale che risolve il problema di disaccopiare la logica di interfaccia da quella di dominio.

Model

View Controller

Observer

Page 62: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Model

View Controller

Model

View Controller

MVC adattato al Web (Model 2)

”Skinny

Controller, Fat Model and

Dumb View

“(RubyOnRails devs)

Page 63: Cloud e Web con Windows AZURE e ASP.NET MVC 3

MVC secondo MicrosoftBR

OWSE

R

ROUT

ING

ENGI

NEController

Model

View

1 2

34

5

6

Page 64: Cloud e Web con Windows AZURE e ASP.NET MVC 3

ATTORI:CONTROLLER, ACTION, ROUTING, VIEWMODEL, VIEW, MODELBINDER.

Page 65: Cloud e Web con Windows AZURE e ASP.NET MVC 3

ControllerE’ una classe.Convention-over-configuration: per convenzione, la classe del Controller deve chiamarsi “NomeControllerController”

– es.: “AnnunciController”Contiene la logica di interazione per un certo numero di “pagine” logicamente collegate

– es.: AnnunciController potrebbe:• visualizzare l’elenco degli annunci• vedere i dettagli di un annuncio• aggiungere un nuovo annuncio

Page 66: Cloud e Web con Windows AZURE e ASP.NET MVC 3

ActionE’ un metodo di un Controller.Quando l’utente richiede l’esecuzione di una certa “azione” (visualizzare i dettagli di un annuncio, crearne uno nuovo, …) viene invocata la relativa Action.

La Action esegue della logica applicativa e poi restituisce un oggetto ActionResult, che sarà utilizzato per mostrare i risultati all’utente in una “pagina” (la View).

ActionFilter Action ActionRes

ult

Page 67: Cloud e Web con Windows AZURE e ASP.NET MVC 3

RICHIESTA

HomeControllerIndex ()

About ()

AnnunciControllerIndex ()

Details (int id)

Create ()

?

Page 68: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Routing engine

ROUTING ENGINE

routes.MapRoute( "Default", "{controller}/{action}/{id}", new {

controller = "Home", action = "Index", id = UrlParameter.Optional });

www.ilmiosito.com/Annunci/Details/12

www.ilmiosito.com/Annunci/Details/12Annunci Details 12

CONTROLLER IDACTION

AnnunciController.Details(12)

Page 69: Cloud e Web con Windows AZURE e ASP.NET MVC 3

DEMO:Creazione di un’applicazione Web con ASP.NET MVC

Page 70: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Model (anzi, ViewModel)Il Model in ASP.NET MVC fa da intermediario fra Controller e View

– permette di tipizzare i dati scambiati fra Controller e ViewSi parla allora di ViewModel:

– Classi create ad uso e consumo delle View– Classi completamente anemiche (solo attributi)

Page 71: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Validazione: Data AnnotationsDato che i ViewModel nascono prettamente per tipizzare i dati scambiati con la view, possono essere usate anche per definire le regole di validazione e rendering della view che le consuma.In .NET possiamo indicare tali informazioni con dei semplici attributi chiamati Data Annotations:

Page 72: Cloud e Web con Windows AZURE e ASP.NET MVC 3

View Loosely-TypedASP.NET MVC < 3: ViewData– ACTION

ViewData[“Messaggio”] = “Benvenuto!”;ViewData[“Cliente”] = new Customer();

– VIEW<%: ViewData[“Messaggio”] %><%: (ViewData[“Cliente”] as Cliente).Nome %>

ASP.NET MVC 3: dynamic ViewBag + Razor– ACTION

ViewBag.Messaggio = “Benvenuto!”;

ViewBag.Cliente = new Customer();– VIEW

@[email protected]

Page 73: Cloud e Web con Windows AZURE e ASP.NET MVC 3

View Strongly-TypedInizia con una dichiarazione @model T

– es.: una View che mostri i dettagli di una Sessione può iniziare con la dichiarazione @model Sessione

È una normale pagina WebT è il ViewModel

– un “modello” della View: raggruppa in una classe i dati che la View deve mostrare e gestire

Vantaggi:– Intellisense– Controlli alla compilazione

Page 74: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Model Binder: tipi primitivi

MODEL BINDE

R

QUERYSTRINGwww.contoso.com/Libri/Details/?

id=12

URL PARAMETERwww.contoso.com/Libri/Details/12

HTML FORMSACTION del CONTROLLER “Libri”

public ActionResult Details(int id)

Page 75: Cloud e Web con Windows AZURE e ASP.NET MVC 3

HTML FORM<form action=“/Persone/Edit”> <input type=“text” name=“persona.Nome” /> <input type=“text” name=“persona.Cognome” /> <input type=“text” name=“persona.Eta” /></form>

HTML FORM<form action=“/Persone/Edit”> @Html.TextBoxFor(model => model.Nome) @Html.TextBoxFor(model => model.Cognome) @Html.TextBoxFor(model => model.Eta)</form>

Model Binder: oggettiCLASSE “PERSONA”public string Nome { get; set; }public string Cognome { get; set; }public int Eta { get; set; }

MODEL BINDER

ACTION del CONTROLLER “Persone”public ActionResult Edit(Persona persona)

Page 76: Cloud e Web con Windows AZURE e ASP.NET MVC 3

DEMO:ViewModel, Data Annotation e Strongly-Typed Views

Page 77: Cloud e Web con Windows AZURE e ASP.NET MVC 3

ASP.NET MVC PER WINDOWS AZURE:BEH, CHE PROBLEMA C’È?

Page 78: Cloud e Web con Windows AZURE e ASP.NET MVC 3

StatelessnessLoad balancer round-robins requests in multi instance rolesFollow web farm best practices

– Do not store state on individual instances – Do not assume subsequent requests will hit the same instance

• Don’t forget things like dynamically generated images loaded by a page

All instances require the same MachineKey for hashing– Fabric uses same machine key for all instances in a role

Page 79: Cloud e Web con Windows AZURE e ASP.NET MVC 3

AJAX and Windows AzureClient side calls may not return to the same instance the original page came fromAJAX calls must be stateless

– Don’t generate a page and leave state on the server to call via AJAX later

Page 80: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Windows Azure Session StateWindows Azure Load Balancer uses round-robin allocation. Session state must persist to client or storage on every request

SQL Azure Windows Azure Storage

LB

session[“foo”] = 1; session[“foo”] = 2;

What is the value of session[“foo”]?

Page 81: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Solving Session StatePersist to Storage via Session State Provider– Windows Azure AppFabric Caching– 3rd party distributed cache (e.g. MemCached)– SQL Azure– Windows Azure Storage– Custom

Persist to Client– Use cookies performance issues

Page 82: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Windows Azure AppFabric CachingUsing Windows Azure AppFabric Caching as the session storeIn-memory, distributed cacheBased on Windows Server AppFabric CachingUsed the Microsoft.Web.DistributedCache assembly found in the SDKEnable ASP.NET 4 Session CompressionCurrently available in AppFabric LABS Portal as CTP

Page 83: Cloud e Web con Windows AZURE e ASP.NET MVC 3

AppFabric Caching Session StateSession state stored using Windows Azure AppFabric Caching and an out-of-the-box session state provider

LB

session[“foo”] = 1; session[“foo”] = 2;

AppFabric Caching

What is the value of session[“foo”]?

Page 84: Cloud e Web con Windows AZURE e ASP.NET MVC 3

SQL Server Session StateUse SQL Azure as backing storeRound trip to database twice per request

– Read at request start– Write at request end

Enable ASP.NET 4 Session CompressionScale out across multiple DBs

– Use session state partitioning– http://tinyurl.com/scale-session

SQL Azure is competitive on cost basis

Page 85: Cloud e Web con Windows AZURE e ASP.NET MVC 3

SQL Azure Session StateSession state stored using SQL Server Session State Provider and session state partitioning

SQL Azure 3 x 1GB Databases

LB

session[“foo”] = 1;

resolve partition

session[“foo”] = 2;

What is the value of session[“foo”]?

Page 86: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Windows Azure Storage ProvidersSample ASP.NET Providers (Session, Membership, Role etc…)Sample Codehttp://code.msdn.microsoft.com/windowsazuresamples

Uses Blob + Table StorageSeveral storage transactions per requestEnable ASP.NET 4 Session Compression

Sample Provider should be treated as a starting point only.

Page 87: Cloud e Web con Windows AZURE e ASP.NET MVC 3

CookiesSerialize and Encrypt state into cookiePossible to implement as Session State ProviderCookies add significant performance overheadCookies sent with every request to domain

– Use alternative host header to serve images, …• http://www.myweb.com• http://images.myweb.com

– Use Windows Azure Storage for static content

Page 88: Cloud e Web con Windows AZURE e ASP.NET MVC 3

DNSAll services get a *.cloudapp.net address

– myservicename.cloudapp.net– TTL is 10 seconds

Standard approach is to CNAME to *.cloudapp.net– Requires two DNS lookups– Limited caching due to low TTL

Officially, Windows Azure do not support the use of A recordsIP Address for deployment is fixed for lifetime of that slot

Page 89: Cloud e Web con Windows AZURE e ASP.NET MVC 3

ASP.NET ON AZURE:COMMON CHALLENGES

Page 90: Cloud e Web con Windows AZURE e ASP.NET MVC 3

File UploadASP.NET File Upload Control uses ASP.NET temporary directory to buffer files

– Temp path cannot be changed to Local Resource or Windows Azure Drive

Windows Azure Compute roles have 100MB of root disk space Problems arise

– Uploading large files (~100MB)– Multiple users uploading concurrently (10 users uploading 10MB

files)

Page 91: Cloud e Web con Windows AZURE e ASP.NET MVC 3

File Upload SolutionsUpload direct to Blob storage using Silverlight

– Provide a Shared Access Signature to Silverlight control– Upload blocks direct to storage [http://tinyurl.com/sl-blob]

Use 3rd Party ControlImplement a custom IHttpHandler to receive file and buffer to disk

Page 92: Cloud e Web con Windows AZURE e ASP.NET MVC 3

TakeawaysASP.NET In Windows Azure

– Broad support for ASP.NET Features– Must understand and architect for scale out

Advanced Techniques– SaaS Applications using Virtual Path Providers and Host header

checkingChallenges

Page 93: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Creazione di un’applicazione Web con ASP.NET MVC + Azure

Demo

Page 94: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Creazione di un’applicazione Web con ASP.NET MVC

Demo

Page 96: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Questions

Page 97: Cloud e Web con Windows AZURE e ASP.NET MVC 3

MicrosoftLogo here

Microsoft Logo Tagline here

IMAGINE CUP 2012

Page 98: Cloud e Web con Windows AZURE e ASP.NET MVC 3

MicrosoftLogo here

Microsoft Logo Tagline here

IMAGINE A WORLD...The most important student technology competition!Let’s join to thousands of students from around the world who are stepping up to the challenge of global change. Choose from three team competitions—Software Design, Game Design: Xbox/Windows, and Game Design: Phone or take on the IT Challenge.

Page 99: Cloud e Web con Windows AZURE e ASP.NET MVC 3

OVERVIEW

The Game Design: Phone competition is an excellent opportunity to learn the art of mobile video game design!

The IT Challenge is an individual challenge for students around the world who have the nterest, and technical knowledge to design infrastructures.

The structure of the game is entirely up to you! The goal :Creatively using technology.

The Software Design Competition is all about creating real-world applications that can help make the world a better place.

Page 100: Cloud e Web con Windows AZURE e ASP.NET MVC 3

MicrosoftLogo here

Microsoft Logo Tagline here

INSPIRATIONNeed a Litte Inspiration? Get motivated by one of the eight United Nations Millennium Development Goals: the Imagine Cup offers these ambitious challenges as a guide to promote change all around the world. Game “Malaria Wars” based on Windows for Xbox that improves knowledge about Malaria, Software Design project “Brain” which allow children, who had their elementary education interrupted, to continue learning and “G7oups” a Windows Phone 7 based application with a clear goal to improve in a creative way the education of guys More at Imagine cup.com/Student stories

Page 101: Cloud e Web con Windows AZURE e ASP.NET MVC 3

STEP UP THE CHALLENGE• Check out

www.imaginecup.com• Form your Team• Make new Friends,

compete & change the World!

Next year you could be on stage @Sidney Finals!!

Page 102: Cloud e Web con Windows AZURE e ASP.NET MVC 3

MicrosoftLogo here

STAY TUNED ON

SITE: WWW.MICROSOFT.IT/STUDENTIWWW.IMAGINECUP.COMSOCIAL: FB FANPAGE INIZIATIVE STUDENTIMAIL TO: [email protected]

Page 103: Cloud e Web con Windows AZURE e ASP.NET MVC 3

Vinci con Windows Phone

Premi per oltre 20.000 euro complessivi in buoni acquisto spendibili online presso Media World. tra estrazioni

bisettimanali e premi finali

http://www.microsoft.it/msdn/concorso

Page 104: Cloud e Web con Windows AZURE e ASP.NET MVC 3