kumar
kumar

Reputation: 9427

Service Fabric set instance count -1

I see the web instance count is set to -1. What does -1 mean?

<Parameter Name="Web1_InstanceCount" Value="-1" />

Upvotes: 5

Views: 4533

Answers (3)

Diego Mendes
Diego Mendes

Reputation: 11361

In you example, -1 means just a parameter value, out of context it does not mean anything. By the name of your variable, it is a parameter likely to be used on service declaration on your ApplicationManifest.xml.

You will probably have something like this:

<?xml version="1.0" encoding="utf-8"?>
<ApplicationManifest ApplicationTypeName="MyAppTypeName" ApplicationTypeVersion="1.0.0" xmlns=...>
  <Parameters>
    <Parameter Name="Web1_InstanceCount" Value="-1" />
    <Parameter Name="FEPlacementConstraints" Value="NodeTypeName==FrontEnd" />
  </Parameters>
  <ServiceManifestImport>
    <ServiceManifestRef ServiceManifestName="MyServicePkg" ServiceManifestVersion="1.0.0" />
    <ConfigOverrides />
  </ServiceManifestImport>
  <DefaultServices>
    <Service Name="Web1">
      <StatelessService ServiceTypeName="MyServiceType" InstanceCount="[Web1_InstanceCount]">
        <SingletonPartition />
        <PlacementConstraints>[FEPlacementConstraints]</PlacementConstraints>
      </StatelessService>
    </Service>
  </DefaultServices>
</ApplicationManifest>

If you pay attention, at the beggining your define the parameters, and at the bottom you use them enclosed by [ ] when declaring the services.

Now, regarding the meaning of the value -1.

-1 is a dynamic instance count, that means that the number of instances of your named service(Web1) will scale dynamically with the number of valid nodes available. Pay attention here to 'valid nodes available' not 'all nodes'

Why valid nodes available?

  • Let's assume you have 2 node types, FrontEnd & BackEnd. If you add a placement constraints to your service to run only on FrontEnd (like in the example) your service will run on all nodes where the type is 'FrontEnd'.
  • The other point is the number of instances will change every time the number of valid nodes available(those that fits your service rules), for example, you scale up/down the number of nodes in a node type scale set. Some nodes fails, or some rules changes, for example, you create a rule based on node labels and these labels change.

You can find more info here

Upvotes: 6

duongthaiha
duongthaiha

Reputation: 855

Its mean -1 is the default value of instance count of an service. So Service Fabric will run it on all node. So if you have 5 nodes then SF will deploy that service into 5 nodes. You then can use Load Balancer or Reverse proxy to direct your traffic to each node

More info here https://learn.microsoft.com/en-us/azure/service-fabric/service-fabric-concepts-scalability

Upvotes: 0

Peter Bons
Peter Bons

Reputation: 29880

A Service Fabric cluster consist of one or more nodes (For testing/development purposes it can have 1 or 3 nodes, production environments typically have >= 5 nodes). When the Web1 service is deployed, it will run on x nodes where x is determined by the value of Web1_InstanceCount.

When to value is set to -1 the service will be deployed to all nodes.

Traffic will be routed to one of the instances of Web1 running on a node in a round robin fashion.

I strongly advice to read this part of the docs.

Scaling by creating or removing stateless service instances

One of the simplest ways to scale within Service Fabric works with stateless services. When you create a stateless service, you get a chance to define an InstanceCount. InstanceCount defines how many running copies of that service's code are created when the service starts up. Let's say, for example, that there are 100 nodes in the cluster. Let's also say that a service is created with an InstanceCount of 10. During runtime, those 10 running copies of the code could all become too busy (or could be not busy enough). One way to scale that workload is to change the number of instances. For example, some piece of monitoring or management code can change the existing number of instances to 50, or to 5, depending on whether the workload needs to scale in or out based on the load.

Upvotes: 1

Related Questions