On 28/01/2016 14:16, Konstantin Kolinko wrote:
> 2016-01-28 17:04 GMT+03:00  <ma...@apache.org>:
>> Author: markt
>> Date: Thu Jan 28 14:04:00 2016
>> New Revision: 1727355
>>
>> URL: http://svn.apache.org/viewvc?rev=1727355&view=rev
>> Log:
>> Switch OutputBuffer to a local Map of C2BConvertors. Loading testing with 
>> HTTP/2 and default Tomcat home page suggests an improvement of a few percent 
>> in throughput.
> 
> How much memory is wasted?

I wouldn't call that memory 'wasted'. I'd call it 'used' to gain
somewhere in the region of a 2% to 4% throughput increase.

> Every connection (incl. keep-alive ones) will have its own map of
> encoders?  Encoders are not reused across different connections?

Using the same load test as I used for the performance numbers, I see a
retained size of less than 1MB all of which is eligible for GC. There
isn't much reuse in HTTP/2.

If I switch to HTTP/1.1 and run the same test I end up with ~60
instances using ~16k. Scale that up to 2000 concurrent connections and
you get ~550k so I am not worried about memory use in this case.

I didn't measure the performance gain of this change for HTTP/1.1 but
I'd expect there to be some benefit although not as much as HTTP/2
simply because HTTP/2 uses more concurrency for broadly the same load.

Mark


> 
> 
>> Modified:
>>     tomcat/trunk/java/org/apache/catalina/connector/OutputBuffer.java
>>
>> Modified: tomcat/trunk/java/org/apache/catalina/connector/OutputBuffer.java
>> URL: 
>> http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/OutputBuffer.java?rev=1727355&r1=1727354&r2=1727355&view=diff
>> ==============================================================================
>> --- tomcat/trunk/java/org/apache/catalina/connector/OutputBuffer.java 
>> (original)
>> +++ tomcat/trunk/java/org/apache/catalina/connector/OutputBuffer.java Thu 
>> Jan 28 14:04:00 2016
>> @@ -22,7 +22,8 @@ import java.nio.charset.Charset;
>>  import java.security.AccessController;
>>  import java.security.PrivilegedActionException;
>>  import java.security.PrivilegedExceptionAction;
>> -import java.util.concurrent.ConcurrentHashMap;
>> +import java.util.HashMap;
>> +import java.util.Map;
>>
>>  import javax.servlet.WriteListener;
>>  import javax.servlet.http.HttpServletResponse;
>> @@ -34,7 +35,6 @@ import org.apache.tomcat.util.buf.B2CCon
>>  import org.apache.tomcat.util.buf.ByteChunk;
>>  import org.apache.tomcat.util.buf.C2BConverter;
>>  import org.apache.tomcat.util.buf.CharChunk;
>> -import org.apache.tomcat.util.collections.SynchronizedStack;
>>  import org.apache.tomcat.util.res.StringManager;
>>
>>  /**
>> @@ -55,8 +55,7 @@ public class OutputBuffer extends Writer
>>      /**
>>       * Encoder cache.
>>       */
>> -    private static final ConcurrentHashMap<Charset, 
>> SynchronizedStack<C2BConverter>> encoders =
>> -            new ConcurrentHashMap<>();
>> +    private final Map<Charset, C2BConverter> encoders = new HashMap<>();
>>
>>
>>      // ----------------------------------------------------- Instance 
>> Variables
>> @@ -233,7 +232,6 @@ public class OutputBuffer extends Writer
>>
>>          if (conv != null) {
>>              conv.recycle();
>> -            encoders.get(conv.getCharset()).push(conv);
>>              conv = null;
>>          }
>>
>> @@ -560,16 +558,11 @@ public class OutputBuffer extends Writer
>>          }
>>
>>          final Charset charset = getCharset(enc);
>> -        SynchronizedStack<C2BConverter> stack = encoders.get(charset);
>> -        if (stack == null) {
>> -            stack = new SynchronizedStack<>();
>> -            encoders.putIfAbsent(charset, stack);
>> -            stack = encoders.get(charset);
>> -        }
>> -        conv = stack.pop();
>> +        conv = encoders.get(charset);
>>
>>          if (conv == null) {
>>              conv = createConverter(charset);
>> +            encoders.put(charset, conv);
>>          }
>>      }
>>
>> @@ -659,7 +652,6 @@ public class OutputBuffer extends Writer
>>          if (resetWriterStreamFlags) {
>>              if (conv != null) {
>>                  conv.recycle();
>> -                encoders.get(conv.getCharset()).push(conv);
>>              }
>>              conv = null;
>>              enc = null;
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
>> For additional commands, e-mail: dev-h...@tomcat.apache.org
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: dev-h...@tomcat.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to