Jetty访问静态资源Open Too Many Files

        Jetty 9.0.3 Open too many files 问题

1. Jetty9.0.3-20130506
2. 问题描述:
  Linux Open too many files. 使用Jetty的DefaultServlet访问静态资源时,每次执行lsof –c java| grep pid 命令发现打开的静态的资源都没有被关闭。虽然通过修改ulimit –n设定了每个进程允许打开的最大文件描述符。但是如果jetty的访问的资源文件一直不被关闭,则上述方式无疑是饮鸠止渴。
3. 问题解决:
   通过跟踪Jetty9.0.3 DefaultServlet访问静态资源的方式,发现如果资源被资源缓存器缓存的话,则不会关闭该资源文件,只能等缓存的中的文件数量超过设置的最大文件数量(maxCachedFiles)或者缓存的文件总大小(maxCacheSize)超过设置的文件总大小,才会根据访问时间将缓存中的文件关闭。

[url]conf/jetty/webdefault.xml [/url]
<servlet>
    <servlet-name>default</servlet-name>
    <servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
    <init-param>
      <param-name>aliases</param-name>
      <param-value>false</param-value>
    </init-param>
    <init-param>
      <param-name>acceptRanges</param-name>
      <param-value>true</param-value>
    </init-param>
    <init-param>
      <param-name>dirAllowed</param-name>
      <param-value>true</param-value>
    </init-param>
    <init-param>
      <param-name>welcomeServlets</param-name>
      <param-value>false</param-value>
    </init-param>
    <init-param>
      <param-name>redirectWelcome</param-name>
      <param-value>false</param-value>
    </init-param>
    <init-param>
      <param-name>maxCacheSize</param-name>
      <param-value>256000000</param-value>
    </init-param>
    <init-param>
      <param-name>maxCachedFileSize</param-name>
      <param-value>200000000</param-value>
    </init-param>
    <init-param>
      <param-name>maxCachedFiles</param-name>
      <param-value>-2</param-value>
    </init-param>
    <init-param>
      <param-name>gzip</param-name>
      <param-value>true</param-value>
    </init-param>
    <init-param>
      <param-name>etags</param-name>
      <param-value>true</param-value>
    </init-param>
    <init-param>
      <param-name>useFileMappedBuffer</param-name>
      <param-value>true</param-value>
    </init-param>
    <!--
    <init-param>
      <param-name>resourceCache</param-name>
      <param-value>resourceCache</param-value>
    </init-param>
    -->
    <!--
    <init-param>
      <param-name>cacheControl</param-name>
      <param-value>max-age=3600,public</param-value>
    </init-param>
    -->
    <load-on-startup>0</load-on-startup>
  </servlet>

你可能感兴趣的:(jetty)