配置 Apache/Tomcat 的最佳实践 [英] Best practices for configuring Apache / Tomcat

查看:32
本文介绍了配置 Apache/Tomcat 的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们目前使用 Apache 2.2.3 和 Tomcat 5(嵌入在 JBoss 4.2.2 中),使用 mod_proxy_jk 作为连接器.

We are currently using Apache 2.2.3 and Tomcat 5 (Embedded in JBoss 4.2.2) using mod_proxy_jk as the connector.

有人可以阐明计算/配置以下值的正确方法(以及其他任何可能相关的内容).Apache 和 Tomcat 都在不同的机器上运行,并且拥有大量的内存(每个 4GB).

Can someone shed some light on the the correct way to calculate / configure the values below (as well as anything else that may be relevant). Both Apache and Tomcat are running on separate machines and have copious amounts of ram (4gb each).

相关的 server.xml 部分:

Relevant server.xml portions:

<Connector port="8009"
    address="${jboss.bind.address}"
    protocol="AJP/1.3"
    emptySessionPath="true"
    enableLookups="false"
    redirectPort="8443"
    maxThreads="320"
    connectionTimeout="45000"
/>

相关httpd.conf部分:

Relevant httpd.conf portions:

<IfModule prefork.c>
  StartServers       8
  MinSpareServers    5
  MaxSpareServers   20
  ServerLimit      256
  MaxClients       256
  MaxRequestsPerChild  0
</IfModule>

推荐答案

您应该考虑服务器可能获得的工作负载.

You should consider the workload the servers might get.

最重要的因素可能是高峰时段同时连接的客户端数量.尝试确定它并以以下方式调整您的设置:

The most important factor might be the number of simultaneously connected clients at peak times. Try to determine it and tune your settings in a way where:

  • Apache 和 Tomcat 中都有足够多的处理线程,因此当服务器负载过重时它们不需要产生新线程
  • 服务器中的处理线程数量不会超过所需数量,因为它们会浪费资源.

通过这种设置,您可以最大限度地减少服务器的内部维护开销,这会很有帮助,尤其是在您的负载是零星的情况下.

With this kind of setup you can minimize the internal maintenance overhead of the servers, that could help a lot, especially when your load is sporadic.

例如,考虑一个应用程序,您每秒有大约 300 个新请求.每个请求平均需要 2.5 秒来服务.这意味着在任何给定时间,您都有大约 750 个需要同时处理的请求.在这种情况下,您可能希望调整服务器,使其在启动时有大约 750 个处理线程,并且您可能希望最多添加大约 1000 个处理线程来处理极高的负载.

For example consider an application where you have ~300 new requests/second. Each request requires on average 2.5 seconds to serve. It means that at any given time you have ~750 requests that need to be handled simultaneously. In this situation you probably want to tune your servers so that they have ~750 processing threads at startup and you might want to add something like ~1000 processing threads at maximum to handle extremely high loads.

还要考虑您需要线程的确切用途.在前面的示例中,每个请求都独立于其他请求,没有使用会话跟踪.在更网络化"的场景中,您可能有用户登录到您的网站,并且根据您使用的软件,Apache 和/或 Tomcat 可能需要使用相同的线程来处理一个会话中出现的请求.在这种情况下,您可能需要更多线程.但是,至少我知道 Tomcat,您实际上不需要考虑这一点,因为它无论如何都可以在内部使用线程池.

Also consider for exactly what do you require a thread for. In the previous example each request was independent from the others, there was no session tracking used. In a more "web-ish" scenario you might have users logged in to your website, and depending on your software used, Apache and/or Tomcat might need to use the same thread to serve the requests that come in one session. In this case, you might need more threads. However as I know Tomcat at least, you won't really need to consider this as it works with thread pools internally anyways.

这篇关于配置 Apache/Tomcat 的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆