GC

背景

现场排查OOM,对于GC的一些理解。

杂项记录

https://vladmihalcea.com/improve-statement-caching-efficiency-in-clause-parameter-padding/

http://technodibble.blogspot.com/2015/02/hibernate-in-clause-outofmemory.html

http://xmlandmore.blogspot.com/2014/10/jdk-8-is-tuning-maxnewsize-in-g1-gc.html

heap内存归还给操作系统:G1GC https://openjdk.org/jeps/346

https://www.youtube.com/watch?v=BTIcja5xcK0

https://www.youtube.com/watch?v=IB7oFVYTOJ0

https://gceasy.io/gc-recommendations/important-g1-gc-arguments.jsp
https://github.com/Snailclimb/JavaGuide/blob/83efb36fb56d197f2c4b471084b884c6a4f23e37/docs/books/java.md

https://www.douban.com/doulist/2545443/

https://www.baeldung.com/jvm-parameters
https://blog.csdn.net/myth_g/article/details/119855832
https://docs.oracle.com/en/java/javase/11/gctuning/introduction-garbage-collection-tuning.html#GUID-326EB4CF-8C8C-4267-8355-21AB04F0D304

https://programmer.ink/think/jvm-series-jvm-tuning-jps-jstat-jmap-jhat-jstack-jinfo.html

https://docs.oracle.com/javase/10/jrockit-hotspot/logging.htm#JRHMG121
https://confluence.atlassian.com/confkb/unrecognized-jvm-gc-options-when-using-java-11-1002472841.html

https://dzone.com/articles/understanding-garbage-collection-log

https://sematext.com/blog/java-garbage-collection-tuning/

https://sematext.com/blog/java-garbage-collection-tuning/

https://cloud.tencent.com/developer/article/1811734

https://docs.oracle.com/en/java/javase/11/tools/jstat.html#GUID-5F72A7F9-5D5A-4486-8201-E1D1BA8ACCB5

https://www.javatang.com/archives/2017/10/19/51301886.html

https://morioh.com/p/935f204ccc1a

https://dzone.com/articles/jvm-tuning-using-jcmd

https://sematext.com/blog/java-garbage-collection-logs/

MAT

dump文件分析用的MAT。

https://zhanglvmeng.gitbooks.io/mat-usage/content/kai-shi-shi-yong/yan-shen-yue-du/shi-yong-mat-de-10-ge-jian-yi.html

线程分析

https://geekflare.com/generate-analyze-thread-dumps/

https://blog.fastthread.io/2016/02/22/thread-dump-analysis-pattern-repetitive-strain-injury-rsi/

当应用程序出现性能瓶颈时,大部分线程将开始在有问题的瓶颈区域累积。这些线程将具有相同的堆栈跟踪。因此,每当大量线程表现出相同/重复的堆栈跟踪时,就应该调查这些堆栈跟踪。这可能表示性能问题。

以下是一些这样的场景:

  • 假设您的 SOR 或外部服务正在变慢,那么大量线程将开始等待其响应。在这种情况下,这些线程将显示相同的堆栈跟踪。
  • 假设一个线程获得了一个锁并且它从未释放,那么在同一执行路径中的其他几个线程将进入阻塞状态,显示相同的堆栈跟踪。
  • 如果循环(for 循环、while 循环、do..while 循环)条件未终止,则执行该循环的多个线程将显示相同的堆栈跟踪。
    当出现上述任何一种情况时,应用程序的性能和可用性都会受到质疑。

重点关注:Troubleshooting Tools、Monitoring Tools
https://docs.oracle.com/en/java/javase/11/tools/tools-and-command-reference.html

https://programmer.ink/think/jvm-series-jvm-tuning-jps-jstat-jmap-jhat-jstack-jinfo.html

https://www.hollischuang.com/archives/110

线程状态产生的原因

  • runnable:状态一般为RUNNABLE。

  • in Object.wait():等待区等待,状态为WAITING或TIMED_WAITING。

  • waiting for monitor entry:进入区等待,状态为BLOCKED。

  • waiting on condition:等待区等待、被park。

  • sleeping:休眠的线程,调用了Thread.sleep()。

https://jakubstransky.com/2017/12/19/hotspot-jvm-internal-threads/

Tomcat线程模型

NIO: synchronous and non blocking. It can support large concurrency better than traditional bio. This mode is adopted by default after Tomcat 8.0.

NiO

https://developpaper.com/nio-optimization-principle-and-tomcat-thread-model/

Tomcat’s NiO model has more poller rolesAcceptor、PollerandHandler worker thread pool。 Are these three roles very familiar? If poller is replaced by reactor, is it the reactor model. Yes, Tomcat’s NiO model is based onMaster slave reactor modelIt’s just a change of name.

AcceptorThe: accepter thread is specifically responsible for establishing network connections(accept)。 After the new connection is created, instead of directly using the worker thread to process the request, the request is first sent to the poller buffer queue.
Poller: in poller, a selector object is maintained. After poller takes the connection from the buffer queue, it registers in the selector and blocks to wait for read and write ready(Read wait ready, send wait ready)。
Handlers: traverse the selector to find out the ready IO operations in the selector and hand them over to the worker thread for processing(Read memory read, decode, process, encode, send memory write)。

https://www.cnblogs.com/grey-wolf/p/13740845.html

调优
https://tomcat.apache.org/tomcat-9.0-doc/config/http.html
https://www.datadoghq.com/blog/tomcat-architecture-and-performance/