我的项目目前正在运行Tomcat 7上。我应该升级到Tomcat 8吗?这样做的利弊如何?在性能和内存利用方面,Tomcat 8是否更好?
考虑到你的项目已经运行在Tomcat 7上,我建议保持现状一段时间。目前关于Tomcat 8性能改进的数据还不是很多。一些问题已经被报告在互联网上,这在任何产品新版本发布时都很常见。
Tomcat 8在并发环境下有更好的性能表现。
根据我对Tomcat产品的经验,除非你的应用程序非常需要资源,否则升级可能不会带来显著的性能提升。在进行升级之前,请阅读下面的链接。
Java 1.7 ==> 第一个重要的更改是,Tomcat 8现在需要Java 7或更高版本才能运行,因此如果你从早期的Tomcat版本迁移,你应该升级到Java 7。
Specification Changes
Servlet 3.1 (JSR 340)
JSP 2.3 (JSR 245 maintenance release)
EL 3.0 (JSR 341)
WebSocket 1.0 (JSR 356)
Specification Changes: EL 3.0
Coercion of nulls to Number, Character or Boolean
- EL 2.2 and earlier (0, 0, false)
- EL 3.0 and later (null, null, null)
System property
– org.apache.el.parser.COERCE_TO_ZERO
– Set to true for EL 2.2 behaviour
Specification Changes: JSP 2.3
Minor changes to reflect the changes in EL 3.0
JSP 2.3
– Supported: GET, POST and HEAD
– Undefined: Everything else
JSP 2.2 and earlier
– Undefined: Most implementations assumed all
Tomcat only permits GET, POST and HEAD
– Protection against verb tampering
Specification Changes: WebSocket 1.0
Tomcat 7 initially shipped with a proprietary WebSocket API
- Tomcat 8 ships with a JSR 356 WebSocket implementation
– Also back-ported to Tomcat 7
- The proprietary WebSocket API is deprecated in Tomcat 7
- Applications using the proprietary API need to migrate
– Relatively simple
– https://svn.apache.org/r1424733
Specification Changes: Servlet 3.1
- Session ID changes by default on authentication
– Prevents session fixation
Tomcat Changes:
Connectors
Default connector has changed from BIO to NIO
– BIO is likely to be dropped for Tomcat 9
- Only BIO option not supported by NIO is irrelevant for NIO
– disableKeepAlivePercentage
- May notice different network / CPU loads
– More established, idle connections
– Marginally higher CPU load
Static Resources
Tomcat 7
– Aliases
– VirtualLoader
– VirtualDirContext
– JAR resources
– External repositories
- All variations on a theme
- Each implemented differently
Tomcat 8
– New WebResources implementation
▪ JAR resources
– External resources for class loader
- Completely new configuration
- Caching attributes removed from Context
Resources now defined by as:
– Pre-resources
– Main resources
– JAR resources
– Post-resources
Resources attributes:
– base
– internalPath
– webappMount
– readOnly
Internal APIs
- Lots of changes
– Manager, Loader and Resources are now Context only
– Mapper moved from Connector to Service
– WebResources
- If you extend a Tomcat class, review the API docs
Database Connection Pools
- Tomcat 7 and earlier based on DBCP 1
- Tomcat 8 based on DBCP 2
- Better performance in concurrent environments
– Comparable to Tomcat’s JDBC pool
- There are some changes to configuration attributes
– Reflect consistency changes made in Commons Pool 2
- maxActive -> maxTotal
- maxWait -> maxWaitMillis
- Validation no longer requires a validation query
– Uses Connection.isValid()
服务器连接器
就服务器连接器而言,Tomcat 8 默认的 HTTP 和 AJP 连接器实现已从 Java 阻塞 IO 实现(BIO)切换到 Java 非阻塞 IO 实现(NIO)。旧的 BIO 仍然可以使用,但是使用非阻塞 IO 的 Servlet 3.1 和 WebSocket 1.0 功能将会回退到阻塞 IO,这可能会导致意外的应用程序行为。
Web 应用资源
现在,作为配置的一部分并表示 Web 应用程序中可用资源的 Resources 元素已经进行了修改。它现在包括类、JAR 文件、HTML、JSP 以及任何其他有助于 Web 应用程序的文件。可以使用目录、JAR 文件和 WAR 文件作为这些资源的来源,并且可以扩展资源实现以支持存储在其他形式中的文件,例如数据库或版本化存储库中的文件。
远程调试
启动带有 jpda 选项以启用远程调试的 Tomcat 8,默认情况下会侦听 localhost:8000。早期版本侦听 *:8000。如果需要,可以通过在 setenv.[bat|sh] 中设置 JPDA_ADDRESS 环境变量来覆盖此默认值。
API 更改
虽然 Tomcat 8 的内部 API 与 Tomcat 7 大体兼容,但在细节层面上发生了许多更改,它们不是二进制兼容的。与 Tomcat 内部交互的自定义组件的开发人员应查看相关 API 的 JavaDoc。
特别需要注意的是:
管理器(Manager)、装载器(Loader)和资源(Resources)已从容器(Container)移动到上下文(Context),因为上下文是唯一使用它们的地方。
Mapper 已从连接器(Connector)移到服务(Service),因为 Mapper 对于给定 Service 的所有 Connector 都是相同的。
有一个新的 Resources 实现,就像我们说的,它将别名(Aliases)、虚拟装载器(VirtualLoader)、虚拟目录上下文(VirtualDirContext)、JAR 资源和外部存储库合并为单个框架,而不是针对每个功能单独实现一个框架。
以下是提供有关 Tomcat 8 更改的更多信息的链接
http://people.apache.org/~markt/presentations/2013-09-Apache-Tomcat8.pdf