当前位置: 首页>>代码示例>>Java>>正文


Java App.getMem方法代码示例

本文整理汇总了Java中mesosphere.marathon.client.model.v2.App.getMem方法的典型用法代码示例。如果您正苦于以下问题:Java App.getMem方法的具体用法?Java App.getMem怎么用?Java App.getMem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mesosphere.marathon.client.model.v2.App的用法示例。


在下文中一共展示了App.getMem方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: scale

import mesosphere.marathon.client.model.v2.App; //导入方法依赖的package包/类
@Override
public void scale(App app, AppStatistics statistics)
{
    // current cpu greater 90 percent
    if (statistics.getCpu().orElse(0F) > 0.9) {
        app.setCpus(app.getCpus() * 1.5);
        logger.info(
            "scaling app {} to {} cpus due to cpu usage ({})",
            app.getId(),
            app.getCpus(),
            statistics.getCpu().get() * 100
        );
    }

    // current memory consumption is greater than 90 percent of max
    if (statistics.getMemoryInMegabytes() > app.getMem() * 0.9) {
        Double oldMem = app.getMem();
        app.setMem(oldMem * 1.5);
        logger.info(
            "scaling app {} to {} Memory due to memory usage ({} MB/{} MB)",
            app.getId(),
            app.getMem(),
            statistics.getMemoryInMegabytes(),
            oldMem
        );
    }
}
 
开发者ID:Marmelatze,项目名称:docker-controller,代码行数:28,代码来源:Vertical.java

示例2: scale

import mesosphere.marathon.client.model.v2.App; //导入方法依赖的package包/类
@Override
public void scale(App app, AppStatistics statistics)
{
    Map<String, String> labels = app.getLabels();
    int maxInstances = app.getInstances();
    if (labels.containsKey(LABEL_MAX_INSTANCES)) {
        maxInstances = Integer.parseInt(labels.get(LABEL_MAX_INSTANCES));
    }
    int minInstances = app.getInstances();
    if (labels.containsKey(LABEL_MIN_INSTANCES)) {
        minInstances = Integer.parseInt(labels.get(LABEL_MIN_INSTANCES));
    }
    if (app.getInstances() == 0) {
        return;
    }

    float cpuAverage = statistics.getCpu().orElse(0F) / app.getInstances();
    float memoryAverage = statistics.getMemoryInMegabytes() / app.getInstances();

    // scaling up
    if (app.getInstances() < maxInstances) {
        if (cpuAverage > 0.9) {
            app.setInstances(app.getInstances() + 1);
            logger.info(
                "scaling app '{}' up to {} instances due to cpu usage ({}%)",
                app.getId(),
                app.getInstances(),
                cpuAverage * 100
            );

            return;
        }

        if (memoryAverage > app.getMem() * 0.9) {
            app.setInstances(app.getInstances() + 1);
            logger.info(
                "scaling app '{}' up to {} instances due to memory usage ({} MB/{} MB)",
                app.getId(),
                app.getInstances(),
                memoryAverage,
                app.getMem()
            );

            return;
        }
    }


    // scaling down
    if (app.getInstances() > minInstances) {
        // check for presence to avoid scaling down, when no value exists
        if (statistics.getCpu().isPresent() && cpuAverage < 0.1
            && statistics.getMemory().isPresent() && memoryAverage < app.getMem() * 0.5) {
            app.setInstances(app.getInstances() - 1);
            logger.info(
                "scaling app '{}' down to {} instances due to low resource usage (CPU {}%, Memory: {}/{} MB)",
                app.getId(),
                app.getInstances(),
                cpuAverage * 100,
                memoryAverage,
                app.getMem()
            );
        }
    }
}
 
开发者ID:Marmelatze,项目名称:docker-controller,代码行数:66,代码来源:Horizontal.java


注:本文中的mesosphere.marathon.client.model.v2.App.getMem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。