3

在 tomcat 6 中,我有一个运行 openbluedragon 的 servlet,一切都编译并快速启动服务器,除了图像,它们确实明显滞后。任何关于图像服务的优化建议?

这是我的 server.xml:

    <Service name="Catalina">

      <Connector port="8009" protocol="AJP/1.3" />
      <Connector port="8080" maxThreads="100" protocol="HTTP/1.1" connectionTimeout="20000" />
      <Engine name="Standalone" defaultHost="hostname.whatever" jvmRoute="ajp13">

      <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
      <Host name="hostname.whatever"  appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
        ...context
      </Host>

    </Engine>
  </Service>
4

3 回答 3

4

另一种选择是使用 apache 作为前端,将 tomcat 与 mod_jk 连接起来。这样,您可以让 apache 提供静态内容(例如图像、css、javascript)并让 tomcat 生成动态内容。可能需要做一些工作来将静态内容与动态内容分开,但对我来说效果很好。

在 Unix 上,将 apache 作为前端是一个不错的选择,因为绑定到端口 80 您经常被迫以 root 身份运行。Apache 知道如何在绑定端口后删除 root 权限,而 Tomcat 不知道。您不希望面向公众的服务器以 root 身份运行。

(这类似于反向代理答案,但不涉及代理但 mod_jk)

于 2008-09-22T06:35:28.827 回答
4

Are you serving the same set of images over and over? In that case adding a servlet filter that adds a reasonable Expires header might save tomcat a lot of work. It will not increase the speed of the served image but will just make the number of requests it has to handle less. Lots of examples for this on the web.

于 2009-01-14T11:50:08.763 回答
3

如果您可以选择,您可以在应用程序之前添加反向代理。在工作中,我有一个接收所有入站 HTTP 连接的 Apache Web 服务器。根据 URL,它要么将请求转发到另一台服务器,要么自己提供内容。我使用这种方法来加速为 Trac 站点提供静态内容。如果你想走这条路,ProxyPass 和 ProxyPassReverse 指令是一个很好的起点。

举个简单的例子,如果您有一个名为 /images 的虚拟目录,Apache 可以为该目录中的某些内容提供任何请求,并将其他所有内容转发到您的 Tomcat 实例。语法相当全面。如果有任何方法可以识别您的静态内容,那么这是一种可行的方法。

Apache 不是这里唯一的选择。我认为所有现代 Web 服务器都包含类似的功能。如果我从今天开始,我可能会改用 LigHTTPd,因为它做得更少。

甚至可能会有缓存反向代理自动为您解决这个问题。我不熟悉他们中的任何一个。

于 2008-09-20T22:50:38.467 回答