Skip to content

Commit

Permalink
补充jvm-options-setting.md
Browse files Browse the repository at this point in the history
  • Loading branch information
youngledo committed Mar 16, 2024
1 parent 6cd511f commit 7379c18
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
* [Netbeans profiler](java/tools/third/netbeans-profiler.md)
* [自定义](java/tools/third/custom.md)
* ❓疑难杂症
* [如何正确的设置JVM参数](java/troubleshoot/jvm-options-setting.md)
* [如何正确的设置JVM参数,以及pod内存疑问?](java/troubleshoot/jvm-options-setting.md)
* [如何分发Java制品到Maven仓库](java/troubleshoot/maven-distribution-artifact.md)

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions docs/java/troubleshoot/jvm-options-setting.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 如何正确的设置JVM参数,以及kubernates的pod内存疑问
# 如何正确的设置JVM参数,以及pod内存疑问

## 1. 如何正确的设置JVM参数?
随着服务容器化部署,特别是Docker、Kubernetes横行之下,如何正确的部署服务显得尤为重要,对于Java服务来说部署时设置JVM参数是个常见的事情。但大多数人并不清楚或并不了解在容器中如何正确的设置JVM参数,比如这样的:
Expand Down Expand Up @@ -27,10 +27,10 @@ Java 9之前用`JAVA_TOOL_OPTIONS`,之后用`JDK_JAVA_OPTIONS`。当然这也

![k8s-pod-memory-upgrade_java.png](assets%2Fk8s-pod-memory-upgrade_java.png)

- jhsdb jmap --heap --pid 1
- jcmd 1 VM.native_memory

![jcmd-VM.native_memory-upgrade_java.png](assets%2Fjcmd-VM.native_memory-upgrade_java.png)

![jvm-jhsdb-upgrade_java.png](assets%2Fjvm-jhsdb-upgrade_java.png)
明明我的服务堆内存以及其它堆外内存使用很少,为什么在kubernates中却显示有那么多?经过多番验证,终于在这篇文章上找到了:[kubernetes pod memory - java gc logs](https://stackoverflow.com/questions/61506136/kubernetes-pod-memory-java-gc-logs)以及[Does GC release back memory to OS?](https://stackoverflow.com/questions/30458195/does-gc-release-back-memory-to-os)

明明我的服务堆内存以及其它堆外内存使用很少,为什么在kubernates中却显示有那么多?经过多番验证,终于在这篇文章上找到了:[kubernetes pod memory - java gc logs](https://stackoverflow.com/questions/61506136/kubernetes-pod-memory-java-gc-logs)

**结论就是:因为垃圾收集器(比如G1)一旦使用了内存就不会再返还给操作系统了。不过好在这种情况已经在[JEP 346](https://openjdk.org/jeps/346)被提出了,并且[Java 12](https://openjdk.org/projects/jdk/12/)中修复了。**
**结论:由于不同版本、不同垃圾收集器采用的策略不一样,比如Java 12之前G1一旦使用了内存就不会再返还给操作系统了。不过好在这种情况已经在[JEP 346](https://openjdk.org/jeps/346)被提出了,并且[Java 12](https://openjdk.org/projects/jdk/12/)中修复了。**不过,默认情况下该策略是禁止的,可以通过`-XX:G1PeriodicGCInterval`参数来调节(默认值是0)。

0 comments on commit 7379c18

Please sign in to comment.