Presto日志中出现大量的Triggering GC to avoid Code Cache eviction bugs
問題描述:
Presto日志中出現(xiàn)大量的
2017-07-31T15:31:21.505+0800 INFO Code-Cache-GC-Trigger com.facebook.presto.server.CodeCacheGcTrigger Triggering GC to avoid Code Cache eviction bugsPresto版本為0.170。
排查過程:
1. 檢查Presto源碼
出現(xiàn)該條日志的代碼為
// Hack to work around bugs in java 8 (8u45+) related to code cache management. // See http://openjdk.5641.n7.nabble.com/JIT-stops-compiling-after-a-while-java-8u45-td259603.html for more info. MemoryPoolMXBean codeCacheMbean = findCodeCacheMBean();Thread gcThread = new Thread(() -> {while (!Thread.currentThread().isInterrupted()) {long used = codeCacheMbean.getUsage().getUsed();long max = codeCacheMbean.getUsage().getMax();if (used > 0.95 * max) {log.error("Code Cache is more than 95% full. JIT may stop working.");}if (used > (max * collectionThreshold) / 100) {// Due to some obscure bug in hotspot (java 8), once the code cache fills up the JIT stops compiling// By forcing a GC, we let the code cache evictor make room before the cache fills up.log.info("Triggering GC to avoid Code Cache eviction bugs");System.gc();}try {TimeUnit.MILLISECONDS.sleep(interval.toMillis());}catch (InterruptedException e) {Thread.currentThread().interrupt();}} });由代碼可知,Presto會啟一個后臺線程,每隔一定時間(默認20s)會檢查一次codecache的使用率,當(dāng)使用率大于一定的值時,會打印該日志,并顯式調(diào)用System.gc()。
而該類的作用,注釋也說的很清楚了,即用于繞過java 8 (8u45+)中關(guān)于code cache管理的bug(一旦code cache滿了,JIT就停止編譯了)。通過強制觸發(fā)一次GC,來騰出空間,避免code cache填滿。
我們知道System.gc()用于建議JVM進行Full GC。然而通過jstat觀察發(fā)現(xiàn),實際情況Minor GC的頻率很高,但是Major GC的次數(shù)為0。
2. 查閱資料
(1) https://groups.google.com/forum/#!topic/presto-users/inF0oLvOfqo
上文中作者最終修改CodeCacheSize為600M、code-cache-collection-threshold為60,情況好轉(zhuǎn)。他們的code cache一般在100M到230M, 不會超過配置的值: 600* 0.6 = 360M。
(2) https://news.ycombinator.com/item?id=12505517
上文中說到Presto is a SQL query engine that generates code for each query (a SQL query is effectively a program), so it can need a lot of codecache depending on the query rate and concurrency.
也就是presto會產(chǎn)生大量的類,也就需要jvm進行定期清理code cache。
由于code cache在方法區(qū),只有Major GC才能夠清理code cache。
3. 解決辦法
檢查當(dāng)前配置
通過以下2種方法都可以查詢當(dāng)前配置的code cache初始值與最大值。默認情況下,初始值為2.4MB,最大值為240MB。
java -XX:+PrintFlagsFinal -version -server | grep ReservedCodeCacheSize java -XX:+PrintCodeCache -version而當(dāng)前使用的量,就得通過jmx查詢了。好在presto自身提供了對jmx的查詢支持。
打開presto,執(zhí)行:
修改配置
由于使用量一般在120MB左右,所以我設(shè)置CodeCacheSize為300M,code-cache-collection-threshold為60。300*0.6=180MB,滿足要求。
(1)在config.properties文件添加code-cache-collection-threshold=60。
(2)在jvm.config添加-XX:ReservedCodeCacheSize=300M。
參考資料
http://openjdk.5641.n7.nabble.com/JIT-stops-compiling-after-a-while-java-8u45-td259603.html
https://groups.google.com/forum/#!topic/presto-users/inF0oLvOfqo
https://news.ycombinator.com/item?id=12505517
總結(jié)
以上是生活随笔為你收集整理的Presto日志中出现大量的Triggering GC to avoid Code Cache eviction bugs的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HiveJDBC与其他JDBC一起使用时
- 下一篇: 记录一次大对象导致的Java堆内存溢出问