从 Java 1.4.2 更新到 Java 6(均为 Sun VM)会导致性能下降
我刚刚将一些在 Sun Java 1.4.2 VM 上运行的旧 Java 源代码升级到了 Sun Java (JRE) 6 VM。 或多或少,我唯一需要改变的就是为一些抽象对象(Hashmap、Vector 等)添加显式数据类型。 代码本身相当内存密集,使用高达 1G 的堆内存(使用 -Xmx1024m 作为启动 VM 的参数)。
由于我阅读了大量有关较新 Java VM 的更好性能的文章,这就是我进行此次升级的原因之一。
- 谁能想到我现在的情况下性能更差的原因(当然,只是一般情况,因为你无法查看代码)?
- 如果我想优化(速度方面)现有代码,有谁能给非 Java 专家一些建议吗? 有什么提示、推荐文档、工具吗?
谢谢。
I've just upgraded some old Java source which has been running on a Sun Java 1.4.2 VM to Sun Java (JRE) 6 VM. More or less the only thing I had to change was to add explicit datatypes for some abstract objects (Hashmap's, Vector's and so on). The code itself it quite memory intensive, using up to 1G of heap memory (using -Xmx1024m as a parameter to start the VM).
Since I read alot about better performance on newer Java VM's, this was one of the reasons I did this upgrade.
- Can anyone think of a reason why the performance is worse in my case now (just in general, of course, since you can't take a look at the code)?
- Has anyone some advice for a non Java guru what to look for if I wanted to optimize (speed wise) existing code? Any hints, recommended docs, tools?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这里没有太多信息。 但这里有一些您可能想要探索的事情:
使用 Xmx 和 Xms 作为相同的值(在您的情况下为 1024M)启动 VM
确保使用服务器 jvm dll 来启动虚拟机。
运行分析器以查看哪些对象占用内存或哪些对象没有被垃圾收集
连接您的虚拟机使用 jconsole 并跟踪对象
Not much information here. But here are a couple of things you might want to explore:
Start the VM with Xmx and Xms as the same value (in your case 1024M)
Ensure that the server jvm dll is being used to start the virtual machine.
Run a profiler to see what objects are hogging memory or what objects are not being garbage collected
Hook up your VM with the jconsole and trace through the objects
如果您的应用程序几乎耗尽可用空间,则垃圾收集时间可能会主导计算时间。
启用 gc 调试来查找此内容。 或者,更好的是,只需启动 jconsole 并将其附加到您的程序即可。
If your application nearly runs out of free space, garbage collection time may dominate computation time.
Enable gc debugging to look for this. Or, even better, simply start jconsole and attach it to your program.
从理论上讲,您的应用程序可能会消耗更多内存,因为字符串共享其内部 char[] 的方式发生了变化。 1.4之后共享较少。
查看我的旧博客 http://www. sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/5100(新博客是 这里)
我会比较垃圾收集器日志,看看内存使用是否真的是问题所在。
如果这没有帮助,我们可以使用 Yourkit 等分析器来查找差异。
Theoretically it could be that you application consumes more memory, because there were changes to the way Strings share their internal char[]. Less sharing is done after 1.4.
Check my old blog at http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/5100 (new blog is here)
I would compare the Garbage Collector logs to see whether memory usage is really the problem.
If that doesn't help, us a profiler such as Yourkit to find the differences.
一定要在应用程序上使用分析器(YourKit 很棒)...当大多数时候您可以在分析器中快速缩小问题范围时,很容易浪费大量时间猜测问题。
Definitely use a profiler on the app (YourKit is great)...it's easy to waste a lot of time guessing at the problem when most of the time you'll be able to narrow it down really quickly in the profiler.