You get a 4 MB buffer immediately and it stays there as long as your connection is alive. But as Mark replied, this thread belongs in the user mailing list because if you are gonna have a buffer bigger than the default, perhaps you are better off using the partial message handler.What's annoying in my case is that i would need the whole message to do something with it, so i d have to gather all the message in my partial message handler and have it garbage collected after i get the last chunk and do what i want to do with it, so from a design perspective that doesn't sound right . In the user mailing list mark mentioned that the reason the buffer doesn't shrink is to avoid gc churn which is a good point. The right question is ,would the gc churn be worse than the memory penalty ?
On Tuesday, June 21, 2016, Christopher Schultz <ch...@christopherschultz.net> wrote: > Afaf, > > On 6/21/16 8:46 AM, Afaf Zahkya wrote: > > Hello, > > > > I m using tomcat 8.0.21. > > > > I want to send *up* to 4 MB of text messages through a websocket > connection > > to my tomcat server. I set the MaxTextMessageBufferSize to 4 MB.Now as a > > result, every time I open a websocket connection and I send a message , > I > > can see that 4 MB are being allocated in memory for the CharBuffer > > messageBufferText regardless of the size of the message I send . 99 % of > my > > messages would be way smaller.The 4 MB remain allocated in the > > messageBufferText CharBuffer even after the message is handled. The > > connection can stay open up to 30 minutes in my case, and each websocket > > connection is taking 4 MB of memory all of that time even if it's > inactive > > which leads my server to eventually run out of memory even with inactive > > connections . Note that I m using a Whole Message Handler. > > > > Why not set the messageBufferText CharBuffer size to the payload length > if > > it doesn't exceed the maxTextMessageBufferSize, and then clearing that > > buffer ( reducing its size) after the message is handled by the Handler, > so > > that inactive connections don't take up memory. ( same for the binary) ? > > > > Any other / better suggestions on how to solve that problem ? > > If you configure Tomcat with maxTextMessageBufferSize="4MB" but only > send small messages, do you get a small buffer? Or do you get a 4MB > buffer immediately? > > -chris > >