java - 在 web 服务器中提供静态内容,在 tomcat 中提供动态内容仍然是一个很好的性能实践吗?

标签 java performance architecture tomcat apache

在旧版本的 tomcat(如 3.2)中,您可以找到在 apache 网络服务器中提供静态内容并将动态内容留给 tomcat 本身的建议。 在新版本的 tomcat 文档中,即使在 mod_jk 配置教程中,您也找不到任何对此实践的引用。 所以我想知道。

tomcat 还不足以提供静态内容吗?如果我更改我的部署架构以分离静态和动态内容,我会提高性能吗?

最佳答案

关于纯速度,我建议阅读 Myth or truth: One should always use Apache httpd in front of Apache Tomcat to improve performance?博客文章。让我部分引用它:

The short answer is that this is a myth. The longer answer is that back in the days of Tomcat 3 there was some truth to this depending on circumstances. However, for the versions of Tomcat in use today (5.5.x and 6.0.x) then there is no need to use httpd for purely performance reasons. Tomcat now supports the native/APR connector which uses the same native library (the Apache Portable Runtime—APR) as httpd for the low-level I/O and therefore can achieve similar performance to httpd. When serving static content there is ever so slightly more overhead when using Tomcat compared to httpd but the differences are so small they are unlikely to be noticeable in production systems.

...

The performance testing performed by Christopher Schultz, a regular on the Tomcat users mailing list, used a wider range of file sizes and provides – in my view – better results. The results of his tests are shown in the graph below.

alt text

These results are much more in line with what is expected, although there are a few interesting points to note:

  • Apache httpd and Coyote APR/native show similar performance levels.
  • Coyote NIO isn't too far behind httpd and Coyote APR/native.
  • There appears to be a limit on the usefulness of sendfile. This may be a hardware limitation but is worthy of further attention. I've added this to my todo list.
  • For small file sizes (less than ~10KiB) the static file caching in Tomcat provides a significant performance boost.

...

While raw performance for static content may not be a good reason to use httpd, there are a number of good reasons why you might want to use httpd with Tomcat. The most frequent reason is to provide load-balancing to two or more Tomcat instances. httpd isn't the only option to so this - hardware load balancers or other reverse proxies can be used - but it is a popular choice amongst system administrators as many of them are already familiar with httpd. I'll write more on using httpd as a load-balancer in a future article.

...

值得一读。

话虽这么说,在 Tomcat 前面使用网络服务器来提供静态内容显然可以为动态内容释放更多的能力,因此是我最喜欢的选择。

关于java - 在 web 服务器中提供静态内容,在 tomcat 中提供动态内容仍然是一个很好的性能实践吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3677108/

相关文章:

java - 为什么 Tomcat 7 将 index.html 附加到 URL 而 Tomcat 6 不附加?

performance - 如何重写 "sapply"命令以提高性能?

objective-c - Objective C 架构问题

architecture - MVC4 WebAPI的正确架构是什么

javascript - React + flux : can action return a value?(例如最后创建的 id)

javascript - 使用 GSON 将 JSON 转换为 Java 对象

java - 如何生成构建器类

javax.net.ssl.SSLException : Received fatal alert: bad_record_mac 异常

Python Pandas 矩阵乘法 多项运算合二为一

C# 属性和元数据含义