空闲后对JVM JIT进行优化 [英] JVM JIT deoptimization after idle

查看:101
本文介绍了空闲后对JVM JIT进行优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我主要使用Java编写宠物项目,这些项目大部分时间都是空闲的.在闲置数小时/天后,响应时间增加到几秒钟(最多10s),然后慢慢减少到200-300ms.

I use Java primarily for writing pet projects, which are idle most of the time. And after being idle for hours/days response time increases to seconds (up to 10s), then slowly decreases back to 200-300ms.

据我了解,这是由于JIT

As far as I understand, this happens because of JIT deoptimization (optimized code becomes marked as a zombie, removed and later compiled again).

除非代码缓存已满,是否有任何方法可以禁止JVM对代码进行优化?对于这种情况,Java 9的AOT似乎是最好的解决方案,但我仍然没有设法使其正常工作.

Is there any way to forbid JVM to deoptimize code unless code cache is full? Java 9's AOT looks like the best solution for this case, but I still haven't managed to make it work.

UPD:和往常一样,正确的解决方案是显而易见的解决方案.看起来问题实际上是由交换引起的.尽管有12 GB的ram,其中有6个是可用的,但过一会儿,每个JVM的内存中约有100 MB被交换到了HDD.

UPD: And as always, the right solution is the obvious one. Looks like the problem was actually caused by swap. Despite 12 GB of ram, 6 of which were free, about 100 MB of every JVM's memory was swapped to HDD after a while.

尽管如此,@ apangin的答案对于遇到相同情况的其他人还是有用的,所以我在此留下这个问题.谢谢大家!

Nevertheless @apangin's answer can be useful for someone else who run into the same situation, so I leave this question here. Thanks all!

推荐答案

-XX:-UseCodeCacheFlushing完全禁用扫描的已编译方法.

-XX:-UseCodeCacheFlushing disables sweeping compiled methods altogether.

尽管这是给定问题的答案,但我高度怀疑这是否可以解决您原来的问题.

Though this is the answer to the given question, I highly doubt this will resolve your original problem.

当应用程序处于空闲状态时,NMethod清除程序也处于空闲状态. JIT编译如此的速度也不可能太慢,以至于热代码被(重新)编译需要花费数十秒的时间.文件缓存丢失,网络连接陈旧等都是导致这种速度降低的原因.

When an application is idle, NMethod sweeper is also idle. It is also unlikely that JIT compilation is so slow that it takes tens of seconds before the hot code is (re-)compiled. Flushed file caches, stale network connections etc. are more likely reasons for such slowdowns.

这篇关于空闲后对JVM JIT进行优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆