rschuetz commented on issue #3395:
URL: 
https://github.com/apache/logging-log4j2/issues/3395#issuecomment-2593386211

   > [@rschuetz](https://github.com/rschuetz), this is indeed a bug (thanks for 
the report! 🙇) and your suggested fix makes sense. I will submit a PR 
containing the fix along with some tests.
   
   @vy, excellent, thanks a lot!
   
   > [@rschuetz](https://github.com/rschuetz), curious: would you mind briefly 
explaining your custom recycler factory? How does it work? Do you use an 
external library for the pool? If so, which one? Where did the recyclers 
bundled with JTL fall short in your use case?
   
   The issue I face is that I need a very large maxStringLength - 10.000.000 
characters, as one of the background services in the application generates 
threaddumps (for debugging/support reasons) in a standard format in case some 
threads got stuck, and truncating these dumps would make them useless. 
Unfortunately this also means all other threads gets buffers of the same size. 
   
   So if we run with this buffer size there is a risk for OOMs / wasting a lot 
of memory if many buffers get allocated. `threadLocal` won't work due to the 
number of active threads, `queue` has no upper limit (threads would still get 
their buffer if there is no buffer in the queue) and `dummy` will increase GC 
pressure a lot.
   
   Therefore I added a pooling recycler that simply just uses Apache Commons 
Pool with a maximum size and blocks if all buffers are in use. Not more, hope 
it works for now, as log frequency is not high.
   
   Actually IMHO it would be better if `maxStringLength` wouldn't be needed or 
would at least not require pre-allocated buffers to hold the entire JSON 
document, i.e. if data could be streamed out using smaller buffers instead.
   
   > In the meantime, as a workaround, you can try extending your custom 
`RecyclerFactory` from `java.util.Queue` and activate it by setting the 
`recyclerFactory` plugin attribute to 
`queue:supplier=path.to.your.RecyclerFactory.new,capacity=123`. Does this work 
for you?
   
   Thanks a lot, but as there is no upper limit here, it wouldn't be safe. For 
now I put a patched copy of JsonTemplateLayoutDefaults at the beginning of the 
classpath.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to