2016-02-29 56 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程序嗎,還是可以從命令行執行? –