-
Notifications
You must be signed in to change notification settings - Fork 102
Classloader leak can lead to PermGen/Metaspace OutOfMemoryError #104
Comments
Thanks for the bug report. Not using pooling causes a lot of garbage and negatively affects performance. Have you tried setting |
When logstash-gelf.buffer.size=0 and logstash-gelf.message.pooling=false leak doesn't reproduced, but can the setting of these parameters lead to performance degradation and increase count of objects? |
Using an object pool requires several invasive changes and tbh runtime class reloading isn't something that is in the primary usage scope. Disabling pooling/buffering falls back to performance characteristics of 1.10 with the difference that 1.11 uses an own, improved JSON encoder. |
ok. Thank you for help and for library |
logstash-gelf now uses a PoolHolder instead of static final ThreadLocal instances to hold references to ThreadLocal's and the associated objects. Using an instance to hold ThreadLocal instances breaks the cycle so objects can be collected by the GC if the ClassLoader is no longer in use (i.e. because of a hot-redeploy without restarting the JVM). The object root and the PoolHolder are referenced from PoolingGelfMessageBuilder which is created per log appender/handler instance or as static instance (default setting). Holding pools per instance can increase memory usage. Pooling mode can be controlled via logstash-gelf.message.pooling (Environment variable, System property).
I pushed an updated version of the library with configurable pooling options via Instance-held pools can consume more memory initially but the ClassLoader leak should be fixed. Care to give |
Although I set logstash-gelf.message.pooling to false, I am still having problem when redeploying in Tomcat (failure of garbage collection due to GelfUDPSender pooling threads). I explicitly call
with no success. Do have any idea how I can overcome this? Thanks in advance. (I use version 1.11.2) |
Seems that something is not cleaned up properly. @ozeray Care to file a new ticket along a heap dump? |
Hello Mark, Thanks for your quick reply. Our heap dumps size up to 200MB. Sorry for that. I am trying to inject my own implementation of GelfUDPSender. Is there a simple and elegant way to do that? |
200MB doesn't really sound as if that would be the culprit. Senders do not hold any |
I'm using logstash-gelf-1.11.0 configured via biz.paluch.logging.gelf.log4j.GelfLogAppender and deployed with war. As the application server is used Wildfly 10.1 but it must be reproduced in any server with worker pool.
After send log messages and redeploy application classes cannot be garbage collected due to ThreadLocal's that hold reference on custom class:
Because of this PermGen/Metaspace OutOfMemoryError can be occurred
screen from Eclipse MAT:
I think the simplest solution is not to use ThreadLocal's for these cases and always create objects or implement ObjectPool.
I don't know which way is more appropriate, so I don't sent pull request.
If don't use ThreadLocal's then will be some performance degradation (actually such result is not representative due to big errors).
The text was updated successfully, but these errors were encountered: