加速Tomcat 6中的图像

时间:2022-07-29 02:43:04

In tomcat 6 i have a servlet running openbluedragon, everything compiles and servers up quik, with the exception of images, they really lag significantly. Any suggestions optimization for image serving?

在tomcat 6中,我有一个运行openbluedragon的servlet,所有内容都编译并提供服务器,除了图像,它们确实显着滞后。对图像服务的任何建议优化?

Here is my server.xml:

这是我的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>

3 个解决方案

#1


4  

Another option is to use apache as a frontend, connecting tomcat with mod_jk. This way you can let apache serve static content (e.g. images, css, javascript) and let tomcat generate the dynamic content. Might leave a bit of work to separate the static content from the dynamic ones, but works great for me.

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

On Unix, having an apache as frontend is a nice option because being bound to port 80 you're often forced to run as root. Apache knows how to drop root permissions after binding a port, Tomcat doesn't. You don't want a server faced to the public to run as root.

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

(This is similar to the reverse proxy answer, but doesn't involve a proxy but mod_jk)

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

#2


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.

你一遍又一遍地提供同一套图像吗?在这种情况下,添加一个添加合理的Expires头的servlet过滤器可能会为tomcat节省大量的工作。它不会增加所服务图像的速度,但只会使它必须处理的请求数量减少。网上有很多这方面的例子。

#3


3  

If you have the option, you could add a reverse proxy in advance of your application. At work I have an Apache web server that receives all inbound HTTP connections. Based on the URL, it either forwards the request to another server or serves up the content itself. I've used this approach to accelerate serving up static content for a Trac site. The ProxyPass and ProxyPassReverse directives are a good place to start looking if you want to go this route.

如果您有选项,则可以在申请之前添加反向代理。在工作中,我有一个Apache Web服务器,它接收所有入站HTTP连接。基于URL,它将请求转发到另一个服务器或提供内容本身。我已经使用这种方法来加速为Trac网站提供静态内容。 ProxyPass和ProxyPassReverse指令是一个很好的地方,如果你想走这条路线,开始寻找。

As a simple example, if you have a virtual directory called /images, Apache could serve up any request for something in that directory and forward everything else to your Tomcat instance. The syntax is pretty comprehensive. If there is any method at all to the way your static content is identified this is an approach that will work.

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

Apache isn't the only choice here. I think all modern web servers include similar functionality. If I was starting today I'd probably look at LigHTTPd instead, just because it does less.

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

There may even be caching reverse proxies that figure this out for you automatically. I'm not familiar with any of them though.

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

#1


4  

Another option is to use apache as a frontend, connecting tomcat with mod_jk. This way you can let apache serve static content (e.g. images, css, javascript) and let tomcat generate the dynamic content. Might leave a bit of work to separate the static content from the dynamic ones, but works great for me.

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

On Unix, having an apache as frontend is a nice option because being bound to port 80 you're often forced to run as root. Apache knows how to drop root permissions after binding a port, Tomcat doesn't. You don't want a server faced to the public to run as root.

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

(This is similar to the reverse proxy answer, but doesn't involve a proxy but mod_jk)

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

#2


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.

你一遍又一遍地提供同一套图像吗?在这种情况下,添加一个添加合理的Expires头的servlet过滤器可能会为tomcat节省大量的工作。它不会增加所服务图像的速度,但只会使它必须处理的请求数量减少。网上有很多这方面的例子。

#3


3  

If you have the option, you could add a reverse proxy in advance of your application. At work I have an Apache web server that receives all inbound HTTP connections. Based on the URL, it either forwards the request to another server or serves up the content itself. I've used this approach to accelerate serving up static content for a Trac site. The ProxyPass and ProxyPassReverse directives are a good place to start looking if you want to go this route.

如果您有选项,则可以在申请之前添加反向代理。在工作中,我有一个Apache Web服务器,它接收所有入站HTTP连接。基于URL,它将请求转发到另一个服务器或提供内容本身。我已经使用这种方法来加速为Trac网站提供静态内容。 ProxyPass和ProxyPassReverse指令是一个很好的地方,如果你想走这条路线,开始寻找。

As a simple example, if you have a virtual directory called /images, Apache could serve up any request for something in that directory and forward everything else to your Tomcat instance. The syntax is pretty comprehensive. If there is any method at all to the way your static content is identified this is an approach that will work.

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

Apache isn't the only choice here. I think all modern web servers include similar functionality. If I was starting today I'd probably look at LigHTTPd instead, just because it does less.

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

There may even be caching reverse proxies that figure this out for you automatically. I'm not familiar with any of them though.

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