Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Faster random generator in Tomcat 7

Tags:

java

tomcat

I have the problem that Tomcat 7 is terribly slow on startup. I found this in the log file:

INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [12,367] milliseconds.

Security is important, sure, but not on my development machine. I could perfectly live with a standard fast random number generator. So I don't need this ridiculously slow SecureRandom implementation.

Question is: How can I disable it? Is searched for a solution but only found some deprecated info about a randomClass attribute which can be set to java.util.Random. I also found out that this attribute seems to be named secureRandomClass now in Tomcat 7. I tried to set it to java.util.Random but this fails because Tomcat 7 casts the object to java.util.SecureRandom (And it's also documented that the specified class must extend java.util.SecureRandom, so it's no longer possible to use java.util.Random instead.)

So how can I get rid of this terribly slow random number generator startup so my development tomcat starts/restarts as fast as possible?

like image 909
kayahr Avatar asked Sep 26 '11 12:09

kayahr


People also ask

Is SecureRandom slow?

Unfortunately, SecureRandom can be very slow. If it uses /dev/random on Linux, it can block waiting for sufficient entropy to build up.

Which method is used for improving performance of Tomcat with a database?

Connection pooling is a common technique for optimizing database accesses by having a pool of open connections so that requests can take connections from the pool and return connections back to the pool once they are done with their tasks.

Why Tomcat is taking too long to start?

If your Tomcat takes longer to start, it may be due to the random number generator that it is using. You might want to consider forcing it to use '/dev/urandom' rather than the default '/dev/random' that Tomcat uses.


1 Answers

According to TomCat Wiki you can use non blocking entropy source:

"There is a way to configure JRE to use a non-blocking entropy source by setting the following system property: -Djava.security.egd=file:/dev/./urandom"

like image 92
levsa Avatar answered Sep 25 '22 15:09

levsa