[GitHub] [servicecomb-java-chassis] liubao68 commented on a change in pull request #1161: [SCB-1232] make GroupExecutor configuration compatible to old version

2019-04-01 Thread GitBox
liubao68 commented on a change in pull request #1161: [SCB-1232] make 
GroupExecutor configuration compatible to old version
URL: 
https://github.com/apache/servicecomb-java-chassis/pull/1161#discussion_r270734371
 
 

 ##
 File path: 
core/src/test/java/org/apache/servicecomb/core/executor/TestGroupExecutor.java
 ##
 @@ -86,46 +75,83 @@ public void maxQueueSize() {
   }
 
   @Test
-  public void maxThreads() {
+  public void threads_allDefault() {
 groupExecutor.initConfig();
+Assert.assertEquals(100, groupExecutor.coreThreads);
 Assert.assertEquals(100, groupExecutor.maxThreads);
+  }
+
+  @Test
+  public void threads_compatible() {
+ArchaiusUtils.setProperty(GroupExecutor.KEY_OLD_THREAD, 200);
 
-LogCollector collector = new LogCollector();
-ArchaiusUtils.setProperty(GroupExecutor.KEY_THREAD, 200);
 groupExecutor.initConfig();
+Assert.assertEquals(200, groupExecutor.coreThreads);
 Assert.assertEquals(200, groupExecutor.maxThreads);
-Assert.assertEquals(
-"servicecomb.executor.default.thread-per-group is deprecated, 
recommended to use servicecomb.executor.default.maxThreads-per-group.",
-collector.getEvents().get(collector.getEvents().size() - 
2).getMessage());
-collector.teardown();
+  }
+
+  @Test
+  public void threads_standard() {
+ArchaiusUtils.setProperty(GroupExecutor.KEY_CORE_THREADS, 25);
+ArchaiusUtils.setProperty(GroupExecutor.KEY_MAX_THREADS, 100);
 
-ArchaiusUtils.setProperty(GroupExecutor.KEY_MAX_THREADS, 300);
 groupExecutor.initConfig();
-Assert.assertEquals(300, groupExecutor.maxThreads);
+Assert.assertEquals(25, groupExecutor.coreThreads);
+Assert.assertEquals(100, groupExecutor.maxThreads);
   }
 
   @Test
-  public void adjustCoreThreads() {
+  public void threads_onlyMaxThread() {
 ArchaiusUtils.setProperty(GroupExecutor.KEY_MAX_THREADS, 10);
 
-LogCollector collector = new LogCollector();
 groupExecutor.initConfig();
 Assert.assertEquals(10, groupExecutor.maxThreads);
-Assert.assertEquals(
-"coreThreads is bigger than maxThreads, change from 25 to 10.",
-collector.getEvents().get(collector.getEvents().size() - 
2).getMessage());
-collector.teardown();
+Assert.assertEquals(10, groupExecutor.maxThreads);
 
 Review comment:
   Why you keep this:
 3.if configured queue, and queue size is not max int, then coreThreads 
default to be 25
   
   I can't figure out the relationship between queue size and max thread size. 
For example, if users configure queue size to be MAX_INT/2
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [servicecomb-java-chassis] liubao68 commented on a change in pull request #1161: [SCB-1232] make GroupExecutor configuration compatible to old version

2019-04-01 Thread GitBox
liubao68 commented on a change in pull request #1161: [SCB-1232] make 
GroupExecutor configuration compatible to old version
URL: 
https://github.com/apache/servicecomb-java-chassis/pull/1161#discussion_r27071
 
 

 ##
 File path: 
core/src/main/java/org/apache/servicecomb/core/executor/GroupExecutor.java
 ##
 @@ -83,25 +83,31 @@ public void init() {
   }
 
   public void initConfig() {
-groupCount = 
DynamicPropertyFactory.getInstance().getIntProperty(KEY_GROUP, 2).get();
-coreThreads = 
DynamicPropertyFactory.getInstance().getIntProperty(KEY_CORE_THREADS, 25).get();
-
-maxThreads = 
DynamicPropertyFactory.getInstance().getIntProperty(KEY_MAX_THREADS, -1).get();
-if (maxThreads <= 0) {
-  maxThreads = 
DynamicPropertyFactory.getInstance().getIntProperty(KEY_THREAD, -1).get();
-  if (maxThreads > 0) {
-LOGGER.warn("{} is deprecated, recommended to use {}.", KEY_THREAD, 
KEY_MAX_THREADS);
-  } else {
-maxThreads = 100;
-  }
-}
-if (coreThreads > maxThreads) {
-  LOGGER.warn("coreThreads is bigger than maxThreads, change from {} to 
{}.", coreThreads, maxThreads);
+LOGGER.info("JDK standard thread pool rules:\n"
++ "1.use core threads.\n"
++ "2.if all core threads are busy, then queue the request.\n"
++ "3.if queue is full, then create new thread util reach the limit of 
max threads.\n"
++ "4.if queue is full, and threads count is max, then reject the 
request.");
+
+// the complex logic is to keep compatible
+// otherwise can throw exception if configuration is invalid.
+coreThreads = 
DynamicPropertyFactory.getInstance().getIntProperty(KEY_CORE_THREADS, -1).get();
+
+int oldMaxThreads = 
DynamicPropertyFactory.getInstance().getIntProperty(KEY_OLD_MAX_THREAD, 
-1).get();
+maxThreads = 
DynamicPropertyFactory.getInstance().getIntProperty(KEY_MAX_THREADS, 
oldMaxThreads).get();
+maxThreads = Math.max(coreThreads, maxThreads);
+maxThreads = maxThreads <= 0 ? 100 : maxThreads;
+
+maxQueueSize = 
DynamicPropertyFactory.getInstance().getIntProperty(KEY_MAX_QUEUE_SIZE, 
Integer.MAX_VALUE).get();
+if (maxQueueSize == Integer.MAX_VALUE) {
   coreThreads = maxThreads;
+  LOGGER.info("not configured {},  make coreThreads and maxThreads to be 
{}.", KEY_MAX_QUEUE_SIZE, maxThreads);
+} else {
+  coreThreads = coreThreads <= 0 ? 25 : coreThreads;
 
 Review comment:
   This statement should be calculated before 
   maxThreads = Math.max(coreThreads, maxThreads);
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services