[grizzly~git:be619331] [2.3.x] + (additional commit for) implement improvement #1662

  • From: oleksiys@...
  • To: commits@...
  • Subject: [grizzly~git:be619331] [2.3.x] + (additional commit for) implement improvement #1662
  • Date: Fri, 14 Mar 2014 23:13:10 +0000

Project:    grizzly
Repository: git
Revision:   be6193310b07b13c240b03e9e5c4f5079b24621c
Author:     oleksiys
Date:       2014-03-14 23:12:50 UTC
Link:       

Log Message:
------------
[2.3.x] + (additional commit for) implement improvement #1662
https://java.net/jira/browse/GRIZZLY-1662
"Check that kernel ThreadPoolConfig size is big enough to run configured 
number of SelectorRunners"


Revisions:
----------
be6193310b07b13c240b03e9e5c4f5079b24621c


Modified Paths:
---------------
modules/grizzly/src/main/java/org/glassfish/grizzly/nio/NIOTransport.java
modules/grizzly/src/test/java/org/glassfish/grizzly/ThreadPoolsTest.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
@@ -423,11 +423,15 @@ public abstract class NIOTransport extends 
AbstractTransport
                             .setCorePoolSize(selectorRunnersCnt)
                             .setMaxPoolSize(selectorRunnersCnt)
                             .setPoolName("grizzly-nio-kernel");
+                } else if (kernelPoolConfig.getMaxPoolSize() < 
selectorRunnersCnt) {
+                    LOGGER.log(Level.INFO, "Adjusting kernel thread pool to 
max "
+                            + "size {0} to handle configured number of 
SelectorRunners",
+                            selectorRunnersCnt);
+                    kernelPoolConfig.setCorePoolSize(selectorRunnersCnt)
+                            .setMaxPoolSize(selectorRunnersCnt);
                 }
+
                 kernelPoolConfig.setMemoryManager(memoryManager);
-                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(
                                 kernelPoolConfig));--- 
a/modules/grizzly/src/test/java/org/glassfish/grizzly/ThreadPoolsTest.java
+++ b/modules/grizzly/src/test/java/org/glassfish/grizzly/ThreadPoolsTest.java
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013-2014 Oracle and/or its affiliates. All rights reserved.
  *
  * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common Development
@@ -51,6 +51,10 @@ import java.util.Map;
 import java.util.concurrent.ArrayBlockingQueue;
 
 import static junit.framework.Assert.assertEquals;
+import org.glassfish.grizzly.nio.transport.TCPNIOTransport;
+import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder;
+import org.glassfish.grizzly.strategies.SameThreadIOStrategy;
+import org.glassfish.grizzly.strategies.WorkerThreadIOStrategy;
 
 public class ThreadPoolsTest {
 
@@ -74,4 +78,47 @@ public class ThreadPoolsTest {
         assertEquals("Pool did not properly initialize threads based on core 
pool size configuration.", 5, ((Map) workers.get(fixedThreadPool)).size());
     }
 
+    @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();
+        }
+    }    
 }





[grizzly~git:be619331] [2.3.x] + (additional commit for) implement improvement #1662

oleksiys 03/14/2014
Terms of Use; Privacy Policy; Copyright ©2013-2016 (revision 20160708.bf2ac18)
 
 
Close
loading
Please Confirm
Close