Skip to content
Permalink
Browse files
JIRA-1223
closes #107
  • Loading branch information
Maja Kabiljo committed Sep 9, 2019
1 parent 5edbdb2 commit 1c5a4e7790d526edfe31a03e41749c9d71f3f3fa
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
@@ -1311,5 +1311,11 @@ public interface GiraphConstants {
"Disables GiraphClassResolver, which is a custom implementation " +
"of kryo class resolver that avoids writing class names to the " +
"underlying stream for faster serialization.");

/**
* Path where jmap exists
*/
StrConfOption JMAP_PATH = new StrConfOption("giraph.jmapPath", "jmap",
"Path to use for invoking jmap");
}
// CHECKSTYLE: resume InterfaceIsTypeCheck
@@ -30,8 +30,6 @@
* Helper to run jmap and print the output
*/
public class JMap {
/** The command to run */
public static final String CMD = "jmap ";
/** Arguments to pass in to command */
public static final String ARGS = " -histo ";
/** This option will print out onlu live objects */
@@ -58,29 +56,34 @@ public static int getProcessId() {
*
* @param numLines Number of lines to print
* @param liveObjectsOnly Should we only print non GC-able objects?
* @param jmapPath Path to jmap binary
*/
public static void heapHistogramDump(int numLines,
boolean liveObjectsOnly) {
heapHistogramDump(numLines, liveObjectsOnly, System.err);
boolean liveObjectsOnly,
String jmapPath) {
heapHistogramDump(numLines, liveObjectsOnly, System.err, jmapPath);
}

/**
* Run jmap, print numLines of output from it to stderr.
*
* @param numLines Number of lines to print
* @param jmapPath Path to jmap binary
*/
public static void heapHistogramDump(int numLines) {
heapHistogramDump(numLines, System.err);
public static void heapHistogramDump(int numLines, String jmapPath) {
heapHistogramDump(numLines, System.err, jmapPath);
}

/**
* Run jmap, print numLines of output from it to stream passed in.
*
* @param numLines Number of lines to print
* @param printStream Stream to print to
* @param jmapPath Path to jmap binary
*/
public static void heapHistogramDump(int numLines, PrintStream printStream) {
heapHistogramDump(numLines, false, printStream);
public static void heapHistogramDump(int numLines, PrintStream printStream,
String jmapPath) {
heapHistogramDump(numLines, false, printStream, jmapPath);
}

/**
@@ -89,13 +92,15 @@ public static void heapHistogramDump(int numLines, PrintStream printStream) {
* @param numLines Number of lines to print
* @param liveObjectsOnly Should we only print non GC-able objects?
* @param printStream Stream to print to
* @param jmapPath Path to jmap binary
*/
private static void heapHistogramDump(int numLines,
boolean liveObjectsOnly,
PrintStream printStream) {
PrintStream printStream,
String jmapPath) {
try {
String args = liveObjectsOnly ? LIVE_HISTO_OPTION : ARGS;
Process p = Runtime.getRuntime().exec(CMD + args + getProcessId());
Process p = Runtime.getRuntime().exec(jmapPath + args + getProcessId());
BufferedReader in = new BufferedReader(
new InputStreamReader(p.getInputStream(), Charset.defaultCharset()));
printStream.println("JMap " +
@@ -47,6 +47,8 @@ public class JMapHistoDumper implements MasterObserver, WorkerObserver {
private Thread thread;
/** Halt jmap thread */
private volatile boolean stop = false;
/** Path to jmap*/
private String jmapPath;

@Override
public void preLoad() {
@@ -90,7 +92,7 @@ public void startJMapThread() {
@Override
public void run() {
while (!stop) {
JMap.heapHistogramDump(linesToPrint, liveObjectsOnly);
JMap.heapHistogramDump(linesToPrint, liveObjectsOnly, jmapPath);
ThreadUtils.trySleep(sleepMillis);
}
}
@@ -116,6 +118,7 @@ public void setConf(ImmutableClassesGiraphConfiguration configuration) {
sleepMillis = GiraphConstants.JMAP_SLEEP_MILLIS.get(configuration);
linesToPrint = GiraphConstants.JMAP_PRINT_LINES.get(configuration);
liveObjectsOnly = GiraphConstants.JMAP_LIVE_ONLY.get(configuration);
jmapPath = GiraphConstants.JMAP_PATH.get(configuration);
}

@Override
@@ -54,6 +54,8 @@ public class ReactiveJMapHistoDumper extends
private Thread thread;
/** Halt jmap thread */
private volatile boolean stop = false;
/** Path to jmap*/
private String jmapPath;

@Override
public void preLoad() {
@@ -100,7 +102,7 @@ public void run() {
long potentialMemory = (runtime.maxMemory() -
runtime.totalMemory()) + runtime.freeMemory();
if (potentialMemory / MB < minFreeMemory) {
JMap.heapHistogramDump(linesToPrint);
JMap.heapHistogramDump(linesToPrint, jmapPath);
}
ThreadUtils.trySleep(sleepMillis);
}
@@ -127,5 +129,6 @@ public void setConf(ImmutableClassesGiraphConfiguration configuration) {
sleepMillis = GiraphConstants.JMAP_SLEEP_MILLIS.get(configuration);
linesToPrint = GiraphConstants.JMAP_PRINT_LINES.get(configuration);
minFreeMemory = GiraphConstants.MIN_FREE_MBS_ON_HEAP.get(configuration);
jmapPath = GiraphConstants.JMAP_PATH.get(configuration);
}
}

0 comments on commit 1c5a4e7

Please sign in to comment.