0

我已经使用 Quarkus 做了一些服务,并且想自己探索一些性能差异。在这里,我遇到了一个问题,docker 和 kubernetes 报告的容器上的内存使用情况远低于 smallrye 指标或通过容器内的 top 等命令报告的内存使用情况。我现在想收集有关服务中内存的更多详细信息,以进行尽可能准确的比较,但是我不知道如何获得更详细的信息。

GraalVM 也提供了一些工具,比如 visualVM,但它似乎只能在图像本地运行(而不是在 docker 容器中)时才能工作。Smallrye 的指标没有提供我希望看到的详细信息,并且 NativeMemoryTracking 之类的东西不可用(据我所知)。

还有什么我可以探索的或我缺少的信息吗?

4

1 回答 1

0

我使用以下,

docker stats <containerId>

或者

docker stats $(docker ps -q)

查看整个容器的内存使用情况。

我使用指标或:

ps -o "pid,rss,command" <pid> 

从命令行查看内存使用情况。

或者只是编写您自己的指标“健康检查”:

    @Liveness                                                                                                                                              
    @ApplicationScoped                                                                                                                                               
    public class InfoCheck implements HealthCheck {                                                                                             


    private final DecimalFormat nf = new DecimalFormat("###,### MB", new 
    DecimalFormatSymbols(new Locale("nl")));


    @ConfigProperty(name = "quarkus.application.name")                                                                                                                                                   
    String appName;


    @ConfigProperty(name = "app.version")                                                                                                                                                   
    String version;                                               


    @Override                                                                                                                                                                                               
    public HealthCheckResponse call() {                                                                                                            
        nf.setGroupingUsed(true);                                                                                                                                                               
        nf.setParseIntegerOnly(true);                                                                                                                                                                                                                   

        Runtime runtime = Runtime.getRuntime();                                
        long totalMemory = runtime.totalMemory();                                                                                                                                                       
        long freeMemory = runtime.freeMemory();                                                                                                                                                       
        long maxMemory = runtime.maxMemory();                                                                                                                                                                                                                                                                  

        return HealthCheckResponse.named(this.appName)                                                                                                                                                               
                .up()                                                                                                                                                               
                .withData("application.version", this.version)                                                                                                                                                            
                .withData("cpu.amount", runtime.availableProcessors())                                                                                                                                                              
                .withData("memory.free", nf.format(freeMemory / (1024 * 1024)))                                                                                                                                                               
                .withData("memory.allocated", nf.format(totalMemory / (1024 * 1024)))                                                                                                                                                              
                .withData("memory.total.free", nf.format((freeMemory + (maxMemory - totalMemory)) / (1024 * 1024)))

                .build();                                                       

        }                                                                                

    } 
于 2020-05-27T17:12:52.163 回答