手机版
你好,游客 登录 注册
背景:
阅读新闻

Tomcat 配置gzip无效

[日期:2013-03-12] 来源:Linux社区  作者:xuefeng0707 [字体:大 中 小]

并在Http11Processor的process方法的最后一部分,把文件内容以FileChannel的形式写回到前台,不需要先把文件内容先读到用户内存->压缩->写回socket内核内存。

/**
    * Process pipelined HTTP requests using the specified input and output
    * streams.
    *
    * @throws IOException error during an I/O operation
    */
    public SocketState process(NioChannel socket)
        throws IOException {
       
        ......
            // Do sendfile as needed: add socket to sendfile and end
            if (sendfileData != null && !error) {
                KeyAttachment ka = (KeyAttachment)socket.getAttachment(false);
                ka.setSendfileData(sendfileData);
                sendfileData.keepAlive = keepAlive;
                SelectionKey key = socket.getIOChannel().keyFor(socket.getPoller().getSelector());
                //do the first write on this thread, might as well
                openSocket = socket.getPoller().processSendfile(key,ka,true,true);
                break;
            }
        ......

    }

这种NIO底层读写channel的形式避免了读取到用户内存的开销,也可以提升性能。

目前,尚不清楚使用NIO快,还是gzip较快,有待测试。

如果在使用NIO的同时还一定要用gzip,可以关闭NIO Connector的useSendFile选项。

<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"
              connectionTimeout="20000"
              redirectPort="8443"
               useSendfile="false"
               compression="on"
    compressionMinSize="2048"
    noCompressionUserAgents="gozilla, traviata"
    compressableMimeType="text/html,text/xml,text/Javascript" />

参考:http://tomcat.apache.org/tomcat-6.0-doc/config/http.html

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款