Limit the number of forks getting Java versions (#41386)
To reduce configuration time, we fork some threads to compute the Java version for the various configured Javas. However, as the number of JAVA${N}_HOME variable increases, the current implementation creates as many threads as there are such variables, which could be more than the number of physical cores on the machine. It is not likely that we would see benefits to trying to execute all of these once beyond the number of physical cores (maybe simultaneous multi-threading helps though, who knows. Therefore, this commit limits the parallelization here to the number number of physical cores.
This commit is contained in:
parent
c0164cbb63
commit
38b43c4a56
|
@ -197,9 +197,10 @@ class BuildPlugin implements Plugin<Project> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final int numberOfPhysicalCores = numberOfPhysicalCores(project.rootProject)
|
||||||
if (javaVersions.isEmpty() == false) {
|
if (javaVersions.isEmpty() == false) {
|
||||||
|
|
||||||
ExecutorService exec = Executors.newFixedThreadPool(javaVersions.size())
|
ExecutorService exec = Executors.newFixedThreadPool(numberOfPhysicalCores)
|
||||||
Set<Future<Void>> results = new HashSet<>()
|
Set<Future<Void>> results = new HashSet<>()
|
||||||
|
|
||||||
javaVersions.entrySet().stream()
|
javaVersions.entrySet().stream()
|
||||||
|
@ -247,7 +248,7 @@ class BuildPlugin implements Plugin<Project> {
|
||||||
project.rootProject.ext.inFipsJvm = inFipsJvm
|
project.rootProject.ext.inFipsJvm = inFipsJvm
|
||||||
project.rootProject.ext.gradleJavaVersion = JavaVersion.toVersion(gradleJavaVersion)
|
project.rootProject.ext.gradleJavaVersion = JavaVersion.toVersion(gradleJavaVersion)
|
||||||
project.rootProject.ext.java9Home = "${-> findJavaHome("9")}"
|
project.rootProject.ext.java9Home = "${-> findJavaHome("9")}"
|
||||||
project.rootProject.ext.defaultParallel = findDefaultParallel(project.rootProject)
|
project.rootProject.ext.defaultParallel = numberOfPhysicalCores
|
||||||
}
|
}
|
||||||
|
|
||||||
project.targetCompatibility = project.rootProject.ext.minimumRuntimeVersion
|
project.targetCompatibility = project.rootProject.ext.minimumRuntimeVersion
|
||||||
|
@ -1024,7 +1025,7 @@ class BuildPlugin implements Plugin<Project> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int findDefaultParallel(Project project) {
|
private static int numberOfPhysicalCores(Project project) {
|
||||||
if (project.file("/proc/cpuinfo").exists()) {
|
if (project.file("/proc/cpuinfo").exists()) {
|
||||||
// Count physical cores on any Linux distro ( don't count hyper-threading )
|
// Count physical cores on any Linux distro ( don't count hyper-threading )
|
||||||
Map<String, Integer> socketToCore = [:]
|
Map<String, Integer> socketToCore = [:]
|
||||||
|
@ -1037,7 +1038,7 @@ class BuildPlugin implements Plugin<Project> {
|
||||||
if (name == "physical id") {
|
if (name == "physical id") {
|
||||||
currentID = value
|
currentID = value
|
||||||
}
|
}
|
||||||
// Number of cores not including hyper-threading
|
// number of cores not including hyper-threading
|
||||||
if (name == "cpu cores") {
|
if (name == "cpu cores") {
|
||||||
assert currentID.isEmpty() == false
|
assert currentID.isEmpty() == false
|
||||||
socketToCore[currentID] = Integer.valueOf(value)
|
socketToCore[currentID] = Integer.valueOf(value)
|
||||||
|
@ -1055,8 +1056,11 @@ class BuildPlugin implements Plugin<Project> {
|
||||||
standardOutput = stdout
|
standardOutput = stdout
|
||||||
}
|
}
|
||||||
return Integer.parseInt(stdout.toString('UTF-8').trim())
|
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) {
|
private static configurePrecommit(Project project) {
|
||||||
|
|
Loading…
Reference in New Issue