Tomcat 熵池阻塞變慢詳解
?
Tomcat 啟動很慢,且日志上無任何錯誤,在日志中查看到如下信息:
Log4j:[2015-10-29 15:47:11] INFO ReadProperty:172 - Loading properties file from class path resource [resources/jdbc.properties]
Log4j:[2015-10-29 15:47:11] INFO ReadProperty:172 - Loading properties file from class path resource [resources/common.properties]
29-Oct-2015 15:52:53.587 INFO [localhost-startStop-1] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [342,445] milliseconds.
- 1
- 2
- 3
- 4
原因
Tomcat 7/8都使用org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom類產生安全隨機類SecureRandom的實例作為會話ID,比較耗時。
是基于SHA-1算法實現且保密性較強的偽隨機數生成器。
非常適合那些需要非常高質量隨機性的場景,比如一次性的支付或生成密鑰的場景。對于生成高質量的加密密鑰或者是需要長期保護的場景,一定要這么做。
隨機數產生器會收集來自設備驅動器和其它源的環境噪聲數據,并放入熵池中。產生器會評估熵池中的噪聲數據的數量。當熵池為空時,這個噪聲數據的收集是比較花時間的。這就意味著,Tomcat在生產環境中使用熵池時,會被阻塞較長的時間。
解決
解決辦法:
在JVM環境中解決
打開$JAVA_PATH/jre/lib/security/java.security這個文件,找到下面的內容:
securerandom.source=file:/dev/urandom
替換成
securerandom.source=file:/dev/./urandom
轉載:http://blog.csdn.net/chszs
?