Search in sources :

Example 76 with MemoryMXBean

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();
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean) MemoryUsage(java.lang.management.MemoryUsage)

Example 77 with MemoryMXBean

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;
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean) LinkedHashMap(java.util.LinkedHashMap)

Example 78 with MemoryMXBean

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;
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean)

Example 79 with MemoryMXBean

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));
}
Also used : HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) ArrayList(java.util.ArrayList) MemoryMXBean(java.lang.management.MemoryMXBean) CompilationOpContext(org.apache.hadoop.hive.ql.CompilationOpContext) VectorGroupByDesc(org.apache.hadoop.hive.ql.plan.VectorGroupByDesc) Iterator(java.util.Iterator) FakeVectorRowBatchFromObjectIterables(org.apache.hadoop.hive.ql.exec.vector.util.FakeVectorRowBatchFromObjectIterables) FakeCaptureVectorToRowOutputOperator(org.apache.hadoop.hive.ql.exec.vector.util.FakeCaptureVectorToRowOutputOperator) VectorGroupByDesc(org.apache.hadoop.hive.ql.plan.VectorGroupByDesc) GroupByDesc(org.apache.hadoop.hive.ql.plan.GroupByDesc) Test(org.junit.Test)

Example 80 with MemoryMXBean

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();
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean) ConsoleReporter(org.springside.modules.metrics.reporter.ConsoleReporter) CachedGauge(org.springside.modules.metrics.metric.CachedGauge) ArrayList(java.util.ArrayList) Gauge(org.springside.modules.metrics.metric.Gauge) CachedGauge(org.springside.modules.metrics.metric.CachedGauge) Test(org.junit.Test)

Aggregations

MemoryMXBean (java.lang.management.MemoryMXBean)84 MemoryUsage (java.lang.management.MemoryUsage)30 RuntimeMXBean (java.lang.management.RuntimeMXBean)18 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)12 IOException (java.io.IOException)11 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)11 ThreadMXBean (java.lang.management.ThreadMXBean)11 NotificationEmitter (javax.management.NotificationEmitter)10 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)9 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 Map (java.util.Map)7 Test (org.junit.Test)7 Test (org.testng.annotations.Test)7 ObjectName (javax.management.ObjectName)6 ClassLoadingMXBean (java.lang.management.ClassLoadingMXBean)5 Properties (java.util.Properties)5 MalformedObjectNameException (javax.management.MalformedObjectNameException)5 Notification (javax.management.Notification)5 MemoryMXBeanImpl (com.ibm.java.lang.management.internal.MemoryMXBeanImpl)4