I think it's broken. Check this two tests:
@Test
public void testCustomThreadPoolSameThreadStrategy() throws Exception {
final int poolSize = Math.max(Runtime.getRuntime().availableProcessors()/2, 1);
final ThreadPoolConfig poolCfg = ThreadPoolConfig.defaultConfig();
poolCfg.setCorePoolSize(poolSize).setMaxPoolSize(poolSize);
final TCPNIOTransport tcpTransport = TCPNIOTransportBuilder.newInstance()
.setReuseAddress(true)
.setIOStrategy(SameThreadIOStrategy.getInstance())
.setSelectorThreadPoolConfig(poolCfg)
.setWorkerThreadPoolConfig(null)
.build();
try {
tcpTransport.start();
} finally {
tcpTransport.shutdownNow();
}
}
@Test
public void testCustomThreadPoolWorkerThreadStrategy() throws Exception {
final int selectorPoolSize = Math.max(Runtime.getRuntime().availableProcessors()/2, 1);
final ThreadPoolConfig selectorPoolCfg = ThreadPoolConfig.defaultConfig();
selectorPoolCfg.setCorePoolSize(selectorPoolSize).setMaxPoolSize(selectorPoolSize);
final int workerPoolSize = Runtime.getRuntime().availableProcessors() * 2 ;
final ThreadPoolConfig workerPoolCfg = ThreadPoolConfig.defaultConfig();
workerPoolCfg.setCorePoolSize(workerPoolSize).setMaxPoolSize(workerPoolSize);
final TCPNIOTransport tcpTransport = TCPNIOTransportBuilder.newInstance()
.setReuseAddress(true)
.setIOStrategy(WorkerThreadIOStrategy.getInstance())
.setSelectorThreadPoolConfig(selectorPoolCfg)
.setWorkerThreadPoolConfig(workerPoolCfg)
.build();
try {
tcpTransport.start();
} finally {
tcpTransport.shutdownNow();
}
}
Tigran.
----- Original Message -----
> From: "Oleksiy Stashok" <oleksiy.stashok_at_oracle.com>
> To: dev_at_grizzly.java.net
> Sent: Friday, March 14, 2014 1:25:16 AM
> Subject: Re: [PATCH] adjust selector count on NIOTransportBuilder#setSelectorThreadPoolConfig
>
> Hi Tigran,
>
> I've commited this fix:
> https://github.com/GrizzlyNIO/grizzly-mirror/commit/55273b6750a191b113f67de515cefc0c96e45758
>
> with the following change [1], which still haven't reached github mirror.
>
> What do you think?
>
> WBR,
> Alexey.
>
>
> [1]
>
> Revisions:
> ----------
> fbef39556a11f8f0fc6b767ab56621473d2f7da0
>
>
> Modified Paths:
> ---------------
> modules/grizzly/src/main/java/org/glassfish/grizzly/nio/NIOTransport.java
>
>
> Diffs:
> ------
> ---
> a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/NIOTransport.java
> +++
> b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/NIOTransport.java
> @@ -196,7 +196,8 @@ public abstract class NIOTransport extends
> AbstractTransport
> public void setSelectorRunnersCount(final int selectorRunnersCount) {
> if (selectorRunnersCount > 0) {
> this.selectorRunnersCount = selectorRunnersCount;
> - if (kernelPoolConfig != null) {
> + if (kernelPoolConfig != null &&
> + kernelPoolConfig.getMaxPoolSize() <
> selectorRunnersCount) {
> kernelPoolConfig.setCorePoolSize(selectorRunnersCount)
> .setMaxPoolSize(selectorRunnersCount);
> }
> @@ -424,8 +425,8 @@ public abstract class NIOTransport extends
> AbstractTransport
> .setPoolName("grizzly-nio-kernel");
> }
> kernelPoolConfig.setMemoryManager(memoryManager);
> - if (kernelPoolConfig.getCorePoolSize() < selectorRunnersCnt)
> {
> - throw new IllegalStateException("The min threads count
> of the kernel ThreadPool has to be larger or equal to the
> selectorRunnersCount");
> + if (kernelPoolConfig.getMaxPoolSize() < selectorRunnersCnt)
> {
> + throw new IllegalStateException("The max threads count
> of the kernel ThreadPool has to be larger or equal to the
> selectorRunnersCount");
> }
> setKernelPool0(
> GrizzlyExecutorService.createInstance(
>
>
>
> On 13.03.14 01:32, Tigran Mkrtchyan wrote:
> > Signed-off-by: Tigran Mkrtchyan <tigran.mkrtchyan_at_desy.de>
> > ---
> > .../src/main/java/org/glassfish/grizzly/NIOTransportBuilder.java | 5
> > +++++
> > 1 file changed, 5 insertions(+)
> >
> > diff --git
> > a/modules/grizzly/src/main/java/org/glassfish/grizzly/NIOTransportBuilder.java
> > b/modules/grizzly/src/main/java/org/glassfish/grizzly/NIOTransportBuilder.java
> > index 9cc98cf..8630c8b4 100644
> > ---
> > a/modules/grizzly/src/main/java/org/glassfish/grizzly/NIOTransportBuilder.java
> > +++
> > b/modules/grizzly/src/main/java/org/glassfish/grizzly/NIOTransportBuilder.java
> > @@ -149,6 +149,11 @@ public abstract class NIOTransportBuilder<T extends
> > NIOTransportBuilder> {
> > */
> > public T setSelectorThreadPoolConfig(final ThreadPoolConfig
> > threadPoolConfig) {
> > transport.setKernelThreadPoolConfig(threadPoolConfig);
> > + /*
> > + * selector runners count MUST not be greater than number of
> > threads in the pool
> > + */
> > + int selectorRunnersCount =
> > Math.min(threadPoolConfig.getMaxPoolSize(),
> > transport.getSelectorRunnersCount());
> > + transport.setSelectorRunnersCount(selectorRunnersCount);
> > return getThis();
> > }
> >
>
>