首先启动 Tomcat 5.5.20 的时候总是会显示这样的 log, 我用的是 Windows 版本:
2006-12-22 15:04:41 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
信息: The Apache Tomcat Native library which allows optimal performance in produ
ction environments was not found on the java.library.path: E:\_PortableJava\JDK1
.6.0\bin;.;D:\WINDOWS\Sun\Java\bin;D:\WINDOWS\system32;D:\WINDOWS;
...
信息: Server startup in 2078 ms
那么我们去下载tcnative-1.dll后放在 Tomcat 的 bin 目录下, 启动后就会输出这样的信息:
2006-12-22 15:03:03 org.apache.coyote.http11.Http11AprProtocol init
信息: Initializing Coyote HTTP/1.1 on http-8080
2006-12-22 15:03:03 org.apache.coyote.ajp.AjpAprProtocol init
...
信息: Server startup in 1938 ms
可 以看到 Tomcat 启动的速度明显加快了, 甚至在加载了应用之后也是如此. 那么 Apache Tomcat Native library 是干什么的呢? 原来这是 Apache 为了提升 Tomcat 的性能搞的一套本地化 Socket, Thread, IO 组件.
Tomcat can use the Apache Portable Runtime to provide superior scalability, performance, and better integration with native server technologies. The Apache Portable Runtime is a highly portable library that is at the heart of Apache HTTP Server 2.x. APR has many uses, including access to advanced IO functionality (such as sendfile, epoll and OpenSSL), OS level functionality (random number generation, system status, etc), and native process handling (shared memory, NT pipes and Unix sockets).
These features allows making Tomcat a general purpose webserver, will enable much better integration with other native web technologies, and overall make Java much more viable as a full fledged webserver platform rather than simply a backend focused technology.
也就是说它有高级 IO 功能, 操作系统级别的功能调用, 以及本地进程处理等等, 这些都能使 Tomcat 更像一个 Web Server(像Apache那样), 而不是只能用来解释 JSP, 也就是说提升单独的 Tomcat 作为服务器的吞吐性能.
如何检查有没有启用这些功能呢? 参考1.2中的链接的介绍:
一 旦这些组件正确的安装并且可供java调用 (如果加载失败, 库文件路径将被显示在控制台), Tomcat 连接器将自动使用 APR 功能. APR连接器的配置与普通连接器的配置基本相同, 但是提供了一些扩展的属性供APR组件使用。 注意:默认值已经适用于大多数的应用场景, 额外的调整不是必须的。
当APR可用之后, 以下特性将在Tomcat中可用:
- Secure session ID generation by default on all platforms (platforms other than Linux required random number generation using a configured entropy)
- Tomcat进程的内存占用率和CPU占用率将被 status servlet 显示。
有个简单的办法, 就是点击 Tomcat 启动后首页的 Status, 可以看到启用了 APR 之后多出了下列信息:
OS
Physical memory: 1022.45 MB Available memory: 433.33 MB Total page file: 2472.66 MB Free page file: 1196.89 MB Memory load: 57
Process kernel time: 0.812 s Process user time: 4.656 s
JVM
Free memory: 0.94 MB Total memory: 8.66 MB Max memory: 63.56 MB
参考资料里面有一些台湾人士的测试报告.
参考资料:
-
Apache Portable Runtime and Tomcat http://tomcat.apache.org/tomcat-5.5-doc/apr.html http://tomcat.jaxmao.org/apr.html(部分中文翻译)
- 下载地址: http://tomcat.heanet.ie/native/1.1.8/binaries/win32/ 只需要 tcnative-1.dll .
- Tomcat 的 APR 連接器簡易測試 http://www.javaworld.com.tw/jute/post/view?bid=9&id=139958&sty=1&tpg=1&age=0
- Native Tomcat in SLAX http://blog.extremepattern.com/articles/2006/09/11/native-tomcat-in-slax