How do I speed up the JVM?
I'm writing some java software that is being run on both Linux and Windows XP Embedded on a Vortex86 Chip. The software usually loads in 2-3 seconds in Windows XP but when I try and load it in Linux it takes around 10-12 seconds. I don't think its a code optimization issue because it takes 1 second to run a Hello 开发者_运维技巧World program.
Any suggestions would be greatly appreciated. Pre-loading java is an option because the machine will only be running these programs but I have no idea how to do that.
As Matt pointed out, there are many factors at play. With your incomplete description, it's impossible to make targeted recommendations. Having said that, here are a few things to try :
- Profile your memory utilization with -verbose:gc and increase the memory allotted to your program (java -Xms512m -Xmx512m)
- Check that the version of Java on both machines is roughly equivalent
- Check that the hardware on both machines is roughly equivalent
- Check whether both machines are quiet when you're measuring performance
- Make sure both are running in either 32-bit or 64-bit, and you're not reporting results from a mixed profile.
- Check for startup scripts that your program may be using for one platform, but may be missing for the other (e.g a run.properties)
If you have run Java before, the shared files and rt.jar will be in memory. i.e. pre-loaded for you. I can only imagine your Linux machine is very low on memory and it has to load everything from disk each time.
On my Linux box
$ time java -cp . HelloWorld
Hello World.
real 0m0.043s
user 0m0.030s
sys 0m0.010s
The total time to start and run is 0.043 seconds. Can you do a similar test with your hello world?
精彩评论