You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by up...@apache.org on 2018/09/07 19:27:11 UTC

[geode] 02/03: Adding an option to limit the number of CPUs for docker

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 0ab08672aa5964ffb696dfe7c5fd13d631de1c6b
Author: Dan Smith <up...@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
     }
   }