tillrohrmann commented on a change in pull request #9703: [FLINK-14038]Add 
default GC options for flink on yarn to facilitate debugging
URL: https://github.com/apache/flink/pull/9703#discussion_r341645333
 
 

 ##########
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/clusterframework/BootstrapTools.java
 ##########
 @@ -513,6 +514,76 @@ public static Configuration 
cloneConfiguration(Configuration configuration) {
                return clonedConfiguration;
        }
 
+       /**
+        * Format the default gc logging options
+        * @param logDirectory to save the gc log
+        * @return the formatted gc logging options string
+        */
+       public static String getGCLoggingOpts(String logDirectory) {
+    return "-Xloggc:" + logDirectory + "/gc.log " +
+      "-XX:+PrintGCApplicationStoppedTime " +
+      "-XX:+PrintGCDetails " +
+      "-XX:+PrintGCDateStamps " +
+      "-XX:+UseGCLogFileRotation " +
+      "-XX:NumberOfGCLogFiles=10 " +
+      "-XX:GCLogFileSize=10M " +
+      "-XX:+PrintPromotionFailure " +
+      "-XX:+PrintGCCause";
+       }
+
+       /**
+        * Format the default heapdump options
+        * @param appId application id
+        * @param ident the ident of the process, taskmanager/jobmanager
+        * @param logDirectory to print some logs
+        * @param heapdumpDir to save heap dump file
+        * @return the formatted heapdump options string
+        */
+       public static String getHeapdumpOpts(String appId, String ident, String 
logDirectory, String heapdumpDir) {
+    String dumpDestName = String.format("flink-%s-heapdump.hprof", ident);
+    String dumpFileDestPath = new File(heapdumpDir, appId + "-" + 
dumpDestName).getAbsolutePath();
+    String oomScript = String.format("echo -e 'OutOfMemoryError! Killing 
current process %%p...\n" +
+        "Check gc logs and heapdump file(%s) for details.' > " +
+        logDirectory + "/%s.err; " +
+        "kill -9 %%p",
+      dumpFileDestPath, ident);
+    return String.format("-XX:+HeapDumpOnOutOfMemoryError " +
+        "-XX:HeapDumpPath=%s " +
+        "-XX:OnOutOfMemoryError=\"%s\"",
+      dumpFileDestPath,
+      oomScript);
+       }
+
+       /**
+        * Get the common jvm options
+        * @param appId application id
+        * @param ident the ident of the process, taskmanager/jobmanager
+        * @param logDirectory to print some logs
+   * @param conf flink configuration
+   */
+  public static String getCommonJvmOpts(
+      String appId,
+      String ident,
+      String logDirectory,
+      Configuration conf) {
+    String commonOpts = "";
+               boolean enableGCLogging = 
conf.getBoolean(CoreOptions.FLINK_JVM_DEFAULT_GC_LOGGING);
+    if (enableGCLogging) {
+      // Add default gc logging options if enabled
+      commonOpts += getGCLoggingOpts(logDirectory);
+    }
+               boolean enableHeapDump = 
conf.getBoolean(CoreOptions.FLINK_JVM_HEAPDUMP_ON_OOM);
+    if (enableHeapDump) {
+      // Add default heap dump options if enabled
+                 String heapdumpDir = 
conf.getString(CoreOptions.FLINK_JVM_HEAPDUMP_DIRECTORY);
+      commonOpts += " " + getHeapdumpOpts(appId, ident, logDirectory, 
heapdumpDir);
+    }
+    if (conf.getString(CoreOptions.FLINK_JVM_OPTIONS).length() > 0) {
+                 commonOpts += " " + 
conf.getString(CoreOptions.FLINK_JVM_OPTIONS);
+    }
+    return commonOpts;
+  }
 
 Review comment:
   Here as well. Please use tabs.

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