Skip to content

Commit

Permalink
fix some details about structure
Browse files Browse the repository at this point in the history
  • Loading branch information
ChangerYoung committed Nov 4, 2017
1 parent eb4000b commit 4275177
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 83 deletions.
30 changes: 19 additions & 11 deletions core/common/src/main/java/alluxio/PropertyKey.java
Expand Up @@ -1887,27 +1887,32 @@ public String toString() {
.build();

//
// JVM related properties
// JVM Monitor related properties
//
public static final PropertyKey JVM_MONITOR_WARN_THRESHOLD_MS =
new Builder(Name.JVM_MONITOR_WARN_THRESHOLD_MS)
.setDefaultValue(10000)
.setDescription("Extra sleep time longer than this threshold, log WARN.")
.build();
public static final PropertyKey JVM_MONITOR_INFO_THRESHOLD_MS =
new Builder(Name.JVM_MONITOR_INFO_THRESHOLD_MS)
.setDefaultValue(1000)
.setDescription("Extra sleep time longer than this threshold, log INFO.")
.build();
public static final PropertyKey JVM_MONITOR_SLEEP_INTERVAL_MS =
new Builder(Name.JVM_MONITOR_SLEEP_INTERVAL_MS)
.setDefaultValue(500)
.setDescription("The time for the JVM monitor thread to sleep.")
.build();
public static final PropertyKey JVM_MONITOR_MASTER_ENABLE =
new Builder(Name.JVM_MONITOR_MASTER_ENABLE)
public static final PropertyKey MASTER_JVM_MONITOR_ENABLED =
new Builder(Name.MASTER_JVM_MONITOR_ENABLED)
.setDefaultValue(false)
.setDescription("Whether to enable start JVM monitor thread on master.")
.build();
public static final PropertyKey JVM_MONITOR_WORKER_ENABLE =
new Builder(Name.JVM_MONITOR_WORKER_ENABLE)
public static final PropertyKey WORKER_JVM_MONITOR_ENABLED =
new Builder(Name.WORKER_JVM_MONITOR_ENABLED)
.setDefaultValue(false)
.setDescription("Whether to enable start JVM monitor thread on worker.")
.build();

/**
Expand Down Expand Up @@ -2366,13 +2371,16 @@ public static final class Name {
public static final String SECURITY_LOGIN_USERNAME = "alluxio.security.login.username";

//
// JVM related properties
// JVM Monitor related properties
//
public static final String JVM_MONITOR_WARN_THRESHOLD_MS = "jvm.monitor.warn.threshold.ms";
public static final String JVM_MONITOR_INFO_THRESHOLD_MS = "jvm.monitor.info.threshold.ms";
public static final String JVM_MONITOR_SLEEP_INTERVAL_MS = "jvm.monitor.sleep.interval.ms";
public static final String JVM_MONITOR_MASTER_ENABLE = "jvm.monitor.master.enable";
public static final String JVM_MONITOR_WORKER_ENABLE = "jvm.monitor.worker.enable";
public static final String JVM_MONITOR_WARN_THRESHOLD_MS =
"alluxio.jvm.monitor.warn.threshold.ms";
public static final String JVM_MONITOR_INFO_THRESHOLD_MS =
"alluxio.jvm.monitor.info.threshold.ms";
public static final String JVM_MONITOR_SLEEP_INTERVAL_MS =
"alluxio.jvm.monitor.sleep.interval.ms";
public static final String MASTER_JVM_MONITOR_ENABLED = "alluxio.master.jvm.monitor.enabled";
public static final String WORKER_JVM_MONITOR_ENABLED = "alluxio.worker.jvm.monitor.enabled";

private Name() {} // prevent instantiation
}
Expand Down
50 changes: 0 additions & 50 deletions core/common/src/main/java/alluxio/util/Daemon.java

This file was deleted.

63 changes: 43 additions & 20 deletions core/common/src/main/java/alluxio/util/JvmPauseMonitor.java
Expand Up @@ -39,8 +39,7 @@
*/
@NotThreadSafe
public final class JvmPauseMonitor {
private static final Log LOG = LogFactory.getLog(
JvmPauseMonitor.class);
private static final Log LOG = LogFactory.getLog(JvmPauseMonitor.class);

/** The time to sleep. */
private final long mGcSleepIntervalMs;
Expand All @@ -52,9 +51,9 @@ public final class JvmPauseMonitor {
private final long mInfoThresholdMs;

/** Times extra sleep time exceed WARN. */
private long mWarnTimeExceededMS = 0;
private long mWarnTimeExceeded = 0;
/** Times extra sleep time exceed INFO. */
private long mInfoTimeExceededMS = 0;
private long mInfoTimeExceeded = 0;
/** Total extra sleep time. */
private long mTotalExtraTimeMs = 0;

Expand All @@ -73,8 +72,7 @@ public JvmPauseMonitor() {
* Starts jvm monitor thread.
*/
public void start() {
Preconditions.checkState(mJvmMonitorThread == null,
"JVM monitor thread already started");
Preconditions.checkState(mJvmMonitorThread == null, "JVM monitor thread already started");
mJvmMonitorThread = new Daemon(new Monitor());
mJvmMonitorThread.start();
}
Expand Down Expand Up @@ -112,14 +110,14 @@ public boolean isStarted() {
* @return time exceeds WARN threshold in milliseconds
*/
public long getWarnTimeExceeded() {
return mWarnTimeExceededMS;
return mWarnTimeExceeded;
}

/**
* @return time exceeds INFO threshold in milliseconds
*/
public long getInfoTimeExceeded() {
return mInfoTimeExceededMS;
return mInfoTimeExceeded;
}

/**
Expand All @@ -136,10 +134,10 @@ private String getMemoryInfo() {
+ runtime.freeMemory() / (1024 * 1024) + "M";
}

private String formatLogString(long extraSleepTime,
private StringBuilder formatLogString(long extraSleepTime,
Map<String, GarbageCollectorMXBean> gcMXBeanMapBeforeSleep,
Map<String, GarbageCollectorMXBean> gcMXBeanMapAfterSleep) {
List<String> diffBean = Lists.newArrayList();
List<String> beanDiffs = Lists.newArrayList();
GarbageCollectorMXBean oldBean;
GarbageCollectorMXBean newBean;
Set<String> nameSet = Sets.intersection(gcMXBeanMapBeforeSleep.keySet(),
Expand All @@ -148,26 +146,27 @@ private String formatLogString(long extraSleepTime,
oldBean = gcMXBeanMapBeforeSleep.get(name);
newBean = gcMXBeanMapAfterSleep.get(name);
if (oldBean == null) {
diffBean.add("new GCBean created name= '" + newBean.getName() + " count="
beanDiffs.add("new GCBean created name= '" + newBean.getName() + " count="
+ newBean.getCollectionCount() + " time=" + newBean.getCollectionTime() + "ms");
} else if (newBean == null) {
diffBean.add("old GCBean canceled name= '" + oldBean.getName() + " count="
beanDiffs.add("old GCBean canceled name= '" + oldBean.getName() + " count="
+ oldBean.getCollectionCount() + " time=" + oldBean.getCollectionTime() + "ms");
} else {
if (oldBean.getCollectionTime() != newBean.getCollectionTime()
|| oldBean.getCollectionCount() != newBean.getCollectionCount()) {
diffBean.add("GC name= '" + newBean.getName() + " count="
beanDiffs.add("GC name= '" + newBean.getName() + " count="
+ newBean.getCollectionCount() + " time=" + newBean.getCollectionTime() + "ms");
}
}
}
String ret = "JVM paused " + extraSleepTime + "ms\n";
if (diffBean.isEmpty()) {
ret += "No GCs detected ";
StringBuilder ret = new StringBuilder().append("JVM paused ").append(extraSleepTime)
.append("ms\n");
if (beanDiffs.isEmpty()) {
ret.append("No GCs detected ");
} else {
ret += "GC list:\n" + Joiner.on("\n").join(diffBean);
ret.append("GC list:\n" + Joiner.on("\n").join(beanDiffs));
}
ret += "\n" + getMemoryInfo();
ret.append("\n").append(getMemoryInfo());
return ret;
}

Expand Down Expand Up @@ -198,16 +197,40 @@ public void run() {
Map<String, GarbageCollectorMXBean> gcBeanMapAfterSleep = getGarbageCollectorMXBeans();

if (extraTime > mWarnThresholdMs) {
++mWarnTimeExceededMS;
mWarnTimeExceeded++;
LOG.warn(formatLogString(
extraTime, gcBeanMapBeforeSleep, gcBeanMapAfterSleep));
} else if (extraTime > mInfoThresholdMs) {
++mInfoTimeExceededMS;
mInfoTimeExceeded++;
LOG.info(formatLogString(
extraTime, gcBeanMapBeforeSleep, gcBeanMapAfterSleep));
}
gcBeanMapBeforeSleep = gcBeanMapAfterSleep;
}
}
}

private class Daemon extends Thread {

private final Runnable mRunnable;

/**
* Constructs a daemon thread.
*
* @param runnable given a Runnable object
*/
public Daemon(Runnable runnable) {
super(runnable);
setDaemon(true);
mRunnable = runnable;
setName(((Object) mRunnable).toString());
}

/**
* @return mRunnable
*/
public Runnable getRunnable() {
return mRunnable;
}
}
}
Expand Up @@ -289,7 +289,7 @@ protected void startServingWebServer() {
* Starts jvm monitor process, to monitor jvm.
*/
protected void startJvmMonitorProcess() {
if (Configuration.getBoolean(PropertyKey.JVM_MONITOR_MASTER_ENABLE)) {
if (Configuration.getBoolean(PropertyKey.MASTER_JVM_MONITOR_ENABLED)) {
mJvmPauseMonitor = new JvmPauseMonitor();
mJvmPauseMonitor.start();
}
Expand Down
Expand Up @@ -229,7 +229,7 @@ public void start() throws Exception {
mWebServer.start();

// Start monitor jvm
if (Configuration.getBoolean(PropertyKey.JVM_MONITOR_WORKER_ENABLE)) {
if (Configuration.getBoolean(PropertyKey.WORKER_JVM_MONITOR_ENABLED)) {
mJvmPauseMonitor = new JvmPauseMonitor();
mJvmPauseMonitor.start();
}
Expand Down

0 comments on commit 4275177

Please sign in to comment.