Java 程序的参数调优

Posted on Tue 15 September 2020 in Journal

Quote

JVM tuning

-XX:+AlwaysPreTouch

Pre-touch the Java heap during JVM initialization. Every page of the heap is thus demand-zeroed during initialization rather than incrementally during application execution.

在JVM初始化期间预先触摸Java堆。 因此,堆的每个页面都在初始化期间按需清零,而不是在应用程序执行期间递增。

  • NMT (Native Memory Tracking)

本地内存跟踪, 参见 https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/tooldescr007.html

The Native Memory Tracking (NMT) is a Java HotSpot VM feature that tracks internal memory usage for a Java HotSpot VM

Follow these steps to detect a memory leak.

  1. Start the JVM with summary or detail tracking using the command line option: -XX:NativeMemoryTracking=summary or -XX:NativeMemoryTracking=detail .

  2. Establish an early baseline - use NMT baseline feature to get a baseline to compare during development and maintenance by running: jcmd <pid> VM.native_memory baseline.

  3. Monitor memory changes using: jcmd <pid> VM.native_memory detail.diff .

  4. If the application leaks a small amount of memory, it make take a while to show up.

使用 java -XX:+PrintFlagsFinal -version 来打印 JVM options

$java -XX:+PrintFlagsFinal -version | wc -l
557

$java -XX:+PrintFlagsFinal -XX:+UnlockDiagnosticVMOptions -version | wc -l
728

$java -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+PrintFlagsFinal -version | wc -l
809

Netty tuning

refer to https://dzone.com/articles/thousands-of-socket-connections-in-java-practical

 -Dio.netty.allocator.maxOrder=4
 -Djdk.nio.maxCachedBufferSize=131072
 -Dio.netty.tryReflectionSetAccessible=true
 -Dio.netty.eventLoopThreads=16

btw. 配置尽量用环境变量,不要用配置文件或者配置表,这样比较方便的修改配置,也比较灵活

English

  • arena 英 [əˈriːnə] 美 [əˈriːnə]

n. 舞台;竞技场

  • vulnerability 英 [ˌvʌlnərəˈbɪləti] 美 [ˌvʌlnərəˈbɪləti]

n. 易损性;弱点

  • willfully 英 ['wilfəli] 美 [ˈwɪlfəli]

adv. 故意地;任性固执地

  • breach 英 [briːtʃ] 美 [briːtʃ]

n. 违背,违反;缺口 vt. 违反,破坏;打破

  • malware 英 [ˈmælweə(r)] 美 [ˈmælwer]

n. 恶意软件