Tomcat 6 中的图像加速

发布于 2024-07-04 21:44:16 字数 770 浏览 8 评论 0原文

在 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>

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?

Here is my 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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

请你别敷衍 2024-07-11 21:44:16

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

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

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

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

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.

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.

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.

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

未蓝澄海的烟 2024-07-11 21:44:16

您是否一遍又一遍地提供同一组图像? 在这种情况下,添加一个 servlet 过滤器来添加合理的 Expires 标头可能会为 tomcat 节省大量工作。 它不会提高提供图像的速度,只会减少它必须处理的请求数量。 网上有很多这方面的例子。

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.

情痴 2024-07-11 21:44:16

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

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

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

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.

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.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文