最小化Java“预热”的技术或实用程序时间? [英] Technique or utility to minimize Java "warm-up" time?

查看:94
本文介绍了最小化Java“预热”的技术或实用程序时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我支持需要低延迟的Java消息传递应用程序(处理每条消息的时间<300微秒)。但是,我们的分析表明Sun Java虚拟机最初运行缓慢,并且在前5,000条消息之后加速。前5,000条消息的延迟为1-4毫秒。在大约前5000个后,后续消息有〜250微秒的延迟,偶尔有异常值。



通常认为这是Java应用程序的典型行为。但是,从业务角度来看,告诉客户他们必须等待JVM热身才能看到他们所要求的性能是不可接受的。在处理第一个客户消息之前,应用程序需要预热



JVM是Sun 1.6.0更新4.



克服此问题的想法:


  1. JVM设置,例如-XX:CompileThreshold =

  2. 添加组件以在启动时预热应用程序,例如通过应用程序发送假消息。

  3. 在应用程序启动时静态加载应用程序和JDK类,以便在处理客户消息时不从JAR加载类。

  4. 完成上述两个想法中的一个或两个的一些实用程序或Java代理,这样我就不必重新发明轮子了。

注意:显然,对于这个解决方案,我正在考虑所有因素,包括芯片拱,磁盘类型和配置以及操作系统设置。但是,对于这个问题,我想集中讨论如何优化Java应用程序并最大限度地减少预热时间。

解决方案

< Java中的热身通常有两件事:



(1):懒惰类加载:这可以通过强制加载来解决。 / p>

这样做的简单方法是发送虚假消息。您应确保虚假消息将触发对类的所有访问。例如,如果你发送一条空信息,但你的程序会检查信息是否为空,并且避免做某些事情,那么这将不起作用。



另一种方法程序启动时通过访问该类来强制进行类初始化。



(2):实时优化:在运行时,Java VM将优化部分码。这就是为什么有一个预热时间的主要原因。



为了简化这一点,你可以发送一堆假的(但看起来真实的)消息,以便优化可以在用户使用之前完成。



您可以帮助缓解此问题的另一个方法是支持内联,例如尽可能多地使用private和final。原因是,VM不需要查找继承表来查看实际调用的方法。



希望这会有所帮助。


I am supporting a Java messaging application that requires low latency (< 300 microseconds processing each message). However, our profiling shows that the Sun Java Virtual Machine runs slowly at first, and speeds up after the first 5,000 messages or so. The first 5,000 messages have latency of 1-4 milliseconds. After about the first 5,000, subsequent messages have ~250 microseconds latency, with occasional outliers.

It's generally understood that this is typical behavior for a Java application. However, from a business standpoint it's not acceptable to tell the customer that they have to wait for the JVM to "warm-up" before they see the performance they demand. The application needs to be "warmed-up" before the first customer message is processed

The JVM is Sun 1.6.0 update 4.

Ideas for overcoming this issue:

  1. JVM settings, such as -XX:CompileThreshold=
  2. Add a component to "warm-up" the application on startup, for example by sending "fake messages" through the application.
  3. Statically load application and JDK classes upon application startup, so that classes aren't loaded from JARs while processing customer messages.
  4. Some utility or Java agent that accomplishes either or both of the above two ideas, so that I don't have to re-invent the wheel.

NOTE: Obviously for this solution I'm looking at all factors, including chip arch, disk type and configuration and OS settings. However, for this question I want to focus on what can be done to optimize the Java application and minimize "warm up" time.

解决方案

"Warm-up" in Java is generally about two things:

(1): Lazy class loading: This can be work around by force it to load.

The easy way to do that is to send a fake message. You should be sure that the fake message will trigger all access to classes. For exmaple, if you send an empty message but your progrom will check if the message is empty and avoid doing certain things, then this will not work.

Another way to do it is to force class initialization by accessing that class when you program starts.

(2): The realtime optimization: At run time, Java VM will optimize some part of the code. This is the major reason why there is a warm-up time at all.

To ease this, you can sent bunch of fake (but look real) messages so that the optimization can finish before your user use it.

Another that you can help to ease this is to support inline such as using private and final as much as you can. the reason is that, the VM does not need to look up the inheritance table to see what method to actually be called.

Hope this helps.

这篇关于最小化Java“预热”的技术或实用程序时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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