我發現一個來源描述了默認 gc 使用的更改取決于可用資源。似乎 jvm 使用 g1gc 或串行 gc 依賴于硬體和作業系統。
在某些硬體和作業系統配置上默認選擇串行收集器
有人可以指出更詳細的來源,說明具體標準是什么以及如何將其應用于 dockerized/kubernetes 環境。換句話說:
可以將 k8s 中 pod 的資源請求設定為 eg。1500 mCpu 使 jvm 使用串行 gc 并更改為 2 Cpu 將默認 gc 更改為 g1gc?使用哪個 gc 的限制是否會根據 jvm 版本(11 與 17)而改變?
uj5u.com熱心網友回復:
在當前的 OpenJDK 中,“服務器類機器”默認選擇 G1 GC,否則選擇 Serial GC。“服務器級機器”定義為具有 2 個或更多非 HT CPU 和 2 個或更多 GiB RAM 的系統。
可以在src/hotspot/share/runtime/os.cpp 中找到確切的演算法:
// This is the working definition of a server class machine:
// >= 2 physical CPU's and >=2GB of memory, with some fuzz
// because the graphics memory (?) sometimes masks physical memory.
// If you want to change the definition of a server class machine
// on some OS or platform, e.g., >=4GB on Windows platforms,
// then you'll have to parameterize this method based on that state,
// as was done for logical processors here, or replicate and
// specialize this method for each platform. (Or fix os to have
// some inheritance structure and use subclassing. Sigh.)
// If you want some platform to always or never behave as a server
// class machine, change the setting of AlwaysActAsServerClassMachine
// and NeverActAsServerClassMachine in globals*.hpp.
bool os::is_server_class_machine() {
// First check for the early returns
if (NeverActAsServerClassMachine) {
return false;
}
if (AlwaysActAsServerClassMachine) {
return true;
}
// Then actually look at the machine
bool result = false;
const unsigned int server_processors = 2;
const julong server_memory = 2UL * G;
// We seem not to get our full complement of memory.
// We allow some part (1/8?) of the memory to be "missing",
// based on the sizes of DIMMs, and maybe graphics cards.
const julong missing_memory = 256UL * M;
/* Is this a server class machine? */
if ((os::active_processor_count() >= (int)server_processors) &&
(os::physical_memory() >= (server_memory - missing_memory))) {
const unsigned int logical_processors =
VM_Version::logical_processors_per_package();
if (logical_processors > 1) {
const unsigned int physical_packages =
os::active_processor_count() / logical_processors;
if (physical_packages >= server_processors) {
result = true;
}
} else {
result = true;
}
}
return result;
}
uj5u.com熱心網友回復:
在 JDK 11 和 17 中,Serial當只有一個 CPU 可用時使用收集器。否則G1被選中
如果您限制容器可用的 CPU 數量,JVM 會選擇Serial而不是默認G1
JDK11
1 個 CPU
docker run --cpus=1 --rm -it eclipse-temurin:11 java -Xlog:gc* -version
[0.004s][info][gc] Using **Serial**
它用 Serial
多于一個 CPU
docker run --cpus=2 --rm -it eclipse-temurin:11 java -Xlog:gc* -version
[0.008s][info][gc ] Using G1
它用 G1
JDK17
1 個 CPU
docker run --cpus=1 --rm -it eclipse-temurin:17 java -Xlog:gc* -version
[0.004s][info][gc] Using Serial
它用 Serial
多于一個 CPU
docker run --cpus=2 --rm -it eclipse-temurin:17 java -Xlog:gc* -version
[0.007s][info][gc] Using G1
它用 G1
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/408243.html
標籤:
上一篇:java.util.function.Supplier的C#等價物是什么?
下一篇:在HashMap中列印唯一的字串
