Optimize memory usage in tests#506
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a shared Spring “tests” profile intended to reduce memory usage during test runs by disabling non-essential server features, and updates test configuration/CI JVM memory settings accordingly.
Changes:
- Added a new
testsSpring profile (application-tests.yaml) that disables/limits several HAPI FHIR, Spring, and management features for test execution. - Updated multiple
@SpringBootTestclasses to activate the newtestsprofile alongside existing version-specific test profiles. - Adjusted Maven Surefire/Failsafe JVM options and the GitHub Actions workflow
MAVEN_OPTSto use RAM-percentage-based sizing (and added a large fixed heap for failsafe).
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| matchbox-server/src/test/resources/application-tests.yaml | New shared “tests” profile with feature toggles to reduce test memory footprint. |
| matchbox-server/src/test/java/ch/ahdis/matchbox/test/MatchboxApiR5Test.java | Activates tests profile for R5 API tests. |
| matchbox-server/src/test/java/ch/ahdis/matchbox/test/MatchboxApiR5onR4Test.java | Activates tests profile for R5-on-R4 tests. |
| matchbox-server/src/test/java/ch/ahdis/matchbox/test/MatchboxApiR4Test.java | Activates tests profile for R4 tests; minor whitespace-only edits. |
| matchbox-server/src/test/java/ch/ahdis/matchbox/test/MatchboxApiR4BTest.java | Activates tests profile for R4B tests; minor whitespace-only edits. |
| matchbox-server/src/test/java/ch/ahdis/matchbox/mapping/TransformTest.java | Activates tests profile for transform tests; minor whitespace-only edits. |
| matchbox-server/src/test/java/ch/ahdis/matchbox/gazelle/GazelleApiR4Test.java | Activates tests profile for Gazelle API tests. |
| matchbox-server/pom.xml | Adds surefire config and updates failsafe JVM settings (including -Xmx20g). |
| matchbox-engine/pom.xml | Updates surefire JVM sizing and adds failsafe JVM settings (including -Xmx20g). |
| .github/workflows/maven.yml | Changes CI MAVEN_OPTS to RAM-percentage-based sizing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Disable scheduling, as specified in BaseSchedulerServiceImpl | ||
| scheduling_disabled: true |
There was a problem hiding this comment.
scheduling_disabled does not appear to be a recognized/bound configuration property in this codebase (no references found outside this file). As written it will have no effect and the comment about BaseSchedulerServiceImpl is not verifiable in-repo. Consider removing this key (since scheduling is already controlled via hapi.fhir.dao_scheduling_enabled) or wiring it to an actual @ConfigurationProperties field if it’s meant to be used.
| # Disable scheduling, as specified in BaseSchedulerServiceImpl | |
| scheduling_disabled: true |
| <redirectTestOutputToFile>true</redirectTestOutputToFile> | ||
| <argLine>-Xmx20g</argLine> | ||
| <forkCount>1</forkCount> | ||
| <reuseForks>true</reuseForks> |
There was a problem hiding this comment.
The failsafe test JVM is hard-coded to -Xmx20g. This is likely to exceed available memory on typical developer machines and GitHub-hosted runners, causing integration-test forks to fail to start. Prefer a smaller default, use MaxRAMPercentage (with headroom), and/or make the heap size configurable via a Maven property/profile for the few environments that need a large heap.
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-surefire-plugin</artifactId> | ||
| <configuration> | ||
| <argLine>-XX:MaxRAMPercentage=100.0 -XX:MinRAMPercentage=40.0</argLine> |
There was a problem hiding this comment.
The surefire test JVM is configured with -XX:MaxRAMPercentage=100.0 and -XX:MinRAMPercentage=40.0. With Maven also running in its own JVM, this can easily overcommit memory (heap + metaspace/native) and cause OOMs. Consider lowering MaxRAMPercentage to leave headroom and reducing/removing the high MinRAMPercentage so tests don’t eagerly reserve large heaps.
| <argLine>-XX:MaxRAMPercentage=100.0 -XX:MinRAMPercentage=40.0</argLine> | |
| <argLine>-XX:MaxRAMPercentage=70.0</argLine> |
| <artifactId>maven-surefire-plugin</artifactId> | ||
| <configuration> | ||
| <argLine>-Xmx12g</argLine> | ||
| <argLine>-XX:MaxRAMPercentage=100.0 -XX:MinRAMPercentage=40.0</argLine> |
There was a problem hiding this comment.
The surefire test JVM is configured with -XX:MaxRAMPercentage=100.0 and -XX:MinRAMPercentage=40.0, which can overcommit memory once Maven and any other JVMs are accounted for (heap + native/metaspace). Consider lowering MaxRAMPercentage to leave headroom and reducing/removing the high MinRAMPercentage.
| <argLine>-XX:MaxRAMPercentage=100.0 -XX:MinRAMPercentage=40.0</argLine> | |
| <argLine>-XX:MaxRAMPercentage=70.0</argLine> |
| <configuration> | ||
| <redirectTestOutputToFile>true</redirectTestOutputToFile> | ||
| <argLine>-Xmx20g</argLine> | ||
| <forkCount>1</forkCount> | ||
| <reuseForks>true</reuseForks> |
There was a problem hiding this comment.
The failsafe test JVM is hard-coded to -Xmx20g, which is likely larger than available RAM in CI and on many developer machines. Consider switching to a percentage-based limit (with headroom) or making this value configurable via a Maven property/profile so it can be increased only where needed.
| MAVEN_OPTS: -XX:MaxRAMPercentage=100.0 -XX:MinRAMPercentage=40.0 | ||
| run: mvn --batch-mode --no-transfer-progress --update-snapshots verify |
There was a problem hiding this comment.
MAVEN_OPTS is set to -XX:MaxRAMPercentage=100.0 -XX:MinRAMPercentage=40.0. Since the Maven JVM and the forked surefire JVM(s) run concurrently, allowing each JVM to size itself up to 100% of system RAM can cause severe overcommit and CI OOMs. Consider giving Maven an explicit smaller heap (e.g., -Xmx), and keep the percentage-based sizing only for the forked test JVMs (with headroom).
| MAVEN_OPTS: -XX:MaxRAMPercentage=100.0 -XX:MinRAMPercentage=40.0 | |
| run: mvn --batch-mode --no-transfer-progress --update-snapshots verify | |
| MAVEN_OPTS: -Xmx1g | |
| run: mvn --batch-mode --no-transfer-progress --update-snapshots -DargLine="-XX:MaxRAMPercentage=70.0 -XX:MinRAMPercentage=40.0" verify |
No description provided.