From 5f92f32a39f2d5c509a0ebf28e67d9ef20bc01bb Mon Sep 17 00:00:00 2001 From: Ning Wang Date: Fri, 23 Mar 2018 14:38:54 -0700 Subject: [PATCH] remove three other roundings in cpu calculation --- .../src/java/com/twitter/heron/packing/builder/Container.java | 4 ++-- .../com/twitter/heron/packing/builder/PackingPlanBuilder.java | 4 ++-- .../java/com/twitter/heron/packing/utils/PackingUtils.java | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/heron/packing/src/java/com/twitter/heron/packing/builder/Container.java b/heron/packing/src/java/com/twitter/heron/packing/builder/Container.java index e2d667fc0ad..b6ecf32f43e 100644 --- a/heron/packing/src/java/com/twitter/heron/packing/builder/Container.java +++ b/heron/packing/src/java/com/twitter/heron/packing/builder/Container.java @@ -151,8 +151,8 @@ private void assertHasSpace(Resource resource) throws ResourceExceededException Resource usedResources = this.getTotalUsedResources(); ByteAmount newRam = usedResources.getRam().plus(resource.getRam()).increaseBy(paddingPercentage); - double newCpu = Math.round( - PackingUtils.increaseBy(usedResources.getCpu() + resource.getCpu(), paddingPercentage)); + double newCpu = + PackingUtils.increaseBy(usedResources.getCpu() + resource.getCpu(), paddingPercentage); ByteAmount newDisk = usedResources.getDisk().plus(resource.getDisk()).increaseBy(paddingPercentage); diff --git a/heron/packing/src/java/com/twitter/heron/packing/builder/PackingPlanBuilder.java b/heron/packing/src/java/com/twitter/heron/packing/builder/PackingPlanBuilder.java index dba516334c6..78d02b68ed4 100644 --- a/heron/packing/src/java/com/twitter/heron/packing/builder/PackingPlanBuilder.java +++ b/heron/packing/src/java/com/twitter/heron/packing/builder/PackingPlanBuilder.java @@ -352,12 +352,12 @@ private static Set buildContainerPlans( new Resource(instanceCpu, instanceRam, instanceDisk))); } - containerCpu += (paddingPercentage * containerCpu) / 100; + containerCpu = PackingUtils.increaseBy(containerCpu, paddingPercentage); containerRam = containerRam.increaseBy(paddingPercentage); containerDiskInBytes = containerDiskInBytes.increaseBy(paddingPercentage); Resource resource = - new Resource(Math.round(containerCpu), containerRam, containerDiskInBytes); + new Resource(containerCpu, containerRam, containerDiskInBytes); PackingPlan.ContainerPlan containerPlan = new PackingPlan.ContainerPlan(containerId, instancePlans, resource); diff --git a/heron/packing/src/java/com/twitter/heron/packing/utils/PackingUtils.java b/heron/packing/src/java/com/twitter/heron/packing/utils/PackingUtils.java index 6a2b32f92db..e8d0a45f7fb 100644 --- a/heron/packing/src/java/com/twitter/heron/packing/utils/PackingUtils.java +++ b/heron/packing/src/java/com/twitter/heron/packing/utils/PackingUtils.java @@ -58,8 +58,8 @@ private static void assertIsValidInstance(Resource instanceResources, instanceRam, maxContainerResources.getRam())); } - double instanceCpu = Math.round(PackingUtils.increaseBy( - instanceResources.getCpu(), paddingPercentage)); + double instanceCpu = PackingUtils.increaseBy( + instanceResources.getCpu(), paddingPercentage); if (instanceCpu > maxContainerResources.getCpu()) { throw new PackingException(String.format( "This instance requires containers with at least %s cpu cores. The current max container"