title: Slow service response Times : Java SecureRandom & /dev/random
body: <p>I am trying to debug a few slow responses served by an app deployed on Tomcat.
  Right now I am focussing on <code>SecureRandom</code> and <code>/dev/random</code> (some of the other probable causes have been investigated and ruled out).
  The pattern is as follows:</p>
  
  <ul>
  <li>The first call takes exactly <strong>30.0</strong>xy seconds after Tomcat restart (even if the request arrives 4 minutes after the Startup)</li>
  <li>Later, some calls take exactly <strong>15.0</strong>pq seconds (there was no specific pattern that I could establish, <em>pq</em> being the time approximate time taken in TP99)</li>
  </ul>
  
  <p>The service call involves encryption and decryption (<em>AES/ECB/PKCS5Padding</em>).</p>
  
  <p><em>Is it possible that SecureRandom init/repopulating is leading to this?</em></p>
  
  <p>(Although, there is a log written in catalina.log that says <code>"Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [28,760] milliseconds."</code>)</p>
  
  <p>Also, in order to check whether <code>/dev/random</code> or <code>/dev/urandom</code> is being used, I used the test from <a href="https://security.stackexchange.com/a/40634/20446">this question</a>. To my surprise, I didn't see reads from either of them unlike the way it happens in the linked question.
  These are the last few lines from the <code>strace</code> log:</p>
  
  <pre><code>3561  lstat("/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/jsse.jar", {st_mode=S_IFREG|0644, st_size=258525, ...}) = 0
  3561  open("/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/jsse.jar", O_RDONLY) = 6
  3561  stat("/dev/random", {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 8), ...}) = 0
  3561  stat("/dev/urandom", {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 9), ...}) = 0
  3561  open("/dev/random", O_RDONLY)     = 7
  3561  open("/dev/urandom", O_RDONLY)    = 8
  3561  unlink("/tmp/hsperfdata_xxxx/3560") = 0
  </code></pre>
  
  <p>What is then being used for seeding SecureRandom?</p>
  
  <p>fyi, <em>java -version</em></p>
  
  <pre><code>java version "1.6.0_32"
  OpenJDK Runtime Environment (IcedTea6 1.13.4) (rhel-7.1.13.4.el6_5-x86_64)
  OpenJDK 64-Bit Server VM (build 23.25-b01, mixed mode)
  </code></pre>