Von neumann workers

30

Transcript of Von neumann workers

Von Neumann Workers

Riccardo Becker| Practice Manager Microsoft| Logica

- Introduction (and turn on some cloud stuff)

- The Worker

- The Generic Worker

- Azure Service Management API

- Elasticity

- Von Neumann Machines

- Summary & Next steps

- Q & A

Agenda

Introduction

• Riccardo Becker

• 13 years of Logica

• Practice Manager

• Strong technical Microsoft background

• www.twitter.com/riccardobecker

• http://nl.linkedin.com/in/riccardobecker

• REMINDER: turn on my TestDeployment on the Portal!

• Long running tasks that are asynchronous that user does not have to wait for.

• To host application services that do not require a user interface.

• Background services listening to a queue.

• Running TCP based services.

• Compute intensive jobs.

• But everything has a price!

The Worker

• Can handle different tasks (from simple calculation up to long running)

• Once, repeatedly or forever

• Has flexibility of loading and unloading code

• Is able to report it´s health

• Has a queue that delivers work

• Loads assemblies from Blob Storage

• Reports health and activities on Service Bus

The Generic Worker

The Generic Worker

• Simple demo

• Quartz.NET for scheduling

• Uses queues, blobs and reflection

Generic Worker example

Type t = assembly.GetType(task.ClassName + "." + task.ClassName);

ICalculation calc = (ICalculation)Activator.CreateInstance(t);

int Result = calc.Addition(task.Parameters);

Windows Azure Service Management API

• REST API

• SSL and mutually authenticated using X.509

• Need subscription id (see portal)

• Operations on storage accounts, hosted

services, deployments, certificates, affinity groups (both

sync & async ops)

• Activities like on Management Portal (build your own)

Service Management APICreate, Swap & Delete Deployment

Change Deployment Config

Update Deployment Status

Upgrade Deployment

Walk Upgrade Domain

Reboot Role Instance

Reimage Role Instance

List throught hosted services, deployments, instances, certificates, affinity groups

Every async operation returns request-id

Use request-id in call to Get Operation Status for Asynchronous Operations(https://management.core.windows.net/<subscription-id>/operations/<request-id>)

Example: List Hosted Services//Takes the embedded resource (not in production environment!) and creates X509 certificate from it. //Certificate is exported on machine, password is required since it's installed/used on another machine using (Stream CertStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(GetType(), @"DevDays2011.pfx")) {

byte[] RawBytes = new byte[CertStream.Length]; for (int Index = 0; Index < CertStream.Length; Index++) { RawBytes[Index] = (byte)CertStream.ReadByte();

} certificate = new X509Certificate2(RawBytes, "riccardo"); } Trace.WriteLine("Certificate retrieved from embedded resource. Friendly Name={0}", certificate.FriendlyName); IServiceManagement channel = ServiceManagementHelper.CreateServiceManagementChannel(ConfigurationConstants.WebHttpBinding(), new Uri(ConfigurationConstants.ServiceEndpoint), this.certificate); //build structure of azure assets (hosted services & storage accounts) hostedServiceList = channel.ListHostedServices("dbded203-cb18-4e0c-99e3-de3f1129ffee");

Example: List Hosted Service[OperationContract(AsyncPattern = true)]

[WebGet(UriTemplate = @"{subscriptionId}/services/hostedservices")]

IAsyncResult BeginListHostedServices(string subscriptionId,AsyncCallback callback, object state);

HostedServiceList EndListHostedServices(IAsyncResult asyncResult);

Demo

Traverse through Azure Assets:

- Hosted Services

- Deployments + Configuration

- Storage

- Affinity Groups

- Certificates

What is elasticity?

• The ability to add/remove based on load

• Take the right decision based on the right

metrics

• Raw data is not meaningful for us people

• Apply smoothing to make it human

interpretable

Work Load Patterns

On off

Usage

Co

mp

ute

Time

Average

Inactivity

Period

On and Off

Co

mp

ute

Time

Unpredictable Bursting

Average Usage

Average Usage

Co

mp

ute

Time

Growing Fast

Co

mp

ute

Time

Average Usage

Predictable Bursting

Performance Counters// Add the performance counters (CPU and memory)

diagConfig.PerformanceCounters.DataSources.Add(

new PerformanceCounterConfiguration()

{

CounterSpecifier = @"\Processor(_Total)\% Processor Time",

SampleRate = TimeSpan.FromSeconds(5)

}

);

// Copy the diagnostic metrics to TableStorage every minute for

diagConfig.PerformanceCounters.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);

// Set the LogLevel and period

diagConfig.DiagnosticInfrastructureLogs.ScheduledTransferLogLevelFilter = LogLevel.Error;

diagConfig.DiagnosticInfrastructureLogs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);

// Start the diagnostic monitor

DiagnosticMonitor diagnosticMonitor = DiagnosticMonitor.Start(csa, diagConfig);

Performance Counters cont’d

• Every 5 seconds 1 sample

• Transfer every minute all data

TableStorage

• Take the Average of e.g. last hour to

decide

• Scale up / down based on outcome

Smoothing• Simple Moving Average

• Weighted Moving Average

• Exponential Moving Average

Smoothing example + demopublic static IEnumerable<WADPerformanceCountersTable> SimpleMovingAverage(IEnumerable<

WADPerformanceCountersTable> source)

{

double total = 0;

List<WADPerformanceCountersTable> target = new List<WADPerformanceCountersTable>();

int i = 0;

foreach (WADPerformanceCountersTable pcdp in source)

{

i += 1;

total += pcdp.CounterValue;

WADPerformanceCountersTable entry = new WADPerformanceCountersTable();

entry.PartitionKey = pcdp.PartitionKey;

entry.RowKey = Guid.NewGuid().ToString();

entry.CounterName = pcdp.CounterName;

entry.DeploymentId = pcdp.DeploymentId;

entry.Role = pcdp.Role;

entry.RoleInstance = pcdp.RoleInstance + ".Smoothed";

entry.Timestamp = pcdp.Timestamp;

entry.EventTickCount = pcdp.EventTickCount;

entry.CounterValue = (total / i);

target.Add(entry);

}

return target;

}

}

DEMO Diagnostics Manager Cerebrata

Scaling

• Manual or

• Use Service Management API

• Modify service configuration

• In this case, a worker decides to scale not

some overlord (probably better)

Scaling//take the average of the last hourvar averageMetrics = perfContext.CreateQuery<WADPerformanceCountersTable>("WADperformanceCountersTable");

var average = (from d in averageMetricswhere (String.Compare(d.RoleInstance,RoleEnvironment.CurrentRoleInstance.Id + ".Smoothed") == 0) &&(Convert.ToDateTime(d.EventTickCount) >= DateTime.UtcNow.AddHours(-1))select d).ToList<WADPerformanceCountersTable>();

double averageCPU = average.Average(a => a.CounterValue);

// get the deployment involvedDeployment deployment =

(from p in this.hostedServiceListfrom c in p.Deployments

from d in c.RoleInstanceListwhere (this.hostedServiceList != null)where (p.Deployments != null)&& (c.RoleInstanceList != null)where (d.RoleName == RoleEnvironment.CurrentRoleInstance.Role.Name)select c).FirstOrDefault();

Scaling demo- Visual Studio 2010

- Windows Azure Portal

- A sea of parts

- A universal constructor

- Manufacture a copy of itself autonomously

- Exponential growth

- Most effective way of large-scale operations

What is self replication according to Von Neumann?

A sea of parts

Von Neumann on AzureAzure Blob Storage

Assembly A

Assembly B

Assembly C

Assembly D

Assembly E

Assembly G

Assembly KAssembly H

Assembly J

Assembly F

Assembly P

Assembly L Assembly RAssembly I

Assembly Q

Assembly S

Assembly O

Assembly N

Assembly M

Assembly U

Assembly T

Universal ConstructorWorker Role

Elasticity agentAssembly linewatcher

WorkerRole

WorkerRole

WorkerRole

WorkerRole

WorkerRole

Assembly LineQueue

Von Neumann WorkerCloudQueueMessage message = assemblylineQueue.GetMessage();

AssemblyTask task2 = AssemblyTask.FromMessage<AssemblyTask>(message);

CloudBlobClient c = csa.CreateCloudBlobClient();

byte[] byteStream = c.GetContainerReference("assemblies").GetBlobReference(taskname + ".dll").DownloadByteArray()

Assembly extAssembly = Assembly.Load(byteStream);

Type t = assembly.GetType(task.ClassName + "." + task.ClassName);

ICalculation calc = (ICalculation)Activator.CreateInstance(t);

int Result = calc.Addition(task.Parameters);

Summary

• Pay-per-use, use what you pay

• Make your workers sweat!

• Be efficient and scale up/down

• Let them run for at least an hour (you pay)

• Have fun experimenting!

Next steps

• Report on service bus

• Singleton in multi-instance for ElasticityAgent

• Proper management

• Actively unload code

• Will post on codeplex?

Logica is a business and technology service company, employing 39,000 people. It provides business consulting, systems integration and outsourcing to clients around the world, including many of Europe's largest businesses. Logica creates value for clients by successfully integrating people, business and technology. It is committed to long term collaboration, applying insight to create innovative answers to clients’ business needs. Logica is listed on both the London Stock Exchange and Euronext (Amsterdam) (LSE: LOG; Euronext: LOG). More information is available at www.logica.com

Thank youRiccardo Becker