Configuring WildFly JVM on Openshift

In this tutorial we will learn how to configure JVM settings for WildFly Container running on Openshift. More in detail, we will see how to apply other JAVA_OPTS to the process and how to set the Memory settings for the JVM

Out of the box, the WildFly application server configures the JVM settings through the JAVA_OPTS environment variable. When moving to the Paas, this is done differently. So if you want to add a JVM argument to the WildFly process, you have to include this information in the JAVA_OPTS_EXT environment variable. In the following example, we are adding the attribute to the Deployment config, but it can be done on creation of the image as well:

jvm openshift java_opts tutorial

Once included the environment variable, the Pod will be recreated with the included environment variable. As you can see, the environment variable "x" has been included:

 JAVA_OPTS: -server -XX:+UseParallelGC -Xms40m -Xmx256m -XX:+AggressiveOpts -XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=40 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dorg.apache.tomcat.util.LOW_MEMORY=true -DOPENSHIFT_APP_UUID= -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true -Dorg.jboss.resolver.warning=true -Dfile.encoding=UTF-8 -Djgroups.bind_addr= -Dorg.apache.coyote.http11.Http11Protocol.COMPRESSION=on -Dx=1

Next thing we want to configure is the amount of memory to allocate for the JVM. As a matter of fact, including the -Xms and -Xmx option as environment variable won't work as the amount of memory to be used for the process depends on the Resource Limits assigned to the Container.

Resource limits can be configured when you create the Container from the Template or as well through the Deployment Configuration -> Edit Resource Limits as shown by the following picture:

openshift wildfly jvm tutorial

As an alternative, you can define Resource Limits for your whole namespace. For example, the following JSON file defines a set of resource limits:

apiVersion: "v1"
kind: "LimitRange"
  name: "core-resource-limits" 
    - type: "Pod"
        cpu: "2" 
        memory: "1Gi" 
        cpu: "200m" 
        memory: "6Mi" 
    - type: "Container"
        cpu: "2" 
        memory: "1Gi" 
        cpu: "100m" 
        memory: "4Mi" 
        cpu: "300m" 
        memory: "200Mi" 
        cpu: "200m" 
        memory: "100Mi" 
        cpu: "10"

 Then, you can apply the Resource Limits to a particular project, say "demowildfly":

$ oc create -f limits.json -n demowildfly

Follow us on Twitter