2016-02-29 112 views
0

我正在Java jar上运行Amazon实例上的某个Web应用程序,但它在12小时左右后总是耗尽内存。以下是写入文件的错误消息:在亚马逊EC2上运行的Jar t2.micro实例内存不足

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 

如何从此处继续?遵循他们的建议,如增加堆大小或交换空间是否合理,还是我真的需要将EC2实例升级到更大尺寸?

回答

1

问题是您耗尽了虚拟内存或实际地址空间。

这意味着你要么

  • 增加交换空间
  • 下降堆大小

你需要降低堆大小的原因是离开了更多的内存JVM和系统的其余部分

1

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

请记住,您将无法将t2.micro实例上的全部1GB内存分配给您的Java应用程序,因为有些操作系统正在使用这些内存。此外,如果可能的话,还需要避免使用交换空间,因此请专心配置JVM以使用EC2实例上的可用RAM。

不知道您当前的JVM设置是否很难给出更确切的建议。

+0

嗯..但错误消息是建议减少堆大小。 –

+0

哦,我明白了。也许你已经分配了比服务器上实际存在更多的内存。无论如何,如果您需要更确切的建议,您需要提供当前的JVM设置。 –

+0

如何获取当前的JVM设置?我需要编写一个Java程序吗,还是可以从命令行执行? –