我已经使用Quarkus做了一些服务,想自己探索一些性能差异。在这里,我遇到了一个问题,即容器上的内存使用情况 docker 和 kubernetes 报告远低于 smallrye 指标或通过容器内 top 等命令报告的内存使用情况。 我现在想收集有关服务中内存的更多详细信息,以便进行尽可能准确的比较,但是我不知道如何获得更详细的信息。
GraalVM 也提供了工具,如 visualVM,但它似乎只能在映像本机运行(而不是在 docker 容器中(时工作。来自Smallrye的指标没有提供我想看到的细节,并且像NativeMemoryTracking这样的东西不可用(据我所知(。
还有什么我可以探索的或我缺少的信息吗?
我使用以下内容,
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();
}
}