I have a webapp that maintains many concurrent comet connections. Transmissions between the client and server are small and infrequent. I'm trying to lessen the memory usage by playing with buffer configurations.
To test various configurations, I wrote a client that opens 2000 connections to a comet servlet. Each connection sends a short message and receives a short message back from the server. I do not close the connections. I'm using the NetBeans 6.0 profiler to look at memory use. The first thing I did was configure the http connector with the following settings (maybe a little extreme, but I'm just playing here): socket.appReadBufSize="512" socket.appWriteBufSize="512" socket.rxBufSize="512" socket.txBufSize="512" These settings reduced vm heap memory use from 251 MB to 220 MB. Then I changed my comet servlet to use my own BufferedReader and PrintWriter with buffer sizes of 512k, instead of using the Reader from HttpServletRequest.getReader() and the Writer from HttpServletResponse.getWriter(), which both have larger default buffer sizes. This reduced memory use from 220 MB to 138 MB. At this point much of the memory was in char arrays in org.apache.catalina.connector.InputBuffer objects, and byte arrays in org.apache.catalina.connector.OutputBuffer objects. Since I couldn't find a way to tweak these buffer sizes with config settings or external code, I tried modifying the tomcat code. I changed the DEFAULT_BUFFER_SIZE in both those classes to 1024 from 8192. This reduced memory use from 138 MB to 95 MB. Now byte arrays in InternalNioInputBuffer and InternalNioOutputBuffer looked like promising targets. To modify these, I changed the maxHttpHeaderSize in Http11NioProtocol to 1024 from 8192. This reduced memory use from 95 MB to 66 MB. At this point my heap map shows the main consumers of memory as follows: Of the 66 MB on the heap: char[] account for 26% (below shows %s of the 26%) Parameters in Request 56% InputBuffer in Request 6% byte[] 19% (below shows %s of the 19%) BufferedInputFilter in Http11NioProcessor 19% OutputBuffer in Response 19% NioBufferHandler in NioEndpoint 19% InternalNioInputBuffer in Http11NioProcessor 20% InternalNioOutputBuffer in Http11NioProcessor 18% So... 1) Are any of the changes listed above bad ideas? What is the danger of sizing buffers too small? Is it just a performance hit, or is there a danger of losing data? 2) Is there a way for me to change the buffer sizes in InputBuffer, OutputBuffer, InternalNioInputBuffer, and InternalNioOutputBuffer without having to change Tomcat code? 3) Does anyone have other ideas for minimizing memory use in a many-connection, small-data-size webapp? Thanks, Peter --------------------------------------------------------------------- To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]