Limiting JVM on VPS (Virtual Private Server)
4. Another trick
alias java='java -Xms32m -Xmx128m'
On *Nix systems, this alias would work just fine.
Up to this point, you should be able to find a solution that would let you run JVM within your VPS Hosting account. Below you will find a crucial difference between two important options for a JVM. Remember that when JVM evaluates the system on which is resides and finds out that RAM exceeds 2 gigabytes, it assumes that your system is a server for its use and will assume the option -Server.
java -server versus java client
J2SE 5.0 provides two implementations of the HotSpot Java virtual machine (JVM):
- The client VM is tuned for reducing startup time and memory footprint. Invoke it by using the -client JVM command-line option.
- The server VM is designed for maximum program execution speed. Invoke it by using the -server JVM command-line option.
By default, the Application Server uses the JVM setting appropriate to the purpose:
- Platform Edition, targeted at application developers, uses the -client JVM flag to optimize startup performance and conserve memory resources.
- Enterprise Edition, targeted at production deployments, uses the default JVM startup mode. With J2SE 5.0, the HotSpot VM provides server-class machine detection, which will use the server VM if it detects "server-class" hardware (at least two CPUs and 2 Gb of physical memory).
This is quite important because VPS servers are usually fully loaded with at 8 Gb of RAM or more to cater to more users on a single machine; therefore, JVM is quite happy with those numbers.
Fortunately, there are many different virtualization applications on the market, both commercial and open source, and provide different ways to configure the limits for each account; therefore, the JVM would not be able to detect such limits and assume default values.
Limiting Ant's Use of RAM
ANT is a neat and most popular build tool and is commonly used. Glassfish utilizes ANT as a way to install itself. You will be pleased to hear that you can limit its use of memory by using this variable:
ANT_OPTS=-Xmx64m
Conclusion
VPS hosting is the optimal and most affordable way to host your J2EE application, yet it isn't very easy to initially set up JVM to work as you wanted. The final result will be worth the effort.
Helpful Links
- Sun App Server FAQ on JVM: java.sun.com/docs/performance/appserver/AppServerPerfFaq.html#JVM1
- JVM Options: java.sun.com/javase/technologies/hotspot/vmoptions.jsp
- Behavioral Options (JVM): java.sun.com/javase/technologies/hotspot/vmoptions.jsp#BehavioralOptions
- If you'd like to read more on JVM, I would suggest these free books from SUN: java.sun.com/docs/books/jvms/index.html
About the Author
![]() |
Serge Bornow works as a freelance consultant in J2EE and .NET. His main interests are most current open source projects in J2EE, Ajax, and web development. He also plays tennis and enjoys traveling around the world. |
Page 2 of 2