ResourceGovernancePolicy 中的 "cpushares" 是如何工作的?

How do "cpushares" in ResourceGovernancePolicy works?

使用不同的 "cpuShares" 设置(500 和 1500)将同一容器应用程序的 2 个版本部署到 Service Fabric。我预计当两者都托管在同一台主机上时,版本 1 将分配 CPU 的三分之一,然后是第二个,但实际上他们都吃 50% CPU。

应用清单

<ApplicationManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ApplicationTypeName="PI_CalculatorType" ApplicationTypeVersion="770Shares" xmlns="http://schemas.microsoft.com/2011/01/fabric">
  <Parameters>
    <Parameter Name="PI_Web_Service_InstanceCount" DefaultValue="-1" />
  </Parameters>
  <ServiceManifestImport>
    <ServiceManifestRef ServiceManifestName="PI_Web_ServicePkg" ServiceManifestVersion="770Shares" />
    <ConfigOverrides />
    <Policies>
      <ContainerHostPolicies CodePackageRef="Code">
        <PortBinding ContainerPort="80" EndpointRef="PI_Web_ServiceTypeEndpoint" />
      </ContainerHostPolicies>
      <ResourceGovernancePolicy CodePackageRef="Code" MemorySwapInMB="4084" MemoryReservationInMB="1024" CpuShares="770" />
    </Policies>
  </ServiceManifestImport>
  <DefaultServices>
    <Service Name="PI_Web_Service">
      <StatelessService ServiceTypeName="PI_Web_ServiceType" InstanceCount="[PI_Web_Service_InstanceCount]">
        <SingletonPartition />
      </StatelessService>
    </Service>
  </DefaultServices>
</ApplicationManifest>

服务清单

<ServiceManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="PI_Web_ServicePkg" Version="770Shares" xmlns="http://schemas.microsoft.com/2011/01/fabric">
  <ServiceTypes>
    <StatelessServiceType ServiceTypeName="PI_Web_ServiceType" UseImplicitHost="true" />
  </ServiceTypes>
  <CodePackage Name="Code" Version="770Shares">
    <EntryPoint>
      <ContainerHost>
        <ImageName>artisticcheese/iis:latest</ImageName>
      </ContainerHost>
    </EntryPoint>
  </CodePackage>
  <ConfigPackage Name="Config" Version="770Shares" />
  <Resources>
    <Endpoints>
      <Endpoint Name="PI_Web_ServiceTypeEndpoint" Protocol="http" UriScheme="http" />
    </Endpoints>
  </Resources>
</ServiceManifest>

URL调用重现

http://192.168.1.193:20001/pi/service.svc/pi/40000
默认情况下

CpuShares is relative to a set of 1024 份 CPU。

Set this flag to a value greater or less than the default of 1024 to increase or reduce the container’s weight, and give it access to a greater or lesser proportion of the host machine’s CPU cycles.

您的 500 设置导致大约一半的 CPU 被一项服务使用,剩下的留给另一项服务。

将 500 更改为 341 应该可以解决问题。

这是容器支持预览位的一个已知问题。它已为即将发布的版本修复。