How to properly limit net4j's thread pool [message #1795103] |
Fri, 14 September 2018 14:50 |
Linuxhippy Mising name Messages: 71 Registered: July 2009 |
Member |
|
|
Hi,
In a real-world net4j/cdo application, we see occasional thread-spikes. While the application typically runs well below <150 threads total, sometimes we see spikes up to ~2000 threads - which is already a bit concerning, keeping in mind the spikes seem random.
I found out those threads are created by net4j, however when looking at the thread-dump they are already lurking in the ThreadPool, just to be released soon after.
To limit those spikes, this is what I currently do during setup:
ExecutorService o = ExecutorServiceFactory.get(container);
try {
Method coreMethod = ThreadPoolExecutor.class.getMethod("setCorePoolSize", new Class[] { int.class});
Method maxMethod = ThreadPoolExecutor.class.getMethod("setMaximumPoolSize", new Class[] { int.class});
Proxy.getInvocationHandler(o).invoke(o, coreMethod, new Object[] {1});
Proxy.getInvocationHandler(o).invoke(o, maxMethod, new Object[] {2});
} catch (Throwable thrbl) {
throw new RuntimeException(thrbl);
}
Therefore my question:
* Is it harmful to limit net4j's ThreadPool to a certain size?
* Is there a proper way, instead of using ugly reflection trickeria?
Thank you in advance
|
|
|
Re: How to properly limit net4j's thread pool [message #1795121 is a reply to message #1795103] |
Sat, 15 September 2018 08:16 |
|
I don't think that limiting the thread pool size to something less than Integer.MAX_VALUE is harmful per se. Of course you'll need to test your configuration.
If you use your own IManagedContainer you can contribute a custom TransportInjector instead of the default one. If instead you want to continue to use the default IPluginContainer.INSTANCE, you should modify it very early in the bootstrap phase of your client or server:
List<IElementProcessor> postProcessors = IPluginContainer.INSTANCE.getPostProcessors();
for (Iterator<IElementProcessor> it = postProcessors.iterator(); it.hasNext();)
{
IElementProcessor elementProcessor = it.next();
if (elementProcessor instanceof TransportInjector)
{
it.remove();
break;
}
}
TransportInjector transportInjector = new TransportInjector()
{
@Override
protected ExecutorService getExecutorService(IManagedContainer container)
{
return (ExecutorService)container.getElement(ExecutorServiceFactory.PRODUCT_GROUP, ExecutorServiceFactory.TYPE, "10:1000:60");
}
};
postProcessors.add(transportInjector);
If you submit a bugzilla I can also add some system properties to override the default values (type and description) of the thread pool and the buffer provider...
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03106 seconds