[ https://issues.apache.org/jira/browse/HIVE-24723?focusedWorklogId=547133&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-547133 ]
ASF GitHub Bot logged work on HIVE-24723: ----------------------------------------- Author: ASF GitHub Bot Created on: 03/Feb/21 17:10 Start Date: 03/Feb/21 17:10 Worklog Time Spent: 10m Work Description: pgaref commented on a change in pull request #1939: URL: https://github.com/apache/hive/pull/1939#discussion_r569583989 ########## File path: ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezSessionPool.java ########## @@ -395,20 +379,38 @@ int getInitialSize() { } while (!deltaRemaining.compareAndSet(oldVal, oldVal + delta)); int toStart = oldVal + delta; if (toStart <= 0) return createDummyFuture(); - LOG.info("Resizing the pool; adding " + toStart + " sessions"); - - // 2) If we need to create some extra sessions, we'd do it just like startup does. - int threadCount = Math.max(1, Math.min(toStart, - HiveConf.getIntVar(initConf, ConfVars.HIVE_SERVER2_TEZ_SESSION_MAX_INIT_THREADS))); - List<ListenableFutureTask<Boolean>> threadTasks = new ArrayList<>(threadCount); - // This is an async method, so always launch threads, even for a single task. - for (int i = 0; i < threadCount; ++i) { - ListenableFutureTask<Boolean> task = ListenableFutureTask.create( - new CreateSessionsRunnable(deltaRemaining)); - new Thread(task, "Tez pool resize " + i).start(); - threadTasks.add(task); + LOG.info("Resizing the pool; adding {} sessions", toStart); + + final int threadCount = + Math.min(toStart, HiveConf.getIntVar(initConf, ConfVars.HIVE_SERVER2_TEZ_SESSION_MAX_INIT_THREADS)); + + return createSessions(toStart, threadCount); + } + + private ListenableFuture<List<Boolean>> createSessions(int sessionCount, int maxParallel) { Review comment: Shall we use same vars here? Add method doc? ########## File path: ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezSessionPool.java ########## @@ -395,20 +379,38 @@ int getInitialSize() { } while (!deltaRemaining.compareAndSet(oldVal, oldVal + delta)); int toStart = oldVal + delta; if (toStart <= 0) return createDummyFuture(); - LOG.info("Resizing the pool; adding " + toStart + " sessions"); - - // 2) If we need to create some extra sessions, we'd do it just like startup does. - int threadCount = Math.max(1, Math.min(toStart, - HiveConf.getIntVar(initConf, ConfVars.HIVE_SERVER2_TEZ_SESSION_MAX_INIT_THREADS))); - List<ListenableFutureTask<Boolean>> threadTasks = new ArrayList<>(threadCount); - // This is an async method, so always launch threads, even for a single task. - for (int i = 0; i < threadCount; ++i) { - ListenableFutureTask<Boolean> task = ListenableFutureTask.create( - new CreateSessionsRunnable(deltaRemaining)); - new Thread(task, "Tez pool resize " + i).start(); - threadTasks.add(task); + LOG.info("Resizing the pool; adding {} sessions", toStart); + + final int threadCount = + Math.min(toStart, HiveConf.getIntVar(initConf, ConfVars.HIVE_SERVER2_TEZ_SESSION_MAX_INIT_THREADS)); Review comment: Shall we rename toStart -> initialSize for consistency? ########## File path: ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezSessionPool.java ########## @@ -395,20 +379,38 @@ int getInitialSize() { } while (!deltaRemaining.compareAndSet(oldVal, oldVal + delta)); int toStart = oldVal + delta; if (toStart <= 0) return createDummyFuture(); - LOG.info("Resizing the pool; adding " + toStart + " sessions"); - - // 2) If we need to create some extra sessions, we'd do it just like startup does. - int threadCount = Math.max(1, Math.min(toStart, - HiveConf.getIntVar(initConf, ConfVars.HIVE_SERVER2_TEZ_SESSION_MAX_INIT_THREADS))); - List<ListenableFutureTask<Boolean>> threadTasks = new ArrayList<>(threadCount); - // This is an async method, so always launch threads, even for a single task. - for (int i = 0; i < threadCount; ++i) { - ListenableFutureTask<Boolean> task = ListenableFutureTask.create( - new CreateSessionsRunnable(deltaRemaining)); - new Thread(task, "Tez pool resize " + i).start(); - threadTasks.add(task); + LOG.info("Resizing the pool; adding {} sessions", toStart); + + final int threadCount = + Math.min(toStart, HiveConf.getIntVar(initConf, ConfVars.HIVE_SERVER2_TEZ_SESSION_MAX_INIT_THREADS)); + + return createSessions(toStart, threadCount); + } + + private ListenableFuture<List<Boolean>> createSessions(int sessionCount, int maxParallel) { + Preconditions.checkArgument(sessionCount > 0); + Preconditions.checkArgument(maxParallel > 0); Review comment: Second Precondition check is redundant ---------------------------------------------------------------- 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 Issue Time Tracking ------------------- Worklog Id: (was: 547133) Time Spent: 40m (was: 0.5h) > Use ExecutorService in TezSessionPool > ------------------------------------- > > Key: HIVE-24723 > URL: https://issues.apache.org/jira/browse/HIVE-24723 > Project: Hive > Issue Type: Improvement > Components: Tez > Reporter: David Mollitor > Assignee: David Mollitor > Priority: Minor > Labels: pull-request-available > Time Spent: 40m > Remaining Estimate: 0h > > Currently there are some wonky home-made thread pooling action going on in > {{TezSessionPool}}. Replace it with some JDK/Guava goodness. -- This message was sent by Atlassian Jira (v8.3.4#803005)