java icon indicating copy to clipboard operation
java copied to clipboard

JsonStreamPool cached JsonStream instances are never eligible for GC

Open mkomadel opened this issue 7 years ago • 0 comments

JsonStream.serialize(...) methods use intern ThreadLocal JsonStream instances from JsonStreamPool which are never issued for GC unless the thread ends. This leads to much higher memory footprint for web applications ( which use thread pools ) where, let say 99% of JSON responses are small (under 300k) and the rest 1% are comparatively much bigger (e.g. 1-2 MB).

It would be convenient to have some configurable limit (e.g. JsonStream size in bytes) which if exceeded, borrowed JsonStream instance isn't returned to the pool.

(Currently we have to use a workaround that borrows (and never returns) JsonStream instance from the JsonStreamPool after serialization, if resulting OutputStream size exceeds some limit)

mkomadel avatar Aug 01 '18 09:08 mkomadel