22 May 2012

Oracle JDBC connections slow to connect /dev/urandom

If your JDBC connections to Oracle take a long time (many seconds) to connect, it could be due to a problem with the random number generator on Linux.

Apparently /dev/random is known to be slow in some instances at generating random numbers, so the solution is to change it to use /dev/urandom instead.

However, there is a further bug in Java 5 (and perhaps above) - if the value is set to /dev/urandom, it will be ignored, falling back to the default /dev/random.

The solution is to set it to /dev/./random instead.

To set the value, edit the java.security file in your JAVA_HOME and find the line starting securerandom.source and change it as below:

securerandom.source=file:/dev/./urandom

This simple change cut my connection times to Oracle from 5 - 10 seconds to almost instant on Cent OS 5.6 with Java 1.6.0 and the Oracle ojdbc6 drivers.

More info here, here and here

blog comments powered by Disqus