Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNAP-2503: jvmkill issues SIGTERM before SIGKILL #450

Open
wants to merge 21 commits into
base: snappy/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
85962e3
adding jvmkill.c and also merged it into libgemfirexd64.so and libgem…
hemanthmeka Oct 11, 2018
84f3fed
changes related to review comments and enhances
hemanthmeka Oct 12, 2018
d6827e4
replacing realpath command with absPath()
hemanthmeka Oct 15, 2018
f9bb646
Merge branch 'snappy/master' of https://github.com/SnappyDataInc/snap…
hemanthmeka Oct 16, 2018
34dfe85
Merge branch 'snappy/master' of https://github.com/SnappyDataInc/snap…
hemanthmeka Oct 19, 2018
4007ec8
added generation of ibgemfirexd*.dylib for Mac
hemanthmeka Oct 19, 2018
d9035e7
Merge branch 'snappy/master' of https://github.com/SnappyDataInc/snap…
hemanthmeka Oct 22, 2018
003de5d
adding gemfirexd(64).dylib files
hemanthmeka Oct 22, 2018
3e4bdf9
recompiled libgemfirexd so files on centos with logging in jvmkill
invalid-email-address Oct 23, 2018
b1cf612
minor fixes
invalid-email-address Oct 23, 2018
1e9e373
logging heap histogram on critical event
hemanthmeka Oct 23, 2018
937546d
adding libgemfirexd dylib files
hemanthmeka Oct 24, 2018
66391d4
adding .so files compiled on centos
invalid-email-address Oct 24, 2018
581f282
incorporating review suggestions
invalid-email-address Oct 25, 2018
3f468e4
implementing review suggestions
hemanthmeka Oct 30, 2018
fa36c22
Merge branch 'snappy/master' of https://github.com/SnappyDataInc/snap…
hemanthmeka Oct 30, 2018
f0d3756
Merge branch 'snappy/master' of https://github.com/SnappyDataInc/snap…
hemanthmeka Oct 30, 2018
6bf9be0
onOutOfMemoryError allowing a cleaner kill
hemanthmeka Dec 6, 2018
0abcf4e
latest changes from snappy/master
hemanthmeka Dec 6, 2018
fffcb90
adding timeout properties for jvmkill and heap dump
hemanthmeka Dec 7, 2018
505f354
minor formatting and cleanup
hemanthmeka Dec 7, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import java.lang.management.MemoryPoolMXBean;
import java.lang.management.MemoryType;
import java.lang.management.MemoryUsage;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -93,9 +95,6 @@ public final class HeapMemoryMonitor implements NotificationListener,
private static final int POLLER_INTERVAL =
Integer.getInteger(POLLER_INTERVAL_PROP, 500);

// Duration in millis to wait for jmap -histo to finish
private static final int JMAP_HISTO_SLEEP_DURATION = 3 * 1000;

// This holds a new event as it transitions from updateStateAndSendEvent(...) to fillInProfile()
private ThreadLocal<MemoryEvent> upcomingEvent = new ThreadLocal<MemoryEvent>();

Expand Down Expand Up @@ -693,17 +692,34 @@ public void jmapDump(String pid) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss");
String dateSuffix = dateFormat.format(new java.util.Date(
System.currentTimeMillis()));
Integer waitTime;

if (inputArgs.contains("-XX:+HeapDumpOnOutOfMemoryError")) {
Integer heapDumpTimeout = 30;
try {
Object[] filtArgs = inputArgs.stream()
.filter(e -> e.contains("snappydata.onCriticalHeapDumpTimeoutSeconds="))
.map(e -> e.split("=")[1]).toArray();
if (filtArgs.length > 0) {
heapDumpTimeout = Integer.parseInt(filtArgs[0].toString());
}
} catch (NumberFormatException e) {
logger.warn("Failed to parse user provided value for " +
"OnCriticalHeapDumpTimeoutSeconds. default value of 30 will be used");
}

jmapCommand = new String[] { "/bin/sh", "-c", "jmap -dump:format=b,file=" +
"java_pid" + pid + "-" + dateSuffix + ".hprof " + pid
};
waitTime = heapDumpTimeout * 1000;
} else {
jmapCommand = new String[] { "/bin/sh", "-c", "jmap -histo " + pid + " > " +
"java_pid" + pid + "-" + dateSuffix + ".jmap"
};
waitTime = 3 * 1000;
}
Process jmapProcess = Runtime.getRuntime().exec(jmapCommand);
jmapProcess.waitFor(JMAP_HISTO_SLEEP_DURATION, TimeUnit.MILLISECONDS);
jmapProcess.waitFor(waitTime, TimeUnit.MILLISECONDS);
} catch (Exception e) {
logger.error("Failed to log heap histogram for pid: " + pid, e);
}
Expand Down
Binary file modified gemfirexd/core/lib/libgemfirexd.so
Binary file not shown.
Binary file modified gemfirexd/core/lib/libgemfirexd64.so
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,23 @@ resourceExhausted(
jint flags,
const void *reserved,
const char *description) {
logMessage("ResourceExhausted: %s: killing current process!", description);
int sleepSeconds = 0;
if (getenv("JVMKILL_SLEEP_SECONDS")) {
const char* s = getenv("JVMKILL_SLEEP_SECONDS");
char *ptr;
sleepSeconds = strtol(s, &ptr, 10);
}
if (sleepSeconds < 1) {
sleepSeconds = 30;
}

logMessage("ResourceExhausted: %s: terminating current process!\n", description);
kill(getpid(), SIGTERM);

logMessage("SIGKILL will be issued after %d seconds if pid doesn't exit\n", sleepSeconds);
sleep(sleepSeconds);

logMessage("ResourceExhausted: %s: killing current process!\n", description);
kill(getpid(), SIGKILL);
}

Expand Down Expand Up @@ -78,4 +94,4 @@ Agent_OnLoad(JavaVM *vm, char *options, void *reserved) {
}

return JNI_OK;
}
}