Improve http performance?

Wade Poziombka wpoziombka at hotmail.com
Wed Mar 31 22:11:44 EDT 2010


I draw the same conclusion from my past testing.  It does range checking for each byte over and over.

 

Wade

 

From: netty-users-bounces at lists.jboss.org [mailto:netty-users-bounces at lists.jboss.org] On Behalf Of Jiming Liu
Sent: Tuesday, March 30, 2010 12:47 AM
To: netty-users at lists.jboss.org
Subject: Re: Improve http performance?

 

Hi Tee,

I've refactored some code to trying to improve Http performance. The following code is around 50% percent faster than the original ones. But to the http service, it only improved around 4%. Yes, Netty is very well coded, it is not easy to find a way to improve it:)

After refactor, I noticed that Buffer.indexOf are a bottleneck now. And after reading netty code deeper, I found maybe the buffers should have more batch operations, and make them real batch operation instead of still operate byte after byte.



HttpMessageDecoder.java

    private String readLine(ChannelBuffer buffer, int maxLineLength) throws TooLongFrameException {
        int lineLength = 0;
        
        
        // Jiming's code
        int fromIndex = buffer.readerIndex();
        int readableBytes = buffer.readableBytes();
        int indexOf = buffer.indexOf(fromIndex, fromIndex + readableBytes, HttpCodecUtil.LF);
        lineLength = indexOf - fromIndex + 1;
        if(lineLength > maxLineLength) {
            throw new TooLongFrameException(
            "An HTTP line is larger than " + maxLineLength +
            " bytes.");
        }
        byte[] arr = new byte[lineLength];
        buffer.readBytes(arr);
        int trimLen = (arr[arr.length - 2] == HttpCodecUtil.CR)?arr.length - 2:arr.length-1;
        return new String(arr, 0, trimLen);
    }

    private String readHeader(ChannelBuffer buffer) throws TooLongFrameException {
           // Jiming's code
            String result = readLine(buffer, maxHeaderSize);
            this.headerSize += result.length() + 1;
            if (headerSize >= maxHeaderSize) {
                throw new TooLongFrameException("HTTP header is larger than "
                        + maxHeaderSize + " bytes.");
            }
            // System.out.println(result + ":" + this.headerSize);
            return result;
    }


Thanks,
Jiming

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/netty-users/attachments/20100331/7cc10ea1/attachment-0001.html 


More information about the netty-users mailing list