In this article we will see how can we protect our application from the OOM killer and plan to ensure our AEM have sufficient RAM to process the request and perform at its best.
AEM Memory management :
Most of AEM admin/architect have been planned their Infra by calculating the Website and Visitors per days. Most critical sites like Banking , Ecommerce site needs special attention to plan their Hardware and Network bandwidth , etc.
In single word , complete capacity planning should be done.
AEM startup file have JVM option where we can plan our Memory settings. Most critical arguments are
-Xms : Initial Heap size. This is the minimum size.
-Xmx: Maximum Heap size AEM process can use.
-Maxmetaspacesize replace MaxpermSize from Java 8.
-XX: +HeapDumpOnOutOfMemroryError -XX: +HeapDumpPath=tmp # capture OOM logs to user mentioned path.
To get more details , please run the below command
- Java -X
1. What is OOM Killer:
In most of our cases we have been followed for our Prod-like and Prod instance. This might helps who have DEV or TEST env linked to Jenkins CI and CD for agile model .
Each time Developers push new code to repository will be picked from Jenkins Via pipeline and deploy it to DEV AEM servers. This can help Developers to test their code on the fly.
Here lies the real challenge. What if any code pushed to Repository with Memory leakage. ?
If this situation occurs then OS ( Ubuntu in my case ) will kill all the process to protect the server crash.
To check if your OS killed your Process via below command
- grep -i kill /var/log/messages
This command shows if any process killed due to OOM.
Technically this is known as OOM Killer.
2.Protect AEM process:
To Protect our AEM process , we have 2 methods.
2.a.Method 1: Add values to oom_adj :
1.Get your AEM process .
> pgrep java # In my system ,AEM pid is 4198.
2.Now naviage to that path below
> Cd /opt/4198/
> echo -17 > oom_adj
This can be passed from anywhere but ensure to add the full path .
-17 Means that this will not be considered by OOM killer if any Memory leaks occurred. So our AEM process will be still running .
2.b.Method 2:Disable OOM killer
If your DEV env is dedicated to only AEM then we can plan to disable OOM killer completely.
- Sysctl -a # this shows complete sysctl values.
By default , vm.overcommit_memory to “0”.
Change the value to 2.
- Sysctl vm.overcommit_memory=2
Also the below command will set this value during boot.
- echo “vm.overcommit_memory=2” >> /etc/sysctl.conf
This command will disable OOM killer from this OS .