Users of Red Hat JBoss Web Server might also want to set memory size on Red Hat OpenShift because it can help manage the resource in fine-grained. In order to change heap memory size of Red Hat JBoss Web Server, you can set -Xms -Xmx with CATALINA_OPTS or JAVA_OPTS. With Red Hat OpenShift Container Platform, you use Java Web Server Tomcat S2I image. By default, the Java Web Server Tomcat S2I image calculates initial heap memory size and max memory size every time when the container spins up. However, it also provides some ways to set heap memory size. This blog shows how to decide default heap memory size and how to change the memory.
How to calculate the default memory size?
Every time the Tomcat container deploys, it executes this command `/opt/webserver/bin/launch.sh`. This script also executes `java-default-options.sh` script to get default java options.
These options provide the values listed below:
-
initial_memory
-
max_memory
-
gc_config
-
diagnostics
-
cpu_core_tunning
-
error_handling
When it comes to initial_memory(Xms) and max_memory(Xmx), this diagram can give an idea of how to decide the default values.
Figure 1. Initial Memory Decision Logic Flow
For example, if the memory of the node that container is running on is 8G (8008824 kB), the minimum memory will be decided by the JVM and the maximum memory will be 4G. You might wonder: why not allocate all of the available memory? This is because there are other memory areas such as metadata, thread, code cache, etc that make up the overall memory footprint.
Setting at 50% seems to be a reasonable compromise, however, it may need additional tuning when you encounter memory issues.
How to change the memory size?
As the above diagram shows, there are two different ways to set up the value of memory size for minimum and maximum limits. But for here, I will only explain resource limit way that can also apply for Standalone Java Applications or Red Hat JBoss Enterprise Application Platform (JBoss EAP).
Resource limit
For a project-wide configuration, LimitRange object can be used. You can add pod limit to DC or pod directly if you are looking to add limits to a specific pod.
- Using LimitRange object
~~~
...
default:
cpu: "300m"
memory: "200Mi"
defaultRequest:
cpu: "200m"
memory: "50Mi"
...
~~~
~~~
## Create java-heap-test project
$ oc new-project java-heap-test
## Create limitRange object
$ oc create -f https://goo.gl/XgU4H6
## Describe the limitRange detail
$ oc describe limitrange core-resource-limits
Name: core-resource-limits
Namespace: java-heap-test
Type |
Resource |
Min |
Max |
Default Request |
Default Limit |
Max Limit/Request Ratio |
---|---|---|---|---|---|---|
Pod |
memory |
6Mi |
2Gi |
- |
- |
- |
Pod |
CPU |
200m |
2 |
- |
- |
- |
Container |
memory |
4Mi |
1Gi |
50Mi |
200Mi |
- |
Container |
CPU |
100m |
2 |
200m |
300m |
10 |
~~~
Let’s try to deploy Tomcat and you will notice that it is really slow because of small heap memory. Afterward, it fails to deploy due to out of memory.
~~~
## Deploy tomcat pod
$ oc new-app --template=jws31-tomcat8-basic-s2i
## Check the status of pod
$ oc get pod
NAME |
READY |
STATUS |
RESTARTS |
AGE |
---|---|---|---|---|
jws-app-1-build |
0/1 |
OOMKilled |
0 |
6m |
## Check the heap memory size of the build pod
$ oc logs jws-app-1-build
Using MAVEN_OPTS '-Xms100m -Xmx100m …………………..'
~~~
Let’s increase heap memory size and build again.
~~~
## Change the default memory size from 200Mi to 500Mi
$ OC_EDITOR='sed s/200Mi/500Mi/g' oc edit limitrange core-resource-limits |oc apply -f -
## Start new build
$ oc start-build jws-app
## Check the heap memory size is changed
$ oc logs jws-app-2-build
Using MAVEN_OPTS '-Xms250m -Xmx250m …………………..'
~~~
After build finishes, Tomcat will be deployed. We can see that it uses 250m for heap memory size (min/max).
~~~
$ oc get pod
NAME |
READY |
STATUS |
RESTARTS |
AGE |
---|---|---|---|---|
jws-app-1-build |
0/1 |
OOMKilled |
0 |
5m |
jws-app-1-deploy |
1/1 |
Running |
0 |
16s |
jws-app-1-mjn9r |
0/1 |
Running |
0 |
8s |
jws-app-2-build |
0/1 |
Completed |
0 |
2m |
$ oc logs jws-app-1-mjn9r -f
...
….Command line argument: -Xms250m
....Command line argument: -Xmx250m
…
~~~
In order to decrease minimum memory size, you can give bigger JAVA_INITIAL_MEM_RATIO (default 100) as a DeploymentConfig environment variable.
~~~
$ oc edit dc jwa-app
...
spec:
containers:
- env:
- name: JAVA_INITIAL_MEM_RATIO
value: 50
...
~~~
Then, the minimum memory size will be half of the maximum memory size(250m). It is 125m.
You can also increase the maximum memory size but you should keep in mind that heap memory size is a portion of the total memory in a container. As I mentioned above, it needs more spaces for metadata, thread, code cache, etc. Therefore, you have to take caution when adjusting the JAVA_MAX_MEM_RATIO.
Like JAVA_INITIAL_MEM_RATIO, you can set up it as a DeploymentConfig environment variable.
~~~
$ oc edit dc jwa-app
...
spec:
containers:
- env:
- name: JAVA_INITIAL_MEM_RATIO
value: 50
- name: JAVA_MAX_MEM_RATIO
value: 70
...
~~~
Then, the maximum memory size will be 70% of maximum memory size (500m). It is 350m. Moreover, the minimum memory size will be changed to 175m because it is also recalculated by script (refer Figure 1. Initial Memory Decision Logic Flow)
Reference:
Jooho Lee is a senior OpenShift Technical Account Manager (TAM) in Toronto supporting middleware products (e.g. JBoss EAP, Red Hat JBoss Data Grid, and Red Hat JBoss Web Server) and cloud technologies (e.g. docker, Kubernetes, OpenShift, and Ansible). He is an active member of JBoss User Group Korea and the Openshift and Ansible Group. Find more posts by Jooho at https://www.redhat.com/en/about/blog/authors/jooho-lee.
A Red Hat Technical Account Manager (TAM) is a specialized product expert who works collaboratively with IT organizations to strategically plan for successful deployments and help realize optimal performance and growth. The TAM is part of Red Hat’s world-class Customer Experience and Engagement organization and provides proactive advice and guidance to help you identify and address potential problems before they occur. Should a problem arise, your TAM will own the issue and engage the best resources to resolve it as quickly as possible with minimal disruption to your business.
Connect with TAMs at a Red Hat Convergence event near you! Red Hat Convergence is a free, invitation-only event offering technical users an opportunity to deepen their Red Hat product knowledge and discover new ways to apply open source technology to meet their business goals. These events travel to cities around the world to provide you with a convenient, local one-day experience to learn and connect with Red Hat experts and industry peers.
저자 소개
Jooho Lee is a senior OpenShift Technical Account Manager (TAM) in Toronto supporting middleware products(EAP/ DataGrid/ Web Server) and cloud products (Docker/ Kubernetes/ OpenShift/ Ansible). He is an active member of JBoss User Group Korea and Openshift / Ansible Group.
채널별 검색
오토메이션
기술, 팀, 인프라를 위한 IT 자동화 최신 동향
인공지능
고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트
오픈 하이브리드 클라우드
하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요
보안
환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보
엣지 컴퓨팅
엣지에서의 운영을 단순화하는 플랫폼 업데이트
인프라
세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보
애플리케이션
복잡한 애플리케이션에 대한 솔루션 더 보기
오리지널 쇼
엔터프라이즈 기술 분야의 제작자와 리더가 전하는 흥미로운 스토리
제품
- Red Hat Enterprise Linux
- Red Hat OpenShift Enterprise
- Red Hat Ansible Automation Platform
- 클라우드 서비스
- 모든 제품 보기
툴
체험, 구매 & 영업
커뮤니케이션
Red Hat 소개
Red Hat은 Linux, 클라우드, 컨테이너, 쿠버네티스 등을 포함한 글로벌 엔터프라이즈 오픈소스 솔루션 공급업체입니다. Red Hat은 코어 데이터센터에서 네트워크 엣지에 이르기까지 다양한 플랫폼과 환경에서 기업의 업무 편의성을 높여 주는 강화된 기능의 솔루션을 제공합니다.