Mahesh Krishnan Creating highly available and resilient Microservices on Microsoft Azure Service Fabric CLD33 4.

  • Published on
    19-Jan-2016

  • View
    217

  • Download
    0

Transcript

<p>Spark the future.Mahesh KrishnanCreating highly available and resilient Microservices on Microsoft Azure Service FabricCLD334AgendaWhy use microservices?Azure Service Fabric Platform An introductionService Fabric Programming modelReliable ActorsReliable ServicesWrap upTraditional Monolithic approachA monolithic application has most of its functionality withina single process that is commonly componentized with libraries</p> <p>Scales by cloning the app on multiple servers/VMs/containers</p> <p>Microservices approachSeparates functionality into separate smaller services</p> <p>Uses a standard communication protocol</p> <p>Scales out be deploying each service independentlycreating instances of these services across servers/VMscontainers</p> <p>Why use microservices?Can be versioned, deployed and scaled independentlyAllows use of different technologiesLoose coupling of servicesFaster delivery of featuresFacilitates small, focused teamsImproves fault isolationMicrosoft Azure Service FabricA platform for reliable, hyperscale, microservice-based applicationsAzure WindowsServerLinux</p> <p>Hosted CloudsWindowsServerLinux</p> <p>Service Fabric</p> <p>Private CloudsWindowsServerLinuxHigh AvailabilityHyper-ScaleHybrid OperationsHigh DensitymicroservicesRolling UpgradesStateful servicesLow LatencyFast startup &amp; shutdownContainer Orchestration &amp; lifecycle managementReplication &amp; FailoverSimple programming modelsLoad balancingSelf-healingData PartitioningAutomated RollbackHealth MonitoringPlacement ConstraintsApp1App2Service Fabric cluster with microservicesTypes of MicroservicesStateless microserviceStateful microservicesStateless MicroservicesHas either no state or state is persisted externally (such as Azure database or Azure storage)</p> <p>There can be multiple instances of the services</p> <p>e.g. Existing ASP.NET web apps, Azure cloud services Stateful MicroservicesState is maintained within the microserviceAllows for hot data to be next to the computeState is partitioned for scaleEach partition state is replicated for reliability</p> <p>e.g. Database, documents, user profile, shopping cart, etcCloud Services vs Service FabricAzure Cloud servicesService FabricOne service instance/VMMultiple microservices/VMLower compute densityHigh microservice densitySlow in deployment and upgradesFasterSlower scaling and DRFast scaling across the clusterProgramming models</p> <p>Service fabric applicationsReliable Actors APIActor programming modelIntroduced in 1973!An actor is the fundamental unit of computationDoes some processingHolds stateCommunicates with other actorsSimilar to objects in OOPReliable Actors APIBuild reliable stateless and stateful objects using a virtual Actor programming model</p> <p>Suitable for applications with multiple independent unitsof scale and compute</p> <p>Automatic state management and turn based concurrency</p> <p>Reliable ActorsActors have an lD that maps to an object</p> <p>Service Fabric manages nodes and can transparentlymove actors amongst them (provides HA and scale)</p> <p>Actor methods run via turn based concurrency</p> <p>Getting startedDownload the Service Fabric Download</p> <p>Ensure PowerShell is installed and right execution policies set up</p> <p>Run the DevClusterSetup.ps1script to start local cluster</p> <p>Server side code - Interfacepublic interface IMyActor : IActor{ Task DoWorkAsync();}Server side code - Implementationpublic class MyActor : Actor, IMyActor{ public async Task DoWorkAsync() { return await Task.FromResult("result"); }}Client side codevar app = "fabric:/HelloWorld";</p> <p>var proxy = ActorProxy.Create (ActorId.NewId(), app);</p> <p>var result = proxy.DoWorkAsync().Result;DemoReliable ActorsMicrosoft Ignite 2015 2015 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.11/20/2015 11:27 AM23Actor LifecycleActor lifecycle - ActivationIf actor is not active, a new actor is created</p> <p>Its state is then loaded (for stateful actors)</p> <p>OnActivateSync method is called</p> <p>Added to Active Actors table</p> <p>Actor lifecycle - DeactivationUnused actors removed from the Active Actors table</p> <p>OnDeactivateSync method is called on Actor</p> <p>Once deactivated, objects are garbage collected by CLR</p> <p>Actor lifecycle more conceptsScan interval Time interval between successive scansby Actor runtime for inactive actors (Default: 60 seconds)</p> <p>Idle timeout Time an actor can be idle before it is deactivated (Default: 60 seconds)</p> <p>ActorGarbageCollection attribute used to change defaults</p> <p>Reliable Services APIReliable Services APIWrite services that are reliable, available, scalable and provide consistency</p> <p>Use Reliable Collections to persist state </p> <p>Communicate using tech of your choice (WCF, WebAPI, ..)Reliable CollectionCan be used to create Stateful services. </p> <p>Features:Multi-machineReplicated (HA)Persistance (durable)AsynchrounousTransactionalGetting startedOnly two methods you need to implement to get started.</p> <p>CreateCommunicationListener Method where the communication stack for the service is defined</p> <p>RunAsync This is where the Service runs the business logic similar to WorkerRoles Run method</p> <p>Server side code - Implementationpublic class MyStatelessService : StatelessService{ protected override ICommunicationListener CreateCommunicationListener() { }</p> <p> protected override async Task RunAsync(CancellationToken cancellationToken) { }}Reliable Collectionvar myDictionary = await this.StateManager.GetOrAddAsync ("myDictionary");</p> <p>using (var tx = this.StateManager.CreateTransaction()){ await myDictionary.AddOrUpdateAsync(tx, "counter", 0, (k, v) =&gt; ++v); await tx.CommitAsync();}</p> <p>ScalabilityCan be partitioned for scalability you choose scheme</p> <p>Node 5Node 4Node 3Node 6Node 2Node 1P2SSSP4SP1SP3SSSDemoReliable ServicesDemoService Fabric in the portalWrap upService Fabric is the next generation of PaaS that canbe used to create microservicesHas 2 programming models:Reliable Actor APIReliable Service APICan create either stateful or stateless servicesAvailability, Scalability, load balancing, etc comes OOB </p> <p>Complete your session evaluation on My Ignite for your chance to win one of many daily prizes. Continue your Ignite learning pathVisit Microsoft Virtual Academy for free online training visit https://www.microsoftvirtualacademy.comVisit Channel 9 to access a wide range of Microsoft training and event recordings https://channel9.msdn.com/Head to the TechNet Eval Centre to download trials of the latest Microsoft products http://Microsoft.com/en-us/evalcenter/</p> <p>Microsoft Ignite 2015 2015 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.11/20/2015 11:27 AM39 2015 Microsoft Corporation. All rights reserved.Microsoft, Windows and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. </p>

Recommended

View more >