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?

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


> 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

Reply via email to