1

ChannelPipeline にデコンプレッサとコンプレッサが導入されていますが、特定のクラスに導入された両方のメソッドの実行時間と比較して、実行時間が長すぎます。

@Override 
public ChannelPipeline getPipeline() throws Exception { 
    ChannelPipeline pipeline = pipeline(); 
    pipeline.addLast("decoder",new IcapRequestDecoder(maxInitialLineLength, maxIcapHeaderSize, maxHttpHeaderSize, maxChunkSize)); 
    pipeline.addLast("chunkAggregator",new IcapChunkAggregator(maxContentLength)); 
    pipeline.addLast("decompressor",new IcapContentDecompressor()); 
    pipeline.addLast("encoder",new IcapResponseEncoder()); 
    pipeline.addLast("chunkSeparator",new IcapChunkSeparator(maxContentLength)); 
    pipeline.addLast("handler", handler); 
    pipeline.addLast("compressor",new IcapContentCompressor()); 
    return pipeline; 
} 

原因は何ですか?

4

1 に答える 1

0

情報を展開していきます。

クラス IcapContentCompress:

public class IcapContentCompressor extends SimpleChannelDownstreamHandler {

...

/**
 * Invoked when {@link Channel#write(Object)} is called.
 */
@Override
public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws Exception {        

            ...

    IcapResponse icapResponse = (IcapResponse) msg;

    // Get response message
    HttpResponse httpMessage = icapResponse.getHttpResponse();

    ...

    boolean compressed = isCompressed(httpMessage);
    if (compressed) {           
        String acceptEncoding = httpMessage.getHeader(HttpHeaders.Names.CONTENT_ENCODING);
        compress(httpMessage, acceptEncoding);
    }

    }       

    ctx.sendDownstream(e);

}

メソッド圧縮:

private void compress(HttpResponse httpMessage, String acceptEncoding) throws Exception {                       
    ZlibWrapper wrapper = determineWrapper(acceptEncoding);
    if (wrapper == null) {
       return;
    }

    EncoderEmbedder<ChannelBuffer>  encoder = new EncoderEmbedder<ChannelBuffer>(new ZlibEncoder(wrapper, compressionLevel, windowBits, memLevel));

    httpMessage.setHeader(
            HttpHeaders.Names.CONTENT_ENCODING,
            getTargetContentEncoding(wrapper));

    ChannelBuffer contentCompressed = ChannelBuffers.wrappedBuffer(
                                            encode(httpMessage.getContent(), encoder), 
                                            finishEncode(encoder));

    // Replace the content.
    httpMessage.setContent(contentCompressed);  
}   

クラスChannelPipelineに導入せずに特定のクラスで同じメソッドを使用すると、実行時間が大幅に短縮されます。

于 2012-12-05T08:19:57.140 に答える