限制Java进程的总内存消耗(在Cloud Foundry中) [英] Limit total memory consumption of Java process (in Cloud Foundry)

查看:366
本文介绍了限制Java进程的总内存消耗(在Cloud Foundry中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与这两个问题相关:

  • How to set the maximum memory usage for JVM?
  • What would cause a java process to greatly exceed the Xmx or Xss limit?

我在Cloud Foundry上运行Java应用程序,需要确保分配的内存是没有超过。否则,这是当前的问题,该过程被Cloud Foundry监视机制(Linux CGROUP)终止。

I run a Java application on Cloud Foundry and need to make sure that the allocated memory is not exceeded. Otherwise, and this is the current issue, the process is killed by Cloud Foundry monitoring mechanisms (Linux CGROUP).

Java Buildpack自动设置<$ c $的合理值c> -Xmx 和 -Xss 。通过调整参数并配置(最大)预期线程数,我非常确定Java进程消耗的内存应该小于我分配给Cloud Foundry应用程序的上限。

The Java Buildpack automatically sets sane values for -Xmx and -Xss. By tuning the arguments and configuring the (maximum) number of expected threads, I'm pretty sure that the memory consumed by the Java process should be less than the upper limit which I assigned to my Cloud Foundry application.

但是,我仍然遇到Cloud Foundry内存不足错误( NOT Java OOM错误!):
index: 3,原因:CRASHED,exit_description:内存不足,exit_status:255

However, I still experience Cloud Foundry "out of memory" errors (NOT the Java OOM error!): index: 3, reason: CRASHED, exit_description: out of memory, exit_status: 255

我试验了 MALLOC_ARENA_MAX 设置。将值设置为1或2会导致启动缓慢。使用 MALLOC_ARENA_MAX = 4 我仍然看到如上所述的错误,所以这不是我的问题的解决方案。

I experimented with the MALLOC_ARENA_MAX setting. Setting the value to 1 or 2 leads to slow startups. With MALLOC_ARENA_MAX=4 I still saw an error as described above, so this is no solution for my problem.

目前我使用非常紧凑的内存设置进行测试,以便更容易重现问题。但是,即使这样,我也要等待大约20-25分钟才能发生错误。

Currently I test with very tight memory settings so that the problem is easier to reproduce. However, even with this, I have to wait about 20-25 minutes for the error to occur.

我需要指定哪些参数和/或环境变量来确保我的Java进程从不超过了某个内存限制?如果应用程序实际需要更多内存,则可以使用Java OOM错误。

Which arguments and/or environment variables do I have to specify to ensure that my Java process never exceeds a certain memory limit? Crashing with a Java OOM Error is acceptable if the application actually needs more memory.

有关 MALLOC_ARENA_MAX 的更多信息:

  • https://github.com/cloudfoundry/java-buildpack/pull/160
  • https://www.infobright.com/index.php/malloc_arena_max/#.VmgdprgrJaQ
  • https://www.ibm.com/developerworks/community/blogs/kevgrig/entry/linux_glibc_2_10_rhel_6_malloc_may_show_excessive_virtual_memory_usage?lang=en

编辑:可能的解释如下: http://www.evanjones.ca/java-bytebuffer-leak.html 。正如我目前在执行大量传出的HTTP / REST请求时看到OOM问题,这些缓冲区可能是罪魁祸首。

A possible explaination is this: http://www.evanjones.ca/java-bytebuffer-leak.html. As I currently see the OOM issue when doing lots of outgoing HTTP/REST requests, these buffers might be to blame.

推荐答案

不幸的是,没有办法明确地对JVM强制执行内存限制。大多数内存区域是可配置的( -Xmx -Xss -XX:MaxPermSize -XX:MaxMetaspaceSize 等)但你无法控制的是本机内存。本机内存包含从内存映射文件到本机库到JNI代码的大量内容。您可以做的最好的事情是分析您的应用程序,找出内存增长的位置,并解决增长或为自己留下足够的喘息空间。

Unfortunately, there is no way to definitively enforce a memory limit on the JVM. Most of the memory regions are configurable (-Xmx, -Xss, -XX:MaxPermSize, -XX: MaxMetaspaceSize, etc.) but the one you can't control is Native memory. Native memory contains a whole host of things from memory mapped files to native libraries to JNI code. The best you can do is profile your application, find out where the memory growth is occurring, and either solve the growth or give yourself enough breathing room to survive.

当然不满意,但最终与没有控制其内存占用的其他语言和运行时没有太大区别。

Certainly unsatisfying, but in the end not much different from other languages and runtimes that have no control over their memory footprint.

这篇关于限制Java进程的总内存消耗(在Cloud Foundry中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆