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.
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.
Sobre o autor
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.
Mais como este
Navegue por canal
Automação
Últimas novidades em automação de TI para empresas de tecnologia, equipes e ambientes
Inteligência artificial
Descubra as atualizações nas plataformas que proporcionam aos clientes executar suas cargas de trabalho de IA em qualquer ambiente
Nuvem híbrida aberta
Veja como construímos um futuro mais flexível com a nuvem híbrida
Segurança
Veja as últimas novidades sobre como reduzimos riscos em ambientes e tecnologias
Edge computing
Saiba quais são as atualizações nas plataformas que simplificam as operações na borda
Infraestrutura
Saiba o que há de mais recente na plataforma Linux empresarial líder mundial
Aplicações
Conheça nossas soluções desenvolvidas para ajudar você a superar os desafios mais complexos de aplicações
Programas originais
Veja as histórias divertidas de criadores e líderes em tecnologia empresarial
Produtos
- Red Hat Enterprise Linux
- Red Hat OpenShift
- Red Hat Ansible Automation Platform
- Red Hat Cloud Services
- Veja todos os produtos
Ferramentas
- Treinamento e certificação
- Minha conta
- Suporte ao cliente
- Recursos para desenvolvedores
- Encontre um parceiro
- Red Hat Ecosystem Catalog
- Calculadora de valor Red Hat
- Documentação
Experimente, compre, venda
Comunicação
- Contate o setor de vendas
- Fale com o Atendimento ao Cliente
- Contate o setor de treinamento
- Redes sociais
Sobre a Red Hat
A Red Hat é a líder mundial em soluções empresariais open source como Linux, nuvem, containers e Kubernetes. Fornecemos soluções robustas que facilitam o trabalho em diversas plataformas e ambientes, do datacenter principal até a borda da rede.
Selecione um idioma
Red Hat legal and privacy links
- Sobre a Red Hat
- Oportunidades de emprego
- Eventos
- Escritórios
- Fale com a Red Hat
- Blog da Red Hat
- Diversidade, equidade e inclusão
- Cool Stuff Store
- Red Hat Summit