Skip to content

Commit

Permalink
ISD-1729 Add RAM percentage JVM option and documentations (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thanhphan1147 authored Apr 17, 2024
1 parent 63de973 commit cf76eef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/how-to/configure-jenkins-memory-usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# How to control heap memory of the jenkins-k8s-operator charm
The [jenkins-k8s-operator](https://github.com/canonical/jenkins-k8s-operator) charm uses [juju constraints](https://juju.is/docs/juju/constraint) to limit the amount of memory a charm can use. To deploy the charm with constraints, use the `--constraints "<key>=<value>"` option when running `juju deploy`:
```bash
juju deploy jenkins-k8s --channel=latest/edge --constraints "mem=2048M"
```
To change this value after deployment, use the `set-constraints` command.
```bash
juju set-constraints jenkins-k8s "mem=4096M"
```
Other types of constraints (like cores, disk, etc.) can also be applied. Note that this value affects the shared maximum memory between the `charm` container and `jenkins` container.

# Considerations when applying memory constraints
Constraints set this way directly influence the amount of heap memory available to the JVM, with a ratio `JVM heap / Container Memory limit` of 0.5. For example, a `jenkins-k8s-operator` charm deployed with `--constraints "mem=1024M"` would set a maximum heap memory size of 512Mb. Too little heap memory can result in the controller getting restarted due to Out-of-memory(OOM) error. Make sure to adapt the memory constraints based on your workload.
1 change: 1 addition & 0 deletions src/pebble.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def _get_pebble_layer(jenkins_instance: jenkins.Jenkins) -> ops.pebble.Layer:
"summary": "jenkins",
"command": f"java -D{jenkins.SYSTEM_PROPERTY_HEADLESS} "
f"-D{jenkins.SYSTEM_PROPERTY_LOGGING} "
"-XX:MaxRAMPercentage=50.0 -XX:InitialRAMPercentage=50.0 "
f"-jar {jenkins.EXECUTABLES_PATH}/jenkins.war "
f"--prefix={env_dict['JENKINS_PREFIX']}",
"startup": "enabled",
Expand Down

0 comments on commit cf76eef

Please sign in to comment.