runzhiwang commented on a change in pull request #242: [LIVY-336][SERVER] Livy 
should not spawn one thread per job to track the job on Yarn
URL: https://github.com/apache/incubator-livy/pull/242#discussion_r354783003
 
 

 ##########
 File path: server/src/main/scala/org/apache/livy/utils/SparkYarnApp.scala
 ##########
 @@ -111,7 +152,48 @@ object SparkYarnApp extends Logging {
     }
   }
 
+  class YarnAppMonitorRunnable extends Runnable {
+    override def run(): Unit = {
+      var loop = true
+      while (loop) {
+        try {
+          // update time when monitor app so that
+          // checkMonitorAppTimeoutThread can check whether the thread was 
blocked on monitoring
+          monitorAppThreadMap.put(Thread.currentThread(), 
System.currentTimeMillis())
+
+          val app = appQueue.poll()
+          if (app != null) {
+            app.monitorSparkYarnApp()
 
+            if (app.isRunning) {
+              appQueue.add(app)
+            }
+          }
+
+          Thread.sleep(yarnPoolInterval)
+        } catch {
+          case e: InterruptedException =>
+            loop = false
+            error(s"YarnAppMonitorRunnable Exception whiling monitor", e)
+        }
+      }
+    }
+  }
+
+  private def initYarnAppMonitorThreadPool(livyConf: LivyConf): Unit = {
+    val poolSize = livyConf.getInt(LivyConf.YARN_APP_LOOKUP_THREAD_POOL_SIZE)
+    val yarnAppMonitorThreadPool: ExecutorService =
+      Executors.newFixedThreadPool(poolSize)
+
+    val runnable = new YarnAppMonitorRunnable()
+    for (i <- 0 until poolSize) {
+      yarnAppMonitorThreadPool.execute(runnable)
+    }
 
 Review comment:
   @jahstreet Hi,Because we start `poolSize` long running threads to monitor 
all the app, each execute start one thread.

----------------------------------------------------------------
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

Reply via email to