Example usage for java.lang.management ManagementFactory getMemoryMXBean

List of usage examples for java.lang.management ManagementFactory getMemoryMXBean

Introduction

In this page you can find the example usage for java.lang.management ManagementFactory getMemoryMXBean.

Prototype

public static MemoryMXBean getMemoryMXBean() 

Source Link

Document

Returns the managed bean for the memory system of the Java virtual machine.

Usage

From source file:org.apache.hadoop.hive.ql.io.orc.MemoryManager.java

/**
 * Create the memory manager.//from  ww w. j  a v  a2  s.  co m
 * @param conf use the configuration to find the maximum size of the memory
 *             pool.
 */
MemoryManager(Configuration conf) {
    double maxLoad = OrcConf.MEMORY_POOL.getDouble(conf);
    totalMemoryPool = Math.round(ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax() * maxLoad);
    ownerLock.lock();
}

From source file:org.apache.hadoop.hive.ql.io.orc.WriterImpl.java

private long getMemoryAvailableForORC() {
    double maxLoad = OrcConf.MEMORY_POOL.getDouble(conf);
    long totalMemoryPool = Math
            .round(ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax() * maxLoad);
    return totalMemoryPool;
}

From source file:org.apache.hadoop.metrics.jvm.JvmMetrics.java

private void doMemoryUpdates() {
    MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
    MemoryUsage memNonHeap = memoryMXBean.getNonHeapMemoryUsage();
    MemoryUsage memHeap = memoryMXBean.getHeapMemoryUsage();
    Runtime runtime = Runtime.getRuntime();

    metrics.setMetric("memNonHeapUsedM", memNonHeap.getUsed() / M);
    metrics.setMetric("memNonHeapCommittedM", memNonHeap.getCommitted() / M);
    metrics.setMetric("memHeapUsedM", memHeap.getUsed() / M);
    metrics.setMetric("memHeapCommittedM", memHeap.getCommitted() / M);
    metrics.setMetric("maxMemoryM", runtime.maxMemory() / M);
}

From source file:org.apache.hyracks.control.nc.NodeControllerService.java

public NodeControllerService(NCConfig ncConfig) throws Exception {
    this.ncConfig = ncConfig;
    id = ncConfig.nodeId;/*  w  ww. j  a v a  2 s .  co  m*/
    ipc = new IPCSystem(new InetSocketAddress(ncConfig.clusterNetIPAddress, ncConfig.clusterNetPort),
            new NodeControllerIPCI(this), new CCNCFunctions.SerializerDeserializer());

    ioManager = new IOManager(getDevices(ncConfig.ioDevices));
    if (id == null) {
        throw new Exception("id not set");
    }
    partitionManager = new PartitionManager(this);
    netManager = new NetworkManager(ncConfig.dataIPAddress, ncConfig.dataPort, partitionManager,
            ncConfig.nNetThreads, ncConfig.nNetBuffers, ncConfig.dataPublicIPAddress, ncConfig.dataPublicPort,
            FullFrameChannelInterfaceFactory.INSTANCE);

    lccm = new LifeCycleComponentManager();
    workQueue = new WorkQueue(id, Thread.NORM_PRIORITY); // Reserves MAX_PRIORITY of the heartbeat thread.
    jobletMap = new Hashtable<>();
    timer = new Timer(true);
    serverCtx = new ServerContext(ServerContext.ServerType.NODE_CONTROLLER,
            new File(new File(NodeControllerService.class.getName()), id));
    memoryMXBean = ManagementFactory.getMemoryMXBean();
    gcMXBeans = ManagementFactory.getGarbageCollectorMXBeans();
    threadMXBean = ManagementFactory.getThreadMXBean();
    runtimeMXBean = ManagementFactory.getRuntimeMXBean();
    osMXBean = ManagementFactory.getOperatingSystemMXBean();
    registrationPending = true;
    getNodeControllerInfosAcceptor = new MutableObject<>();
    memoryManager = new MemoryManager(
            (long) (memoryMXBean.getHeapMemoryUsage().getMax() * MEMORY_FUDGE_FACTOR));
    ioCounter = new IOCounterFactory().getIOCounter();
}

From source file:org.apache.jxtadoop.metrics.jvm.JvmMetrics.java

private void doMemoryUpdates() {
    MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
    MemoryUsage memNonHeap = memoryMXBean.getNonHeapMemoryUsage();
    MemoryUsage memHeap = memoryMXBean.getHeapMemoryUsage();
    metrics.setMetric("memNonHeapUsedM", memNonHeap.getUsed() / M);
    metrics.setMetric("memNonHeapCommittedM", memNonHeap.getCommitted() / M);
    metrics.setMetric("memHeapUsedM", memHeap.getUsed() / M);
    metrics.setMetric("memHeapCommittedM", memHeap.getCommitted() / M);
}

From source file:org.apache.parquet.hadoop.TestMemoryManager.java

@Before
public void setUp() {
    GroupWriteSupport.setSchema(MessageTypeParser.parseMessageType(writeSchema), conf);
    expectPoolSize = Math.round(ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax()
            * MemoryManager.DEFAULT_MEMORY_POOL_RATIO);
    rowGroupSize = (int) Math.floor(expectPoolSize / 2);
    conf.setInt(ParquetOutputFormat.BLOCK_SIZE, rowGroupSize);
    codec = CompressionCodecName.UNCOMPRESSED;
}

From source file:org.apache.pig.impl.util.SpillableMemoryManager.java

private SpillableMemoryManager() {
    ((NotificationEmitter) ManagementFactory.getMemoryMXBean()).addNotificationListener(this, null, null);
    List<MemoryPoolMXBean> mpbeans = ManagementFactory.getMemoryPoolMXBeans();
    long totalSize = 0;
    for (MemoryPoolMXBean pool : mpbeans) {
        log.debug("Found heap (" + pool.getName() + ") of type " + pool.getType());
        if (pool.getType() == MemoryType.HEAP) {
            long size = pool.getUsage().getMax();
            totalSize += size;// w w w .ja va 2s  . c  o m
            // CMS Old Gen or "tenured" is the only heap that supports
            // setting usage threshold.
            if (pool.isUsageThresholdSupported()) {
                tenuredHeap = pool;
            }
        }
    }
    extraGCSpillSizeThreshold = (long) (totalSize * extraGCThresholdFraction);
    if (tenuredHeap == null) {
        throw new RuntimeException("Couldn't find heap");
    }

    configureMemoryThresholds(MEMORY_THRESHOLD_FRACTION_DEFAULT, COLLECTION_THRESHOLD_FRACTION_DEFAULT,
            UNUSED_MEMORY_THRESHOLD_DEFAULT);

}

From source file:org.apache.tajo.storage.thirdparty.orc.MemoryManager.java

/**
 * Create the memory manager./*w w  w.j  a v a 2 s .  c  o  m*/
 * @param conf use the configuration to find the maximum size of the memory
 *             pool.
 */
MemoryManager(Configuration conf) {
    HiveConf.ConfVars poolVar = HiveConf.ConfVars.HIVE_ORC_FILE_MEMORY_POOL;
    double maxLoad = conf.getFloat(poolVar.varname, poolVar.defaultFloatVal);
    totalMemoryPool = Math.round(ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax() * maxLoad);
    ownerLock.lock();
}

From source file:org.apache.tajo.storage.thirdparty.orc.WriterImpl.java

private long getMemoryAvailableForORC() {
    OrcConf.ConfVars poolVar = OrcConf.ConfVars.HIVE_ORC_FILE_MEMORY_POOL;
    double maxLoad = conf.getFloat(poolVar.varname, poolVar.defaultFloatVal);
    long totalMemoryPool = Math
            .round(ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax() * maxLoad);
    return totalMemoryPool;
}

From source file:org.artifactory.webapp.wicket.page.config.advanced.SystemInfoPage.java

/**
 * Return a formatted string of the system info to display
 *
 * @return// www  .ja  v  a 2s  . c o  m
 */
private String collectSystemInfo() {
    StringBuilder infoBuilder = new StringBuilder();

    StorageProperties storageProperties = ContextHelper.get().beanForType(StorageProperties.class);
    infoBuilder.append("Storage Info:").append("\n");
    addInfo(infoBuilder, "Database Type", storageProperties.getDbType().toString());
    BinaryProviderType binariesStorageType = storageProperties.getBinariesStorageType();
    addInfo(infoBuilder, "Storage Type", binariesStorageType.toString());
    if (BinaryProviderType.S3 == binariesStorageType) {
        // S3 properties
        addInfo(infoBuilder, "s3.bucket.name", storageProperties.getS3BucketName());
        addInfo(infoBuilder, "s3.bucket.path", storageProperties.getS3BucketPath());
        addInfo(infoBuilder, "s3.endpoint", storageProperties.getS3Entpoint());
        // Retry properties
        addInfo(infoBuilder, "retry.max.retries.number",
                Integer.toString(storageProperties.getMaxRetriesNumber()));
        addInfo(infoBuilder, "retry.delay.between.retries",
                Integer.toString(storageProperties.getDelayBetweenRetries()));
        // Eventually persisted properties
        addInfo(infoBuilder, "eventually.persisted.max.number.of.threads",
                Integer.toString(storageProperties.getEventuallyPersistedMaxNumberOfThread()));
        addInfo(infoBuilder, "eventually.persisted.timeout",
                Integer.toString(storageProperties.getEventuallyPersistedTimeOut()));
        addInfo(infoBuilder, "eventually.dispatcher.sleep.time",
                Long.toString(storageProperties.getEventuallyPersistedDispatcherSleepTime()));
    }

    infoBuilder.append("\n").append("System Properties:").append("\n");
    Properties properties = System.getProperties();
    //// add Artifactory version to the properties, will be alphabetically sorted later.
    properties.setProperty(ConstantValues.artifactoryVersion.getPropertyName(),
            ConstantValues.artifactoryVersion.getString());
    AddonsManager addonsManager = ContextHelper.get().beanForType(AddonsManager.class);
    addInfo(infoBuilder, "artifactory.running.mode", addonsManager.getArtifactoryRunningMode().name());
    addInfo(infoBuilder, "artifactory.running.state", ContextHelper.get().isOffline() ? "Offline" : "Online");
    addFromProperties(infoBuilder, properties);
    addHaProperties(infoBuilder);
    infoBuilder.append("\n").append("General JVM Info:").append("\n");
    OperatingSystemMXBean systemBean = ManagementFactory.getOperatingSystemMXBean();
    addInfo(infoBuilder, "Available Processors", Integer.toString(systemBean.getAvailableProcessors()));

    MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
    MemoryUsage heapMemoryUsage = memoryBean.getHeapMemoryUsage();

    addInfo(infoBuilder, "Heap Memory Usage-Committed", Long.toString(heapMemoryUsage.getCommitted()));
    addInfo(infoBuilder, "Heap Memory Usage-Init", Long.toString(heapMemoryUsage.getInit()));
    addInfo(infoBuilder, "Heap Memory Usage-Max", Long.toString(heapMemoryUsage.getMax()));
    addInfo(infoBuilder, "Heap Memory Usage-Used", Long.toString(heapMemoryUsage.getUsed()));

    MemoryUsage nonHeapMemoryUsage = memoryBean.getNonHeapMemoryUsage();
    addInfo(infoBuilder, "Non-Heap Memory Usage-Committed", Long.toString(nonHeapMemoryUsage.getCommitted()));
    addInfo(infoBuilder, "Non-Heap Memory Usage-Init", Long.toString(nonHeapMemoryUsage.getInit()));
    addInfo(infoBuilder, "Non-Heap Memory Usage-Max", Long.toString(nonHeapMemoryUsage.getMax()));
    addInfo(infoBuilder, "Non-Heap Memory Usage-Used", Long.toString(nonHeapMemoryUsage.getUsed()));

    RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean();
    StringBuilder vmArgumentBuilder = new StringBuilder();
    List<String> vmArguments = RuntimemxBean.getInputArguments();
    if (vmArguments != null) {
        for (String vmArgument : vmArguments) {
            if (InfoWriter.shouldMaskValue(vmArgument)) {
                vmArgument = Strings.maskKeyValue(vmArgument);
            }
            vmArgumentBuilder.append(vmArgument);
            if (vmArguments.indexOf(vmArgument) != (vmArguments.size() - 1)) {
                vmArgumentBuilder.append("\n");
            }
        }
    }

    infoBuilder.append("\nJVM Arguments:\n").append(vmArgumentBuilder.toString());

    return StringUtils.removeEnd(infoBuilder.toString(), "\n");
}