繁体   English   中英

Google App 引擎标准环境中的 Java 堆转储?

[英]Java heap dump in Google App engine standard environment?

我有一个在 Google App Engine 标准环境上运行的 Java 应用程序,我想通过堆转储来分析内存使用情况。

是否有任何工具可以帮助完成这项任务?

我知道HotSpotDiagnosticMXBean可以做到这一点,但它会将文件写入我在应用引擎上无权访问的本地文件系统。 有没有办法将转储流式传输到云存储?

目前无法在 App Engine Standard 上获得堆转储,但 App Engine 团队目前正在调查此功能请求

请注意,此请求没有 ETA。 更新将发布在问题跟踪器链接上。

现在可以使用 Appengine Standard 写入临时文件: https://cloud.google.com/appengine/docs/standard/java11/using-temp-files ,使您能够以编程方式创建堆转储并保存到本地文件。 例如,获得文件后,您可以将其发送到 Google Cloud Storage,然后从那里对其进行分析。 您可以使用您提到的HotSpotDiagnosticMXBean 这是一个代码片段:

final MemoryMXBean memory = ManagementFactory.getMemoryMXBean();
if (memory.getHeapMemoryUsage().getUsed() > 48 * MB) {
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    final HotSpotDiagnosticMXBean mxBean = ManagementFactory.newPlatformMXBeanProxy(server, "com.sun.management:type=HotSpotDiagnostic", HotSpotDiagnosticMXBean.class);

    final String fileName = "/tmp/heap.hprof";

    mxBean.dumpHeap(fileName, true);

    final GcsFilename objectId = new GcsFilename("my_bucket", "heap-dump.hprof");
    final GcsOutputChannel output = gcs.createOrReplace(objectId, options);

    try (final InputStream is = new FileInputStream(fileName);
         final OutputStream os = Channels.newOutputStream(output)) {
        final byte[] buffer = new byte[65536];

        for (int read; (read = is.read(buffer)) > -1; ) {
            os.write(buffer, 0, read);
        }
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM