use of java.lang.management.MemoryMXBean 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();
}
use of java.lang.management.MemoryMXBean in project gocd by gocd.
the class MemoryInformationProvider method asJson.
@Override
public Map<String, Object> asJson() {
MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
LinkedHashMap<String, Object> json = new LinkedHashMap<>();
json.put("Heap", formatInJson(memoryMXBean.getHeapMemoryUsage()));
json.put("Non Heap", formatInJson(memoryMXBean.getNonHeapMemoryUsage()));
json.put("Pending Finalization", memoryMXBean.getObjectPendingFinalizationCount());
return json;
}
use of java.lang.management.MemoryMXBean in project hive by apache.
the class TopNHash method initialize.
public void initialize(int topN, float memUsage, boolean isMapGroupBy, BinaryCollector collector, final OperatorDesc conf, final Configuration hconf) {
assert topN >= 0 && memUsage > 0;
assert !this.isEnabled;
this.isEnabled = false;
this.topN = topN;
this.collector = collector;
if (topN == 0) {
isEnabled = true;
// topN == 0 will cause a short-circuit, don't need any initialization
return;
}
final boolean isTez = HiveConf.getVar(hconf, HiveConf.ConfVars.HIVE_EXECUTION_ENGINE).equals("tez");
final boolean isLlap = LlapDaemonInfo.INSTANCE.isLlap();
final int numExecutors = isLlap ? LlapDaemonInfo.INSTANCE.getNumExecutors() : 1;
// Used Memory = totalMemory() - freeMemory();
// Total Free Memory = maxMemory() - Used Memory;
long totalFreeMemory = Runtime.getRuntime().maxMemory() - Runtime.getRuntime().totalMemory() + Runtime.getRuntime().freeMemory();
if (isTez) {
MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
// TODO: For LLAP, assumption is off-heap cache.
final long memoryUsedPerExecutor = (memoryMXBean.getHeapMemoryUsage().getUsed() / numExecutors);
// this is total free memory available per executor in case of LLAP
totalFreeMemory = conf.getMaxMemoryAvailable() - memoryUsedPerExecutor;
}
// limit * 64 : compensation of arrays for key/value/hashcodes
this.threshold = (long) (memUsage * totalFreeMemory) - topN * 64L;
if (threshold < 0) {
return;
}
this.indexes = isMapGroupBy ? new HashForGroup() : new HashForRow();
this.keys = new byte[topN + 1][];
this.values = new byte[topN + 1][];
this.hashes = new int[topN + 1];
this.distKeyLengths = new int[topN + 1];
this.evicted = topN;
this.isEnabled = true;
}
use of java.lang.management.MemoryMXBean in project hive by apache.
the class TestVectorGroupByOperator method testMaxHTEntriesFlush.
@Test
public void testMaxHTEntriesFlush() throws HiveException {
List<String> mapColumnNames = new ArrayList<String>();
mapColumnNames.add("Key");
mapColumnNames.add("Value");
VectorizationContext ctx = new VectorizationContext("name", mapColumnNames);
Pair<GroupByDesc, VectorGroupByDesc> pair = buildKeyGroupByDesc(ctx, "max", "Value", TypeInfoFactory.longTypeInfo, new String[] { "Key" }, new TypeInfo[] { TypeInfoFactory.longTypeInfo });
GroupByDesc desc = pair.left;
VectorGroupByDesc vectorDesc = pair.right;
// Set the memory treshold so that we get 100Kb before we need to flush.
MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
long maxMemory = memoryMXBean.getHeapMemoryUsage().getMax();
// 1 MB should be able to store 1M/16bytes(key+data) = 62500 entries
float treshold = 10 * 100.0f * 1024.0f / maxMemory;
desc.setMemoryThreshold(treshold);
// Set really low MAXENTRIES setting
hconf.set("hive.vectorized.groupby.maxentries", "100");
CompilationOpContext cCtx = new CompilationOpContext();
Operator<? extends OperatorDesc> groupByOp = OperatorFactory.get(cCtx, desc);
VectorGroupByOperator vgo = (VectorGroupByOperator) Vectorizer.vectorizeGroupByOperator(groupByOp, ctx, vectorDesc);
FakeCaptureVectorToRowOutputOperator out = FakeCaptureVectorToRowOutputOperator.addCaptureOutputChild(cCtx, vgo);
vgo.initialize(hconf, null);
long expected = vgo.getMaxMemory();
assertEquals(expected, maxMemory);
this.outputRowCount = 0;
out.setOutputInspector(new FakeCaptureVectorToRowOutputOperator.OutputInspector() {
@Override
public void inspectRow(Object row, int tag) throws HiveException {
++outputRowCount;
}
});
Iterable<Object> it = new Iterable<Object>() {
@Override
public Iterator<Object> iterator() {
return new Iterator<Object>() {
long value = 0;
@Override
public boolean hasNext() {
return true;
}
@Override
public Object next() {
return ++value;
}
@Override
public void remove() {
}
};
}
};
FakeVectorRowBatchFromObjectIterables data = new FakeVectorRowBatchFromObjectIterables(100, new String[] { "long", "long" }, it, it);
// The 'it' data source will produce data w/o ever ending
// We want to see that VGBY entries are NOT flushed when reaching 100
// (misconfigured threshold) but when we reach about 30% of maxMemory
long countRowsProduced = 0;
for (VectorizedRowBatch unit : data) {
countRowsProduced += 100;
vgo.process(unit, 0);
if (0 < outputRowCount) {
break;
}
}
// Make sure that we did not flush at the low entry threshold
assertTrue(countRowsProduced > 100);
// Make sure we did not go above 30% of available memory
assertTrue(countRowsProduced < 0.3 * (1000 * 1024 / 16));
}
use of java.lang.management.MemoryMXBean in project springside4 by springside.
the class MetricExamples method gaugeExample.
@Test
public void gaugeExample() throws InterruptedException {
MetricRegistry metricRegistry = new MetricRegistry();
// 使用ConsoleReporter
ConsoleReporter consoleReporter = new ConsoleReporter();
final MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
Gauge<Long> usedMemoryGague = new Gauge<Long>() {
public Long getValue() {
return memoryMXBean.getHeapMemoryUsage().getUsed();
}
};
Gauge<Long> cachedUsedMemoryGague = new CachedGauge<Long>(10, TimeUnit.SECONDS) {
public Long loadValue() {
return memoryMXBean.getHeapMemoryUsage().getUsed();
}
};
metricRegistry.registerGauge(MetricRegistry.name("JVM", "usedMemory"), usedMemoryGague);
metricRegistry.registerGauge(MetricRegistry.name("JVM", "cachedUsedMemory"), cachedUsedMemoryGague);
ReportScheduler scheduler = new ReportScheduler(metricRegistry, consoleReporter);
scheduler.start(1, TimeUnit.SECONDS);
Thread.sleep(1050);
// use some memory
List<Integer> list = new ArrayList<Integer>(200000);
list.add(1);
Thread.sleep(1050);
scheduler.stop();
}
Aggregations