503 alias OOM (OutOfMemoryError) Exception

503 alias OOM (OutOfMemoryError) Exception

One of the most perplexing issues with Java applications is the out-of-memory error. It will have a severe impact on application performance and cause service degradation. Eventually, we will get 503 :(

What is it? Why?

It is a runtime error in Java, and it will occur when the JVM can't find enough space for new objects. It means, you tried to keep too much data on the heap of the JVM process, and there is not enough memory to create new objects, and the garbage collector can't collect enough garbage.?

As previously stated, it will occur at the JVM level and can be classified into two types.

  1. java.lang.OutOfMemoryError: Java heap space?
  2. java.lang.OutOfMemoryError: PermGen space


Let's dive deeper into each type.

1. java.lang.OutOfMemoryError: Java heap space?

What is OOM in Heap Space?

Heap space is used for dynamic memory allocation. When the JVM is started, heap memory is created, and it begins allocating memory for newly loaded objects or classes. Any objects in the heap will be accessed globally and shared between threads as long as the application is running.

Default Size :

It will vary depending on the machine type (32 or 64 bits) and the type of JVM.?But generally, the initial heap size will be 32 MB, and the maximum heap size is 256 MB.

Prevention :

Estimate the heap size effectively, and explicitly specify it by passing it below JVM parameters.

-Xmx : Maximum Heap Size

-Xms : Initial or Minimum Heap Size        

Recommend to keep -Xmx to -Xms ration either 1:1 or 1:1.5. It will play a crucial role in application #performance and #throughput.?

Challange :

The large maximum heap size, which makes garbage collection less frequent. If garbage collection is driven less frequently, the heap size associated with the integration server continues to grow.?

Reference :

https://docs.oracle.com/cd/E19900-01/819-4742/6n6sfgmkr/index.html


2. java.lang.OutOfMemoryError: PermGen Space

What is OOM in PermGen Space?

PermGen is a special type of heap space that is separate from main memory (heap). It used to store the static contents, the code cache, and the loaded class meta-data.

Default Size :

Permgen size is fixed. Most of the JVM default size is 64mb to 82 mb. Since the size is low, we can easily run out of memory if you have too many classes or a huge number of strings in your application.

Prevention :

  1. Increase the size using the following commands.


-XX:PermSize is the minimum or initial size of the PermGen space.

-XX:MaxPermSize is the maximum size        

2. ?Enable Sweeping

Another way to take care of that for good is to allow classes to be unloaded so your PermGen never runs out:?


-XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled        

NEERAJ KUMAR

Jmeter Certified|| Performance Test & SRE Manager ||Ex-Fidelity || Ex-Born ||Ex-CTS ||Performance testing ||jmeter||load runner||Dynatrace||Datadog||New Relic|| Cloud watch||OEM

1 年

Useful !

Vasanth Shanmugam

Azure DevOps Engineer & Platform Engineer at Bank of England

2 年

Good one. Well explained..

要查看或添加评论,请登录

社区洞察

其他会员也浏览了