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.
Sobre el 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.
Más similar
Navegar por canal
Automatización
Las últimas novedades en la automatización de la TI para los equipos, la tecnología y los entornos
Inteligencia artificial
Descubra las actualizaciones en las plataformas que permiten a los clientes ejecutar cargas de trabajo de inteligecia artificial en cualquier lugar
Nube híbrida abierta
Vea como construimos un futuro flexible con la nube híbrida
Seguridad
Vea las últimas novedades sobre cómo reducimos los riesgos en entornos y tecnologías
Edge computing
Conozca las actualizaciones en las plataformas que simplifican las operaciones en el edge
Infraestructura
Vea las últimas novedades sobre la plataforma Linux empresarial líder en el mundo
Aplicaciones
Conozca nuestras soluciones para abordar los desafíos más complejos de las aplicaciones
Programas originales
Vea historias divertidas de creadores y líderes en tecnología empresarial
Productos
- Red Hat Enterprise Linux
- Red Hat OpenShift
- Red Hat Ansible Automation Platform
- Servicios de nube
- Ver todos los productos
Herramientas
- Training y Certificación
- Mi cuenta
- Soporte al cliente
- Recursos para desarrolladores
- Busque un partner
- Red Hat Ecosystem Catalog
- Calculador de valor Red Hat
- Documentación
Realice pruebas, compras y ventas
Comunicarse
- Comuníquese con la oficina de ventas
- Comuníquese con el servicio al cliente
- Comuníquese con Red Hat Training
- Redes sociales
Acerca de Red Hat
Somos el proveedor líder a nivel mundial de soluciones empresariales de código abierto, incluyendo Linux, cloud, contenedores y Kubernetes. Ofrecemos soluciones reforzadas, las cuales permiten que las empresas trabajen en distintas plataformas y entornos con facilidad, desde el centro de datos principal hasta el extremo de la red.
Seleccionar idioma
Red Hat legal and privacy links
- Acerca de Red Hat
- Oportunidades de empleo
- Eventos
- Sedes
- Póngase en contacto con Red Hat
- Blog de Red Hat
- Diversidad, igualdad e inclusión
- Cool Stuff Store
- Red Hat Summit