-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WFSSL-112 Use PooledByteBuffer to fix performance issue caused by ByteBuffer allocation #128
base: main
Are you sure you want to change the base?
Conversation
… ByteBuffer allocation
Benchmark application is Facebook Airlift sample application and benchmark client is wrk.
Below is the benchmark result for direct byte buffer allocation:
Below is the benchmark result for pooled byte buffer:
|
@stuartwdouglas Just wanted to get your thoughts on this one. I see something similar was previously discussed in #120 but the changes that were discussed there are no longer available. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this is not something we want out of the box, it needs to be pluggable.
The issues are:
- Wildfly has its own pool, we want to use this one and not create a new one.
- The ThreadLocal cache in the pool can cause memory leaks, if the engine is used by transient threads.
@stuartwdouglas Thanks for taking a look at this! To make this pluggable, one option might be to introduce a system property that could be used to specify that the pooled byte buffer should be used instead. The new system property could default to Just to provide some more context, @heyuanliu-intel has been working on adding the ability to support a custom engine to WildFly OpenSSL. With his changes, it will be possible to specify a system property that indicates the engine that should be used. @heyuanliu-intel has been making use of the Intel QAT engine and has been testing performance with this engine outside of WildFly. |
@stuartwdouglas @fjuma |
I think on by default is ok, but it should provide a simple way to both disable it, and to allow a custom pool implementation. I think initially just a system property option to disable it is probably ok. |
In the previous version, I have used an ByteBuffer pool created by myself. |
I think if wildfly-openssl can be managed by lightweight dependency injection framework such as Google Guice, then it is easy to allow a custom pool implementation. But it will be huge change for wildfly-openssl. So there is no easy way for the user to provide a custom pool implementation now and this shouldn't be considered now. And I found org.wildfly.openssl.OpenSSLSocket has used this byte buffer pool also. Should that make the pool pluggable also to keep the configuration consistency? Actually I think for the pool solution, out of box is better than make it pluggable now because I don't know which situation should make it turn off. |
@stuartwdouglas Thanks for the feedback! @heyuanliu-intel For now, I think we could introduce a system property that could be used to disable the use of the pooled byte buffer in In the future, we could add the ability to specify a custom |
I will reserve my personal opinion. I have modified the code according to comments. |
@heyuanliu-intel Please feel free to share any thoughts, concerns, etc. |
In my opinion: this is a bug that should be fixed instead of letting user to turn it off. |
If it is turned on it can cause an unfixable memory leak for some situations. Basically any situation where you have threads that use the cache that don't last for the full life of the application the 'ThreadLocal' in the cache will continue to hold onto the direct buffers even after the thread is gone. If you are using a thread pool this is less of an issue, as long as the thread pool does not dynamically resize. Even then you can still get problems (e.g. if a thread pool is recreated on redeployment you end up with memory leaks on redeploy). This is not just a theoretical problem, we have seen it before in WildFly. |
I think the main reason that causes the memory leak is caused by "ThreadLocal", it is discussed on stackoverflow and the link is [ThreadLocal & Memory Leak]. The final conclusion is that there is no good way to avoid memory leak by using "ThreadLocal" in containerized environment. My question is : How about using a global synchronized Map to keep the instances instead of using ThreadLocal? Although it will loss of the performance compared with non-synchronized ThreadLocal but it is safe. |
During using Facebook Airlift sample application to do benchmarking, the CPU user utilization is very low (about 9%) but CPU sys utilization is very high (about 66%) if we use wildfly-openssl as openssl provider and set the custom engine to QAT. From the Java Thread Dump File, we can found the performance bottleneck is the ByteBuffer allocation. So use pooled byte buffer to replace the direct byte buffer allocation to fix the performance bottleneck.