Hi Tee,<br><br>I&#39;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:)<br>

<br>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.<br>

<br><br><br>HttpMessageDecoder.java<br><br>    private String readLine(ChannelBuffer buffer, int maxLineLength) throws TooLongFrameException {<br>        int lineLength = 0;<br>        <br>        <br>        // Jiming&#39;s code<br>

        int fromIndex = buffer.readerIndex();<br>        int readableBytes = buffer.readableBytes();<br>        int indexOf = buffer.indexOf(fromIndex, fromIndex + readableBytes, HttpCodecUtil.LF);<br>        lineLength = indexOf - fromIndex + 1;<br>

        if(lineLength &gt; maxLineLength) {<br>            throw new TooLongFrameException(<br>            &quot;An HTTP line is larger than &quot; + maxLineLength +<br>            &quot; bytes.&quot;);<br>        }<br>        byte[] arr = new byte[lineLength];<br>

        buffer.readBytes(arr);<br>        int trimLen = (arr[arr.length - 2] == HttpCodecUtil.CR)?arr.length - 2:arr.length-1;<br>        return new String(arr, 0, trimLen);<br>    }<br><br>    private String readHeader(ChannelBuffer buffer) throws TooLongFrameException {<br>

           // Jiming&#39;s code<br>            String result = readLine(buffer, maxHeaderSize);<br>            this.headerSize += result.length() + 1;<br>            if (headerSize &gt;= maxHeaderSize) {<br>                throw new TooLongFrameException(&quot;HTTP header is larger than &quot;<br>

                        + maxHeaderSize + &quot; bytes.&quot;);<br>            }<br>            // System.out.println(result + &quot;:&quot; + this.headerSize);<br>            return result;<br>    }<br><br><br>Thanks,<br>

Jiming<br>