diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy index 8219e1a2870..f1c6721aa0d 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy @@ -197,9 +197,10 @@ class BuildPlugin implements Plugin { } } + final int numberOfPhysicalCores = numberOfPhysicalCores(project.rootProject) if (javaVersions.isEmpty() == false) { - ExecutorService exec = Executors.newFixedThreadPool(javaVersions.size()) + ExecutorService exec = Executors.newFixedThreadPool(numberOfPhysicalCores) Set> results = new HashSet<>() javaVersions.entrySet().stream() @@ -247,7 +248,7 @@ class BuildPlugin implements Plugin { project.rootProject.ext.inFipsJvm = inFipsJvm project.rootProject.ext.gradleJavaVersion = JavaVersion.toVersion(gradleJavaVersion) project.rootProject.ext.java9Home = "${-> findJavaHome("9")}" - project.rootProject.ext.defaultParallel = findDefaultParallel(project.rootProject) + project.rootProject.ext.defaultParallel = numberOfPhysicalCores } project.targetCompatibility = project.rootProject.ext.minimumRuntimeVersion @@ -1024,7 +1025,7 @@ class BuildPlugin implements Plugin { } } - private static int findDefaultParallel(Project project) { + private static int numberOfPhysicalCores(Project project) { if (project.file("/proc/cpuinfo").exists()) { // Count physical cores on any Linux distro ( don't count hyper-threading ) Map socketToCore = [:] @@ -1037,7 +1038,7 @@ class BuildPlugin implements Plugin { if (name == "physical id") { currentID = value } - // Number of cores not including hyper-threading + // number of cores not including hyper-threading if (name == "cpu cores") { assert currentID.isEmpty() == false socketToCore[currentID] = Integer.valueOf(value) @@ -1055,8 +1056,11 @@ class BuildPlugin implements Plugin { standardOutput = stdout } return Integer.parseInt(stdout.toString('UTF-8').trim()) + } else { + // guess that it is half the number of processors (which is wrong on systems that do not have simultaneous multi-threading) + // TODO: implement this on Windows + return Runtime.getRuntime().availableProcessors() / 2 } - return Runtime.getRuntime().availableProcessors() / 2 } private static configurePrecommit(Project project) {