Amazon EC2 t2.micro 实例上的 Jar 运行 内存不足

Jar running on Amazon EC2 t2.micro instance runs out of memory

我是 运行 来自 Java jar 的亚马逊实例上的一些网络应用程序,但它总是在 12 小时左右后耗尽内存。这是写入文件的错误消息:

There is insufficient memory for the Java Runtime Environment to continue.
Native memory allocation (malloc) failed to allocate 12288 bytes for                              
committing reserved memory.
Possible reasons:
 The system is out of physical RAM or swap space
 In 32 bit mode, the process size limit was hit
Possible solutions:
 Reduce memory load on the system
 Increase physical memory or swap space
 Check if swap backi ng store is full
 Use 64 bit Java on a 64 bit OS
 Decrease Java heap size (-Xmx/-Xms)
 Decrease number of Java threads
 Decrease Java thread stack sizes (-Xss)
 Set larger code cache with -XX:ReservedCodeCacheSize=
 This output file may be truncated or incomplete.

Out of Memory Error (os_linux.cpp:2827), pid=5808, tid=140367928600320

JRE version: OpenJDK Runtime Environment (7.0_95) (build 1.7.0_95-b00)
Java VM: OpenJDK 64-Bit Server VM (24.95-b01 mixed mode linux-amd64 compressed oops)
Derivative: IcedTea 2.6.4
Distribution: Ubuntu 14.04.3 LTS, package 7u95-2.6.4-0ubuntu0.14.04.1
Failed to write core dump. Core dumps have been disabled. 
To enable core dumping, try "ulimit -c unlimited" before starting Java again

我该如何从这里开始?遵循他们的建议(例如增加堆大小或交换 space 是否有意义,或者我真的只需要将我的 EC2 实例升级到更大的大小?

您需要通过 -Xmx 选项增加最大 JVM 堆大小设置,以允许 JVM 使用更多内存。如果您需要将其增加到超出 t2.micro 实例的物理可用容量,那么您还需要增加 EC2 实例的大小。

请记住,您无法将 t2.micro 实例上的全部 1GB 内存分配给您的 Java 应用程序,因为其中一些内存将被操作系统使用.此外,您还需要尽可能避免使用交换 space,因此请集中精力配置 JVM 以利用 EC2 实例上可用的 RAM。

不知道您当前的 JVM 设置是什么,很难给出更准确的建议。

问题是您 运行 虚拟内存或实际地址 space。

这意味着您应该

  • 增加隔夜利息space
  • 减少 堆大小

您需要减小堆大小的原因是为 JVM 和系统的其余部分留出更多内存