Fix: Tomcat taking very long to serve first request on fresh install on Ubuntu 14.04

Yesterday, I was trying to setup Apache Tomcat 7 on Ubuntu 14.04 on a new DigitalOcean droplet. But it was taking VERY long (10-15+ minutes) to serve first request. After that, it started serving requests normally. If the Tomcat was restarted, it again took very long to serve the first request.

I tried large droplets with more memory. Also, I tried installing Tomcat from both the Ubuntu repository package and from official Tomcat website. But in every case, I faced the same problem.

Turns out, the solution is pretty simple. We just need to install a package named  haveged like this:

Now restart Tomcat and you will see that it starts serving requests immediately at normal speed.

Basically what happens is that the entropy pools run dry on our virtual server running in the cloud. As a result, Tomcat blocks on /dev/random waiting for random numbers to be generated. Haveged seeds our system’s random source (usually /dev/random) using differences in our processor’s time stamp counter (TSC) after executing a loop repeatedly. Please refer to this article on DigitalOcean for details of this process.

Linux: Check from command-line if your OS is 32 bit or 64 bit

Do you need to find out if your Linux installation is 32 bit or 64 bit? I usually need this information when manually installing a piece of software (e.g. Netbeans Profiler Remote Pack).

There are two alternative commands which produce identical output. You can use any one of these:

  1. arch
  2. uname -m

If any of these commands outputs  x86_64 then your Linux is 32 bit. On the other hand, if the output is  i686 or  i386 then you are running a 64 bit Linux distro.

For detailed discussion of these and some other useful, related commands, please checkout: http://www.howtogeek.com/198615/how-to-check-if-your-linux-system-is-32-bit-or-64-bit/