advanced cloud services development (paas)

33
http://vic.ms Advanced Cloud Services Development (PaaS) Vitor Ciaramella Technical Evangelist, Microsoft http://vic.ms Azure Summit Brazil 2013

Upload: vitor-ciaramella

Post on 20-May-2015

312 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Advanced cloud services development (PaaS)

http://vic.ms

Advanced Cloud Services Development (PaaS)

Vitor CiaramellaTechnical Evangelist, Microsofthttp://vic.ms

Azure Summit Brazil 2013

Page 2: Advanced cloud services development (PaaS)

http://vic.ms

LoadBalanc

er

.csconfig

.csdef

Cloud Services

Users Apps /Browsers

DNS Server

www.myapp.net

www.myapp.com

CNAME

myapp.cloudapp.net50.63.202.28

User environmentInternet environment

Dev. environmentWindows Azure environment

MyApp

Developer

Cloud Service

Production

Staging

myapp

myapp

3f2504e0-4f89-11d3-9a0c-0305e82c3301

Disk

VM ImageHW Specs

MyApp

.csdef

.csconfigDeploy

Disk

.csconfig

MyApp

Disk

.csconfig

MyApp

Disk

.csconfig

MyAppNumber of instances

OS / Disk image

Hardware/VM Size

Disk

.csconfig

MyApp

endpoints

Endpointsdefinitions

Page 3: Advanced cloud services development (PaaS)

http://vic.ms

CloudServices

AutomatedStatelessVirtualMachines

=

Page 4: Advanced cloud services development (PaaS)

http://vic.ms

Average usage of Cloud Services

New applications Existing web applications

Page 5: Advanced cloud services development (PaaS)

http://vic.ms

Advanced Scenarios Windows Services, Console or GUI applications including Tomcat, JBoss, Lucene, Solr, Apache, Hadoop, and etc.

Specific Windows Server / IIS configuration including hosts file, Registry, IIS Media Services, multiple SSL

Certificates, custom IIS AppPool, and etc.

Page 6: Advanced cloud services development (PaaS)

http://vic.ms

Challenges Installation, Setup and Configuration

Stateful Memory

Stateful Disk

Page 7: Advanced cloud services development (PaaS)

http://vic.ms

Installation, Setup and Configuration

Page 8: Advanced cloud services development (PaaS)

http://vic.ms

Install, Setup, Config: possible solutions Use the VM Role Create a local VHD with Windows Server Install, setup and configure your application and server Upload the VHD as a VM Role disk image

Automate the installation, the setup and configuration Create an script/code to automate the installation, the setup and configuration Run it with Startup Tasks Role.OnStart Role.Run

Page 9: Advanced cloud services development (PaaS)

http://vic.ms

Automate the installation It depends on the installer technology.

Some applications can be installed simply by copying their files…

For Windows Installer:msiexec.exe /qn /i SQLSysClrTypes.msi /l*v log.txt

Page 10: Advanced cloud services development (PaaS)

http://vic.ms

Automate the setup / configuration It depends on the application.

Some applications can configured simply by overwriting their config files…

For the Windows Registry: regedit MyRegistryEntriesToBeImported.reg

For IIS: %windir%\system32\inetsrv\appcmd set config -section:applicationPools-applicationPoolDefaults.processModel.idleTimeout:00:00:00

Page 11: Advanced cloud services development (PaaS)

http://vic.ms

Automate the setup / configuration Most Windows Server and IIS configurations can be also changed by using:

PowershellPS IIS:\Sites\DemoSite\DemoApp> set-webconfiguration

"/system.webServer/handlers/add[@path='*.aspx']/@path“-value "*.mspx“

.NET Managed APIs: using (var serverManager = new ServerManager()) { var bindingInfo = "*:443:ssl2.myapp.com"; var certStore = (new X509Store(StoreName.My, StoreLocation.LocalMachine)).Name; var site = serverManager.Sites["MySite"]; if (site != null) { var binding = site.Bindings.Add(bindingInfo, certHash, certStore); binding.SetAttributeValue("sslFlags", 1); serverManager.CommitChanges(); } }

Page 12: Advanced cloud services development (PaaS)

http://vic.ms

Running the automated script/code Startup Tasks Simple: Synchronous execution, one-by-one Foreground: Asynchronous execution, keeps the role running Background: Asynchronous execution, does not keep the role running

<Startup> <Task taskType="simple" commandLine="startup\startup.cmd" executionContext="elevated">

<Environment> <Variable name="azurestoragename" value="mystorage" /> </Environment> </Task> </Startup>

Page 13: Advanced cloud services development (PaaS)

http://vic.ms

Running the automated script/code Role, RoleEntryPoint OnStart: Role stays busy until completion (doesn’t receive requests), up to 15

minutes Run: Role recycles when exit this method (so, keep it running). Ready to receive

requests. OnStop: Before role stops (clean up), up to 30 seconds

Execution Context: <Runtime executionContext="elevated“ />

Page 14: Advanced cloud services development (PaaS)

http://vic.ms

Stateful Memory

Page 15: Advanced cloud services development (PaaS)

http://vic.ms

Stateful Memory: possible solutions Rewrite/change your code to not reuse state from subsequent requests

Rewrite/change your code to save the state in a persistent or semi-persistent storage

Use Blob or Table Storage Use SQL Database Use Windows Azure Caching (recommended)

Page 16: Advanced cloud services development (PaaS)

http://vic.ms

Stateful Memory with Azure Caching Add the references to the Azure Caching assemblies.

Edit your web.config or app.config file with:

<dataCacheClients>

<dataCacheClient name="default" maxConnectionsToServer="1">

<hosts>

<host name=“myapp.cache.windows.net" cachePort="22233" />

</hosts>

<securityProperties mode="Message">

<messageSecurity authorizationInfo="YWNzOmh0dHBzOi8vdG…">

</messageSecurity>

</securityProperties>

</dataCacheClient>

</dataCacheClients>

Page 17: Advanced cloud services development (PaaS)

http://vic.ms

Stateful Memory with Azure Caching To automatically save the ASP.NET session on the Azure Caching, edit your web.config with:<configuration> <system.web> <sessionState mode="Custom" customProvider="DistributedSessionProvider" compressionEnabled="false"> <providers> <add name="DistributedSessionProvider" type="Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider,Microsoft.Web.DistributedCache" cacheName="default" applicationName=“MyApp" useBlobMode="false"/> </providers> </sessionState> </system.web></configuration>

Page 18: Advanced cloud services development (PaaS)

http://vic.ms

Stateful Memory with Azure Caching Access the Azure Caching programmatically, if you need:

var cacheFactory = new DataCacheFactory();var myCache = cacheFactory.GetDefaultCache();var key = "DataAtual";var cachedObject = myCache.Get(key);

if (cachedObject != null){ var value = (DateTime) cachedObject;}else{ var value = DateTime.Now.Date; myCache.Put(key, value, TimeSpan.FromSeconds(15));}

Page 19: Advanced cloud services development (PaaS)

http://vic.ms

Stateful Disk

Page 20: Advanced cloud services development (PaaS)

http://vic.ms

Stateful Disk: possible solutions Rewrite/change your code to save the state in a persistent storage Use Blob or Table Storage (recommended) Use SQL Database Use Azure Drive

Page 21: Advanced cloud services development (PaaS)

http://vic.msBlob Storage

Stateful Disk with Azure Drive Create a VHD and store it in the Blob Storage.

Mount the VHD as local drive in each instance.

Attention: Only one instance can mount it with Read/Write access.

Disk

Disk

.csconfig

MyApp

Disk

Disk

.csconfig

MyApp

Disk

Disk

.csconfig

MyApp

Disk

Disk

.csconfig

MyApp

Disk.vhd

R/W Mount

R/O

Mou

nt

R/O Mount

R/O Mount

Page 22: Advanced cloud services development (PaaS)

http://vic.ms

Stateful Disk with Azure Drive Sample Solr/Lucene scenario

Blob Storage

Disk

Query

Disk

Query

Disk

Query

Disk

Index

Disk.vhd

R/W Mount

R/O

Mou

ntR/O Mount

R/O Mount

Read only Read only Read only

Read write

Cloud ServiceInstance

Cloud ServiceInstance

Cloud ServiceInstance

VM

Page 23: Advanced cloud services development (PaaS)

http://vic.ms

Stateful Disk with Azure Drive How to mount a read-only (snapshotted) drive:

var localResource = RoleEnvironment.GetLocalResource("LocalDriveCache");

CloudDrive.InitializeCache(localResource.RootPath, localResource.MaximumSizeInMegabytes);

var storageAccount = CloudStorageAccount.FromConfigurationSetting(“LuceneVHDs");

var client = storageAccount.CreateCloudBlobClient();

var container = new CloudBlobContainer("vhds", client);

var pageBlob = container.GetPageBlobReference(“lucene.vhd");

var drive = new CloudDrive(pageBlob.Uri, storageAccount.Credentials);

drive = new CloudDrive(drive.Snapshot(), storageAccount.Credentials);

var driveLetter = drive.Mount(localResource.MaximumSizeInMegabytes, DriveMountOptions.None);

//e.g.: driveLetter = “H:”

Page 24: Advanced cloud services development (PaaS)

http://vic.ms

Stateful Disk with Azure Drive Delete the snapshot after using it (Role.OnStop)

Use additional logic to “clean-up” unused/old snapshots.

How to list snapshots of a blob:

var pageBlob = container.GetPageBlobReference(“lucene.vhd");

var snapshots = container.ListBlobs(new BlobRequestOptions()

{

BlobListingDetails = BlobListingDetails.Snapshots,

UseFlatBlobListing = true,

}).OfType<CloudPageBlob>().Where((blob) => blob.SnapshotTime.HasValue && blob.Uri.Equals(pageBlob.Uri)).OrderByDescending((blob)=>blob.SnapshotTime).ToList();

Page 25: Advanced cloud services development (PaaS)

http://vic.ms

Automated Configuration and Monitoring

Page 26: Advanced cloud services development (PaaS)

http://vic.ms

Automated Configuration Role.OnStart

Role

RoleEnvironment.Changing += RoleEnvironment_Changing;

void RoleEnvironment_Changing(object sender, RoleEnvironmentChangingEventArgs e){

MyApplyChanges(e.Changes);

e.Cancel = MyCheckIfNeedsToReboot();}

Page 27: Advanced cloud services development (PaaS)

http://vic.ms

Automated Monitoring Role.OnStart

Role

RoleEnvironment.StatusCheck += RoleEnvironment_StatusCheck;

void RoleEnvironment_StatusCheck(object sender, RoleInstanceStatusCheckEventArgs e){

var isHealthy = CheckMyHealth();

if (!isHealthy) e.SetBusy();}

Page 28: Advanced cloud services development (PaaS)

http://vic.ms

Other Tips

Page 29: Advanced cloud services development (PaaS)

http://vic.ms

Reduce the size of the Package Put static files (images, videos, JavaScript, CSS) in the Blob Storage. Adjust the URLs to these resources.

Put installers and large executables in the Blob Storage. Download these files locally using Startup Tasks / Role.OnStart

Page 30: Advanced cloud services development (PaaS)

http://vic.ms

Prefer Async Processing Use the Queue Storage or Service Bus (Queues, Topics and Notification Hub) to distribute work and scale processing

Use the .NET framework 4.5 parallel and async features

Page 31: Advanced cloud services development (PaaS)

http://vic.ms

Proactive Caching All instances read from the cache

One instance is responsible to update the cache periodically

Page 32: Advanced cloud services development (PaaS)

http://vic.ms

Distribute Users and Content Use CDN to distribute and cache the content (Blobs / Web Roles)

Use the Traffic Manager to direct users to the closest datacenter

Page 33: Advanced cloud services development (PaaS)

http://vic.ms

Advanced Cloud Services Development (PaaS)

Vitor CiaramellaTechnical Evangelist, Microsofthttp://vic.ms

Azure Summit Brazil 2013