You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@samza.apache.org by ja...@apache.org on 2017/08/14 23:59:19 UTC

samza git commit: SAMZA-1390; Update SamzaMonitorService to spawn deamon threads

Repository: samza
Updated Branches:
  refs/heads/master b1277d8b4 -> a0aae5292


SAMZA-1390; Update SamzaMonitorService to spawn deamon threads

Observed in LinkedIn production setup that samza-rest jvm process doesn’t stop after main
thread death(due to jetty server failures) since non-deamon threads spawned for
`SamzaMonitorService` are alive.

This affects samza-rest jvm process lifecycle management. To fix this, plugging
in ThreadFactory which sets Thread name format & marks them as daemon.

Author: Shanthoosh Venkataraman <sv...@linkedin.com>

Reviewers: Jagadish <ja...@apache.org>

Closes #270 from shanthoosh/make_samza_rest_non_daemon


Project: http://git-wip-us.apache.org/repos/asf/samza/repo
Commit: http://git-wip-us.apache.org/repos/asf/samza/commit/a0aae529
Tree: http://git-wip-us.apache.org/repos/asf/samza/tree/a0aae529
Diff: http://git-wip-us.apache.org/repos/asf/samza/diff/a0aae529

Branch: refs/heads/master
Commit: a0aae5292c31c8bc260bb15c03396279a30f19ef
Parents: b1277d8
Author: Shanthoosh Venkataraman <sv...@linkedin.com>
Authored: Mon Aug 14 17:01:09 2017 -0700
Committer: Jagadish <ja...@apache.org>
Committed: Mon Aug 14 17:01:09 2017 -0700

----------------------------------------------------------------------
 .../java/org/apache/samza/rest/SamzaRestService.java  | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/samza/blob/a0aae529/samza-rest/src/main/java/org/apache/samza/rest/SamzaRestService.java
----------------------------------------------------------------------
diff --git a/samza-rest/src/main/java/org/apache/samza/rest/SamzaRestService.java b/samza-rest/src/main/java/org/apache/samza/rest/SamzaRestService.java
index de6febb..2f940e3 100644
--- a/samza-rest/src/main/java/org/apache/samza/rest/SamzaRestService.java
+++ b/samza-rest/src/main/java/org/apache/samza/rest/SamzaRestService.java
@@ -18,7 +18,9 @@
  */
 package org.apache.samza.rest;
 
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
 import java.util.Map;
+import java.util.concurrent.ThreadFactory;
 import joptsimple.OptionSet;
 import org.apache.samza.config.MapConfig;
 import org.apache.samza.config.MetricsConfig;
@@ -84,6 +86,7 @@ public class SamzaRestService {
    */
   public static void main(String[] args)
       throws Exception {
+    ScheduledExecutorSchedulingProvider schedulingProvider = null;
     try {
       SamzaRestConfig config = parseConfig(args);
       ReadableMetricsRegistry metricsRegistry = new MetricsRegistryMap();
@@ -99,8 +102,11 @@ public class SamzaRestService {
       restService.addServlet(container, "/*");
 
       // Schedule monitors to run
-      ScheduledExecutorService schedulingService = Executors.newScheduledThreadPool(1);
-      ScheduledExecutorSchedulingProvider schedulingProvider = new ScheduledExecutorSchedulingProvider(schedulingService);
+      ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(true)
+                                                              .setNameFormat("MonitorThread-%d")
+                                                              .build();
+      ScheduledExecutorService schedulingService = Executors.newScheduledThreadPool(1, threadFactory);
+      schedulingProvider = new ScheduledExecutorSchedulingProvider(schedulingService);
       SamzaMonitorService monitorService = new SamzaMonitorService(config,
                                                                    metricsRegistry,
                                                                    schedulingProvider);
@@ -110,6 +116,10 @@ public class SamzaRestService {
       monitorService.stop();
     } catch (Throwable t) {
       log.error("Exception in main.", t);
+    } finally {
+      if (schedulingProvider != null){
+        schedulingProvider.stop();
+      }
     }
   }