Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slow startup on Tomcat 7.0.57 because of SecureRandom

Tags:

java

tomcat7

I'm using Tomcat 7.0.57 on CentOS 6.6 32 bit and openJDK7. When I start 14 different instances of Tomcat on my server(production environment), many of them take too much time to start.

This is part of the startup log, which tells me where is taking all the time

Jan 28, 2015 2:49:41 PM org.apache.catalina.util.SessionIdGenerator createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [199,620] milliseconds.

What's the best practice/solution for this problem?

Thanks!

like image 311
Jose Monreal Bailey Avatar asked Jan 28 '15 20:01

Jose Monreal Bailey


People also ask

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.

Why isn't my Tomcat server is not starting?

Most common issue with Tomcat note starting is that Java is not configured properly, user trying to start Tomcat does not have permissions to do so, or another program is using port 8080 on that server.


2 Answers

I faced same issue of tomcat being too slow to start. I followed this article on DigitalOcean and installed haveged instead of using urandom.

haveged is a solution which will not compromise on security.

haveged allows generating randomness based on variations in code execution time on a processor. Since it's nearly impossible for one piece of code to take the same exact time to execute, even in the same environment on the same hardware, the timing of running a single or multiple programs should be suitable to seed a random source. The haveged implementation seeds your system's random source (usually /dev/random) using differences in your processor's time stamp counter (TSC) after executing a loop repeatedly

How to install haveged

Follow the steps in this article. https://www.digitalocean.com/community/tutorials/how-to-setup-additional-entropy-for-cloud-servers-using-haveged

I have posted it here

like image 128
so-random-dude Avatar answered Oct 22 '22 02:10

so-random-dude


The secure random calls may be blocking as there is not enough entropy to feed them in /dev/random.

If you have the line

securerandom.source=file:/dev/random

in /jre/lib/security/java.security, changing this to urandom may improve things (although this is probably already the default).

Alternatively there are some suggestions on how to feed the pool here

https://security.stackexchange.com/questions/89/feeding-dev-random-entropy-pool

like image 19
henry Avatar answered Oct 22 '22 00:10

henry