eclipse-openj9 / openj9

Eclipse OpenJ9: A Java Virtual Machine for OpenJDK that's optimized for small footprint, fast start-up, and high throughput. Builds on Eclipse OMR (https://github.com/eclipse/omr) and combines with the Extensions for OpenJDK for OpenJ9 repo.
Other
3.28k stars 721 forks source link

Define standard ENV vars passing Kubernetes "request" limits to the JVM #9239

Open DanHeidinga opened 4 years ago

DanHeidinga commented 4 years ago

K8 provides two resource bounds for controlling the use of memory and cpu in a container:

Currently, the "limit" is used to create the cgroup for the container. This means the JVM's default container awareness is based on the upper bound (limit) rather than the lower bound (request).

To my knowledge, the "request" limits are not exposed to the container by default so the JVM can't use them to control heap and CPU settings.

There is a K8 api, the Downward API, that allows passing K8-related info into the container. See https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/

We should define a standard set of environment variables for the REQUEST parameters to allow the JVM to size itself based on the lower bound rather than the upper. These ENV vars would be used in preference to cgroup settings.

We would also need to work with groups like Appsody and others that are creating yaml files to set the env vars in their yaml.

Example ymal from https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/ :

apiVersion: v1
kind: Pod
metadata:
  name: dapi-envars-resourcefieldref
spec:
  containers:
    - .....
      resources:
        requests:
          memory: "32Mi"
          cpu: "125m"
        limits:
          memory: "64Mi"
          cpu: "250m"
      env:
        - name: MY_CPU_REQUEST
          valueFrom:
            resourceFieldRef:
              containerName: test-container
              resource: requests.cpu
        - name: MY_CPU_LIMIT
          valueFrom:
            resourceFieldRef:
              containerName: test-container
              resource: limits.cpu
        - name: MY_MEM_REQUEST
          valueFrom:
            resourceFieldRef:
              containerName: test-container
              resource: requests.memory
        - name: MY_MEM_LIMIT
          valueFrom:
            resourceFieldRef:
              containerName: test-container
              resource: limits.memory
DanHeidinga commented 4 years ago

fyi @dinogun

vijaysun-omr commented 4 years ago

@dinogun what do you think about this technique to get the "request" size via env var in the JVM ?