The cost of 64-bit

64 bit in computing has always seemed a simply-has-to-happen kind of thing to me. 32 bit pointer only allow up to 4 GB of memory to be addressed, so, naturally, we have to move up to 64 bit to address more memory than that. Great. What I never thought of, however, are its costs in memory consumption.

Now sure, memory may seem cheap, it’s not so cheap when you want to run an application on a cheap VPS (Virtual Private Server). Cheap VPS’s typically come with 256 or 512MB of memory (which is what many $20–30/month VPS’s offer). If I want to run a Java web app on that, I better look at memory consumption. So, I have a VPS at Rackspace Cloud, which only offers 64-bit Linux operating systems as an option. So I run 64-bit ubuntu, now let’s look at memory consumption.

First, a cleanly started Java web app at which no requests have been fired:

So, if I read top’s output well, that uses about 89MB of memory (the RES column). That’s quite a bit, alright, now let’s stress it a little bit and fire 200 requests on it with 5 requests concurrently using apache benchmark:

Now the process uses 225MB (which is 39.1% of memory of my 512MB VPS).

What I can do is install a 32-bit JVM, which is kind of dirty, because it requires to install 32-bit version of the standard libraries.

$ apt-get install ia32-libs

Now, I download the 32 bit Linux JDK from the Sun site and run the application again using the 32-bit JVM.

Here is the memory consumption of a clean start of the same web application on a 32-bit JVM:

34MB of memory (versus 89MB on 64-bit). That’s quite a difference.

Now let’s fire the same 200 requests with 5 concurrent connections:

Now the application uses 164MB of memory. That’s about 61mb, or about 12% of the 512MB of RAM that I have available.

When you think of it, this is not all that surprising. Java application typically generate lots of small little object that contain pointers to other small objects. All those little pointers start to add up and double in size with the 64-bit JVM.

So, be sure to consider using a 32-bit JVM, even on a 64-bit OS, if memory matters to you.