use of java.lang.management.MemoryUsage in project hbase by apache.
the class HRegionServer method buildServerLoad.
ClusterStatusProtos.ServerLoad buildServerLoad(long reportStartTime, long reportEndTime) throws IOException {
// We're getting the MetricsRegionServerWrapper here because the wrapper computes requests
// per second, and other metrics As long as metrics are part of ServerLoad it's best to use
// the wrapper to compute those numbers in one place.
// In the long term most of these should be moved off of ServerLoad and the heart beat.
// Instead they should be stored in an HBase table so that external visibility into HBase is
// improved; Additionally the load balancer will be able to take advantage of a more complete
// history.
MetricsRegionServerWrapper regionServerWrapper = metricsRegionServer.getRegionServerWrapper();
Collection<Region> regions = getOnlineRegionsLocalContext();
long usedMemory = -1L;
long maxMemory = -1L;
final MemoryUsage usage = MemorySizeUtil.safeGetHeapMemoryUsage();
if (usage != null) {
usedMemory = usage.getUsed();
maxMemory = usage.getMax();
}
ClusterStatusProtos.ServerLoad.Builder serverLoad = ClusterStatusProtos.ServerLoad.newBuilder();
serverLoad.setNumberOfRequests((int) regionServerWrapper.getRequestsPerSecond());
serverLoad.setTotalNumberOfRequests((int) regionServerWrapper.getTotalRequestCount());
serverLoad.setUsedHeapMB((int) (usedMemory / 1024 / 1024));
serverLoad.setMaxHeapMB((int) (maxMemory / 1024 / 1024));
Set<String> coprocessors = getWAL(null).getCoprocessorHost().getCoprocessors();
Builder coprocessorBuilder = Coprocessor.newBuilder();
for (String coprocessor : coprocessors) {
serverLoad.addCoprocessors(coprocessorBuilder.setName(coprocessor).build());
}
RegionLoad.Builder regionLoadBldr = RegionLoad.newBuilder();
RegionSpecifier.Builder regionSpecifier = RegionSpecifier.newBuilder();
for (Region region : regions) {
if (region.getCoprocessorHost() != null) {
Set<String> regionCoprocessors = region.getCoprocessorHost().getCoprocessors();
Iterator<String> iterator = regionCoprocessors.iterator();
while (iterator.hasNext()) {
serverLoad.addCoprocessors(coprocessorBuilder.setName(iterator.next()).build());
}
}
serverLoad.addRegionLoads(createRegionLoad(region, regionLoadBldr, regionSpecifier));
for (String coprocessor : getWAL(region.getRegionInfo()).getCoprocessorHost().getCoprocessors()) {
serverLoad.addCoprocessors(coprocessorBuilder.setName(coprocessor).build());
}
}
serverLoad.setReportStartTime(reportStartTime);
serverLoad.setReportEndTime(reportEndTime);
if (this.infoServer != null) {
serverLoad.setInfoServerPort(this.infoServer.getPort());
} else {
serverLoad.setInfoServerPort(-1);
}
// for the replicationLoad purpose. Only need to get from one service
// either source or sink will get the same info
ReplicationSourceService rsources = getReplicationSourceService();
if (rsources != null) {
// always refresh first to get the latest value
ReplicationLoad rLoad = rsources.refreshAndGetReplicationLoad();
if (rLoad != null) {
serverLoad.setReplLoadSink(rLoad.getReplicationLoadSink());
for (ClusterStatusProtos.ReplicationLoadSource rLS : rLoad.getReplicationLoadSourceList()) {
serverLoad.addReplLoadSource(rLS);
}
}
}
return serverLoad.build();
}
use of java.lang.management.MemoryUsage in project cassandra by apache.
the class GCInspector method handleNotification.
public void handleNotification(final Notification notification, final Object handback) {
String type = notification.getType();
if (type.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
// retrieve the garbage collection notification information
CompositeData cd = (CompositeData) notification.getUserData();
GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from(cd);
String gcName = info.getGcName();
GcInfo gcInfo = info.getGcInfo();
long duration = gcInfo.getDuration();
/*
* The duration supplied in the notification info includes more than just
* application stopped time for concurrent GCs. Try and do a better job coming up with a good stopped time
* value by asking for and tracking cumulative time spent blocked in GC.
*/
GCState gcState = gcStates.get(gcName);
if (gcState.assumeGCIsPartiallyConcurrent) {
long previousTotal = gcState.lastGcTotalDuration;
long total = gcState.gcBean.getCollectionTime();
gcState.lastGcTotalDuration = total;
// may be zero for a really fast collection
duration = total - previousTotal;
}
StringBuilder sb = new StringBuilder();
sb.append(info.getGcName()).append(" GC in ").append(duration).append("ms. ");
long bytes = 0;
Map<String, MemoryUsage> beforeMemoryUsage = gcInfo.getMemoryUsageBeforeGc();
Map<String, MemoryUsage> afterMemoryUsage = gcInfo.getMemoryUsageAfterGc();
for (String key : gcState.keys(info)) {
MemoryUsage before = beforeMemoryUsage.get(key);
MemoryUsage after = afterMemoryUsage.get(key);
if (after != null && after.getUsed() != before.getUsed()) {
sb.append(key).append(": ").append(before.getUsed());
sb.append(" -> ");
sb.append(after.getUsed());
if (!key.equals(gcState.keys[gcState.keys.length - 1]))
sb.append("; ");
bytes += before.getUsed() - after.getUsed();
}
}
while (true) {
State prev = state.get();
if (state.compareAndSet(prev, new State(duration, bytes, prev)))
break;
}
String st = sb.toString();
if (GC_WARN_THRESHOLD_IN_MS != 0 && duration > GC_WARN_THRESHOLD_IN_MS)
logger.warn(st);
else if (duration > MIN_LOG_DURATION)
logger.info(st);
else if (logger.isTraceEnabled())
logger.trace(st);
if (duration > STAT_THRESHOLD)
StatusLogger.log();
// if we just finished an old gen collection and we're still using a lot of memory, try to reduce the pressure
if (gcState.assumeGCIsOldGen)
LifecycleTransaction.rescheduleFailedDeletions();
}
}
use of java.lang.management.MemoryUsage in project databus by linkedin.
the class JavaStatsRequestProcessor method processHeapMemoryStats.
private void processHeapMemoryStats(DatabusRequest request) throws IOException {
MemoryUsage memStats = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
writeJsonObjectToResponse(memStats, request);
}
use of java.lang.management.MemoryUsage in project databus by linkedin.
the class JavaStatsRequestProcessor method processNonHeapMemoryStats.
private void processNonHeapMemoryStats(DatabusRequest request) throws IOException {
MemoryUsage memStats = ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage();
writeJsonObjectToResponse(memStats, request);
}
use of java.lang.management.MemoryUsage in project orientdb by orientechnologies.
the class SpeedTestData method startTimer.
/*
* (non-Javadoc)
*
* @see com.orientechnologies.common.test.SpeedTest#startTimer(java.lang.String)
*/
public void startTimer(final String iName) {
Runtime.getRuntime().runFinalization();
Runtime.getRuntime().gc();
try {
Thread.sleep(TIME_WAIT);
} catch (InterruptedException e) {
}
final MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
final MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage();
final MemoryUsage nonHeapMemoryUsage = memoryMXBean.getNonHeapMemoryUsage();
currentTestName = iName;
currentTestHeapCommittedMemory = heapMemoryUsage.getCommitted();
currentTestHeapUsedMemory = heapMemoryUsage.getUsed();
currentTestHeapMaxMemory = heapMemoryUsage.getMax();
currentTestNonHeapCommittedMemory = nonHeapMemoryUsage.getCommitted();
currentTestNonHeapUsedMemory = nonHeapMemoryUsage.getUsed();
currentTestNonHeapMaxMemory = nonHeapMemoryUsage.getMax();
System.out.println("-> Started the test of '" + currentTestName + "' (" + cycles + " cycles)");
currentTestTimer = System.currentTimeMillis();
}
Aggregations