During websocket load tests we noticed that the resident memory usage of the tomcat process would grow and stay in use even after the sockets were closed when websocket compression was enabled. The java heap looked fine. It seems to be caused by PerMessageDeflate creating a Deflater and Inflater which in turn allocates native memory that isn't freed until the JVM decides to run their finalizers, which can take a long time before it happens. I propose calling .end() (which is what finalize() does) on the Deflater and Inflater when the websocket is closed. I have created a patch that does this and resident memory usage shrinks after the websockets are closed down with it. Would you be interested in this?
Sure. Attach the patch to this issue and someone will take a look.
Created attachment 33682 [details] Makes PerMessageDeflate call end on Inflater/Deflater by adding a close() method to the Transformation interface
(In reply to Mark Thomas from comment #1) > Sure. Attach the patch to this issue and someone will take a look. Attachment added. Not sure if it's the best way to do it but at least it's something :)
Thanks for the report and the proposed fix. I ended up applying a variation on your patch since I found a simpler path to call close(). The fix has been applied to: - 9.0.x for 9.0.0.M5 onwards - 8.5.x for 8.5.1 onwards - 8.0.x for 8.0.33 onwards - 7.0.x for 7.0.69 onwards
(In reply to Mark Thomas from comment #4) > Thanks for the report and the proposed fix. > > I ended up applying a variation on your patch since I found a simpler path > to call close(). > > The fix has been applied to: > - 9.0.x for 9.0.0.M5 onwards > - 8.5.x for 8.5.1 onwards > - 8.0.x for 8.0.33 onwards > - 7.0.x for 7.0.69 onwards Thanks for the quick response!