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 (人工知能)
お客様が AI ワークロードをどこでも自由に実行することを可能にするプラットフォームについてのアップデート
オープン・ハイブリッドクラウド
ハイブリッドクラウドで柔軟に未来を築く方法をご確認ください。
セキュリティ
環境やテクノロジー全体に及ぶリスクを軽減する方法に関する最新情報
エッジコンピューティング
エッジでの運用を単純化するプラットフォームのアップデート
インフラストラクチャ
世界有数のエンタープライズ向け Linux プラットフォームの最新情報
アプリケーション
アプリケーションの最も困難な課題に対する Red Hat ソリューションの詳細
オリジナル番組
エンタープライズ向けテクノロジーのメーカーやリーダーによるストーリー
製品
ツール
試用、購入、販売
コミュニケーション
Red Hat について
エンタープライズ・オープンソース・ソリューションのプロバイダーとして世界をリードする Red Hat は、Linux、クラウド、コンテナ、Kubernetes などのテクノロジーを提供しています。Red Hat は強化されたソリューションを提供し、コアデータセンターからネットワークエッジまで、企業が複数のプラットフォームおよび環境間で容易に運用できるようにしています。
言語を選択してください
Red Hat legal and privacy links
- Red Hat について
- 採用情報
- イベント
- 各国のオフィス
- Red Hat へのお問い合わせ
- Red Hat ブログ
- ダイバーシティ、エクイティ、およびインクルージョン
- Cool Stuff Store
- Red Hat Summit