Search code examples
xmlazurelimitazure-service-fabricservice-fabric-stateful

How does CpuPercent in Azure's ApplicationManifest.xml work?


I'm currently learning how to limit CPU load for azure services. I essentially made a fork bomb and made it my goal to limit the CPU usage to leave a fraction available for the rest of the system.

I found the "CpuPercent" value in the Resource Governance Policy, but I have yet to see the effect after I publish to the cluster. The memory limit in the same line is applied, but the CPU usage still skyrockets. I can also limit the program to a set number of cores, but this is hardly what I want as that leaves a significant portion of the processor idle during normal operation.

Here is the ApplicationManifest.xml for my project:

<?xml version="1.0" encoding="utf-8"?>
<ApplicationManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ApplicationTypeName="ForkingCloudType" ApplicationTypeVersion="1.0.0" xmlns="http://schemas.microsoft.com/2011/01/fabric">
  <Parameters>
    <Parameter Name="Stateful1_MinReplicaSetSize" DefaultValue="3" />
    <Parameter Name="Stateful1_PartitionCount" DefaultValue="1" />
    <Parameter Name="Stateful1_TargetReplicaSetSize" DefaultValue="3" />
  </Parameters>
  <!-- Import the ServiceManifest from the ServicePackage. The ServiceManifestName and ServiceManifestVersion 
       should match the Name and Version attributes of the ServiceManifest element defined in the 
       ServiceManifest.xml file. -->
  <ServiceManifestImport>
    <ServiceManifestRef ServiceManifestName="Stateful1Pkg" ServiceManifestVersion="1.0.0" />
    <Policies>
      <!--ServicePackageResourceGovernancePolicy CpuCores="1" /-->
      <ResourceGovernancePolicy CodePackageRef="Code" MemoryInMB="2200" CpuPercent="20" />
    </Policies>
  </ServiceManifestImport>
  <DefaultServices>
    <!-- The section below creates instances of service types, when an instance of this 
         application type is created. You can also create one or more instances of service type using the 
         ServiceFabric PowerShell module.

         The attribute ServiceTypeName below must match the name defined in the imported ServiceManifest.xml file. -->
    <Service Name="Stateful1">
      <StatefulService ServiceTypeName="Stateful1Type" TargetReplicaSetSize="[Stateful1_TargetReplicaSetSize]" MinReplicaSetSize="[Stateful1_MinReplicaSetSize]">
        <UniformInt64Partition PartitionCount="[Stateful1_PartitionCount]" LowKey="-9223372036854775808" HighKey="9223372036854775807" />
      </StatefulService>
    </Service>
  </DefaultServices>
</ApplicationManifest>

How is this "CpuPercent" intended to be used? Is there any documentation?


Solution

  • After a back-and-forth with a Microsoft tech I was informed that CpuPercent only functions when inside a container.

    However, I have yet to find or be directed to any official documentation, so if anybody is able to dig that up then I will make that the accepted answer.