Grails / Java Web Hosting - 32 or 64-Bit JVM on 64-Bit VPS?
64-bit OS on VPS offers 64-bit JVM
Virtual private servers are offered with 32-bit and 64-bit operation
systems since x86-64 server hardware is deployed more frequently at
hosting companies. This gives you the choice to select an 64-bit JVM or
an 32-Bit JVM. Which one should you choose?
Pros and Cons of 64-bit JVMs
To be more specific I'll discuss the most frequent environment of a 64-bit Linux distribution on x86-64 hardware with a Sun Java 6 JVM. On Linux you have to choose between a 32-bit and a 64-bit Java JVM. The "-d64" command line parameter is accepted only for compatibility and "-d32" does not work an a 64-bit JVM like in Solaris.
Pro:
- large adress space for objects, surpasses the 2gb barrier of 32-bit
- performance gain because of 16 instead of 8 general purpose CPU registers
- performance gain through use of optimized x64-64 CPU commands
- performance gain because of Hot-Spot JIT for 64-bit server mode
Cons:
- at least 60% more memory consumption for the same application, according to reports
- performance penalty due to 8 byte address data instead of 4 byte
- performance penalty due to possible lack of Hot-Spot optimization
If it was only for the address space your choice would be easy: you almost never have more than 2gb main memory on a virtual private server (VPS). If the performance gain due to additional registers outweights the performance loss of bigger address handling depends on your application. Compute intensive applications would profit, but data intensive ones would loose over all. How about getting those advantages without paying the memory penalty? Bring in the idea of optimized, compressed oops:
Optimized compressed oops saves memory
The idea is to save object references as 32-bit values (compressed) and decompress them to 64-bit when used. The memory penalty is only 16% instead of 60% according to some early benchmarks from Ismael Juma in his blog entry "32-bit or 64-bit JVM? How about a Hybrid?". This is an experimental feature now, but a promising one. It'll surely take some time until it gets available on the Linux distributions offered by providers.
Why 64-bit virtual server OS at all?
You may ask, if 64-bit always means higher memory requirements not only for JVMs but all applications, why do hosting providers offer 64-bit operation systems at all? The answer is the economy of scale. Providers want to sell there servers to more customers. Bigger servers means more main memory. The current available main memory sizes surpass the magical border of 2-4gb for many 32-bit applications. And the x64-64 architecture has some performance gains on top of memory to offer. So you'll see more and more 64-bit offers until 32-bit is phased out completely.
Recommendation
Choose a 32-bit OS if you can to save on memory. If you cannot choose or your favorite distribution is only available as a 64-bit variant install the 32-bit JVM. And for the future keep an eye on the progress of the compressed oops feature for 64-bit JVMs.
