This is an automated email from the ASF dual-hosted git repository.

upthewaterspout pushed a commit to branch concourse-staging
in repository https://gitbox.apache.org/repos/asf/geode.git

commit 1c7516c446a1bfb2049e2ae1ebfdaf9475be2457
Author: Dan Smith <upthewatersp...@apache.org>
AuthorDate: Thu Sep 6 15:06:06 2018 -0700

    Adding an option to limit the number of CPUs for docker
    
    When running tests in docker containers, you can limit the number of
    CPUs each container gets to use with -PdunitCpuQuota=X , where X
    can be a floating point number of CPUs.
---
 gradle/docker.gradle | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/gradle/docker.gradle b/gradle/docker.gradle
index ec08ab7..e49ab04 100644
--- a/gradle/docker.gradle
+++ b/gradle/docker.gradle
@@ -63,6 +63,7 @@ def dockerConfig = {
     // specify the user for starting Gradle test worker within the container.
     user = dunitDockerUser
 
+
     beforeContainerCreate = { cmd, client ->
       def javaHomeIdx = -1
       def pathIdx = -1
@@ -98,6 +99,18 @@ def dockerConfig = {
 
       cmd.withEnv(tmpEnv)
 
+      //Limit the CPU usage of the command
+      //Newer docker has a --cpu command, but for the docker-java plugin
+      //we have to set the CPU period (100 microseconds) and CPU quota
+      if(project.hasProperty("dunitCpuQuota")) {
+        int period = 100_000;
+        int quota = period * Float.parseFloat(project.dunitCpuQuota);
+        def hostConfig = cmd.getHostConfig();
+        hostConfig.withCpuPeriod(period)
+        hostConfig.withCpuQuota(quota)
+        cmd.withHostConfig(hostConfig)
+      }
+
       // Infer the index of this invocation
       def cmdList = cmd.getCmd()
       def matcher = (cmdList[cmdList.length - 1] =~ /.*Executor (\d*).*/)
@@ -105,7 +118,6 @@ def dockerConfig = {
       def workdir = new File(cmd.getWorkingDir() + matcher[0][1])
       workdir.mkdirs()
       cmd.withWorkingDir(workdir.toString())
-
       //println cmd
     }
   }

Reply via email to