Search in sources :

Example 66 with MemoryUsage

use of java.lang.management.MemoryUsage in project jdk8u_jdk by JetBrains.

the class MemoryPoolImpl method setUsageThreshold.

public void setUsageThreshold(long newThreshold) {
    if (!isUsageThresholdSupported()) {
        throw new UnsupportedOperationException("Usage threshold is not supported");
    }
    Util.checkControlAccess();
    MemoryUsage usage = getUsage0();
    if (newThreshold < 0) {
        throw new IllegalArgumentException("Invalid threshold: " + newThreshold);
    }
    if (usage.getMax() != -1 && newThreshold > usage.getMax()) {
        throw new IllegalArgumentException("Invalid threshold: " + newThreshold + " must be <= maxSize." + " Committed = " + usage.getCommitted() + " Max = " + usage.getMax());
    }
    synchronized (this) {
        if (!usageSensorRegistered) {
            // pass the sensor to VM to begin monitoring
            usageSensorRegistered = true;
            setPoolUsageSensor(usageSensor);
        }
        setUsageThreshold0(usageThreshold, newThreshold);
        this.usageThreshold = newThreshold;
    }
}
Also used : MemoryUsage(java.lang.management.MemoryUsage)

Example 67 with MemoryUsage

use of java.lang.management.MemoryUsage in project voltdb by VoltDB.

the class GCInspector method logGCResults.

private void logGCResults() {
    for (GarbageCollectorMXBean gc : beans) {
        Long previousTotal = gctimes.get(gc.getName());
        Long total = gc.getCollectionTime();
        if (previousTotal == null)
            previousTotal = 0L;
        if (previousTotal.equals(total))
            continue;
        gctimes.put(gc.getName(), total);
        // may be zero for a really fast collection
        Long duration = total - previousTotal;
        Long previousCount = gccounts.get(gc.getName());
        Long count = gc.getCollectionCount();
        if (previousCount == null)
            previousCount = 0L;
        if (count.equals(previousCount))
            continue;
        gccounts.put(gc.getName(), count);
        MemoryUsage mu = membean.getHeapMemoryUsage();
        long memoryUsed = mu.getUsed();
        long memoryMax = mu.getMax();
        long durationPerCollection = duration / (count - previousCount);
        if (durationPerCollection > MIN_DURATION) {
            String st = String.format("GC for %s: %s ms for %s collections, %s used; max is %s", gc.getName(), duration, count - previousCount, memoryUsed, memoryMax);
            logger.info(st);
        } else if (logger.isDebugEnabled()) {
            String st = String.format("GC for %s: %s ms for %s collections, %s used; max is %s", gc.getName(), duration, count - previousCount, memoryUsed, memoryMax);
            logger.debug(st);
        }
        // if we just finished a full collection and we're still using a lot of memory, log
        if (newGenGCs.contains(gc.getName())) {
            m_voltGcStats.gcInspectorReport(true, (int) (count - previousCount), duration);
        }
        if (oldGenGCs.contains(gc.getName())) {
            m_voltGcStats.gcInspectorReport(false, (int) (count - previousCount), duration);
            if (memoryUsed > .5 * memoryMax) {
                double usage = (double) memoryUsed / memoryMax;
                String usageStr = String.format("%.2f", usage * 100);
                //2^20 Bytes
                String memoryMaxStr = String.format("%.2f", (double) memoryMax / 1_048_576);
                if (.5 <= usage && usage < .6) {
                    logger.info("Heap is " + usageStr + "% full out of " + memoryMaxStr + "MB.");
                } else if (.6 <= usage) {
                    logger.warn("Heap is " + usageStr + "% full out of " + memoryMaxStr + "MB.");
                }
            }
        }
    }
}
Also used : GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean) MemoryUsage(java.lang.management.MemoryUsage)

Example 68 with MemoryUsage

use of java.lang.management.MemoryUsage in project hive by apache.

the class JvmMetrics method getMemoryUsage.

private void getMemoryUsage(MetricsRecordBuilder rb) {
    MemoryUsage memNonHeap = memoryMXBean.getNonHeapMemoryUsage();
    MemoryUsage memHeap = memoryMXBean.getHeapMemoryUsage();
    Runtime runtime = Runtime.getRuntime();
    rb.addGauge(MemNonHeapUsedM, memNonHeap.getUsed() / M).addGauge(MemNonHeapCommittedM, memNonHeap.getCommitted() / M).addGauge(MemNonHeapMaxM, memNonHeap.getMax() / M).addGauge(MemHeapUsedM, memHeap.getUsed() / M).addGauge(MemHeapCommittedM, memHeap.getCommitted() / M).addGauge(MemHeapMaxM, memHeap.getMax() / M).addGauge(MemMaxM, runtime.maxMemory() / M);
}
Also used : MemoryUsage(java.lang.management.MemoryUsage)

Example 69 with MemoryUsage

use of java.lang.management.MemoryUsage in project ignite by apache.

the class GridManagerMxBeanIllegalArgumentHandleTest method createAlwaysFailingMxBean.

/**
 * MX bean which is always failing to respond with metrics
 */
@NotNull
private MemoryMXBean createAlwaysFailingMxBean() {
    final Answer<MemoryUsage> failingAnswer = new Answer<MemoryUsage>() {

        @Override
        public MemoryUsage answer(InvocationOnMock invocationOnMock) throws Throwable {
            throw new IllegalArgumentException("java.lang.IllegalArgumentException: committed = 5274103808 should be < max = 5274095616");
        }
    };
    final MemoryMXBean memoryMXBean = Mockito.mock(MemoryMXBean.class);
    when(memoryMXBean.getHeapMemoryUsage()).thenAnswer(failingAnswer);
    when(memoryMXBean.getNonHeapMemoryUsage()).thenAnswer(failingAnswer);
    return memoryMXBean;
}
Also used : Answer(org.mockito.stubbing.Answer) MemoryMXBean(java.lang.management.MemoryMXBean) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MemoryUsage(java.lang.management.MemoryUsage) NotNull(org.jetbrains.annotations.NotNull)

Example 70 with MemoryUsage

use of java.lang.management.MemoryUsage in project ignite by apache.

the class GridCapacityLoadTest method main.

/**
 * Main method.
 *
 * @param args Parameters.
 * @throws Exception If failed.
 */
public static void main(String[] args) throws Exception {
    // Initialize Spring factory.
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("org/apache/ignite/loadtests/capacity/spring-capacity-cache.xml");
    IgniteConfiguration cfg = (IgniteConfiguration) ctx.getBean("grid.cfg");
    try (Ignite g = G.start(cfg)) {
        IgniteCache<Integer, Integer> c = g.cache("test-cache");
        long init = mem.getHeapMemoryUsage().getUsed();
        printHeap(init);
        int cnt = 0;
        for (; cnt < 3000000; cnt++) {
            c.put(cnt, cnt);
            if (cnt % 10000 == 0) {
                X.println("Stored count: " + cnt);
                printHeap(init);
                if (cnt > 2100000 && cnt % 100000 == 0)
                    System.gc();
            }
        }
        System.gc();
        Thread.sleep(1000);
        printHeap(init);
        MemoryUsage heap = mem.getHeapMemoryUsage();
        long used = heap.getUsed() - init;
        long entrySize = cnt > 0 ? used / cnt : 0;
        X.println("Average entry size: " + entrySize);
    }
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Ignite(org.apache.ignite.Ignite) MemoryUsage(java.lang.management.MemoryUsage)

Aggregations

MemoryUsage (java.lang.management.MemoryUsage)75 MemoryMXBean (java.lang.management.MemoryMXBean)15 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)15 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)6 RuntimeMXBean (java.lang.management.RuntimeMXBean)6 HashMap (java.util.HashMap)6 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)5 ThreadMXBean (java.lang.management.ThreadMXBean)4 Map (java.util.Map)4 IOException (java.io.IOException)3 MemoryType (java.lang.management.MemoryType)3 ArrayList (java.util.ArrayList)3 NotNull (org.jetbrains.annotations.NotNull)3 ApplicationInfo (com.intellij.openapi.application.ApplicationInfo)2 GarbageCollectionNotificationInfo (com.sun.management.GarbageCollectionNotificationInfo)2 File (java.io.File)2 BufferPoolMXBean (java.lang.management.BufferPoolMXBean)2 ClassLoadingMXBean (java.lang.management.ClassLoadingMXBean)2 Date (java.util.Date)2 Properties (java.util.Properties)2