Skip to content

Optimize memory usage in tests#506

Open
qligier wants to merge 2 commits into
mainfrom
feat/optimize-mem
Open

Optimize memory usage in tests#506
qligier wants to merge 2 commits into
mainfrom
feat/optimize-mem

Conversation

@qligier

@qligier qligier commented Apr 7, 2026

Copy link
Copy Markdown
Member

No description provided.

@qligier qligier requested a review from Copilot April 7, 2026 19:34
@qligier qligier self-assigned this Apr 7, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 tests Spring profile (application-tests.yaml) that disables/limits several HAPI FHIR, Spring, and management features for test execution.
  • Updated multiple @SpringBootTest classes to activate the new tests profile alongside existing version-specific test profiles.
  • Adjusted Maven Surefire/Failsafe JVM options and the GitHub Actions workflow MAVEN_OPTS to 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.

Comment on lines +52 to +53
# Disable scheduling, as specified in BaseSchedulerServiceImpl
scheduling_disabled: true

Copilot AI Apr 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
# Disable scheduling, as specified in BaseSchedulerServiceImpl
scheduling_disabled: true

Copilot uses AI. Check for mistakes.
Comment thread matchbox-server/pom.xml
Comment on lines 338 to +341
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<argLine>-Xmx20g</argLine>
<forkCount>1</forkCount>
<reuseForks>true</reuseForks>

Copilot AI Apr 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread matchbox-server/pom.xml
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-XX:MaxRAMPercentage=100.0 -XX:MinRAMPercentage=40.0</argLine>

Copilot AI Apr 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
<argLine>-XX:MaxRAMPercentage=100.0 -XX:MinRAMPercentage=40.0</argLine>
<argLine>-XX:MaxRAMPercentage=70.0</argLine>

Copilot uses AI. Check for mistakes.
Comment thread matchbox-engine/pom.xml
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Xmx12g</argLine>
<argLine>-XX:MaxRAMPercentage=100.0 -XX:MinRAMPercentage=40.0</argLine>

Copilot AI Apr 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
<argLine>-XX:MaxRAMPercentage=100.0 -XX:MinRAMPercentage=40.0</argLine>
<argLine>-XX:MaxRAMPercentage=70.0</argLine>

Copilot uses AI. Check for mistakes.
Comment thread matchbox-engine/pom.xml
Comment on lines 180 to +184
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<argLine>-Xmx20g</argLine>
<forkCount>1</forkCount>
<reuseForks>true</reuseForks>

Copilot AI Apr 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +30 to 31
MAVEN_OPTS: -XX:MaxRAMPercentage=100.0 -XX:MinRAMPercentage=40.0
run: mvn --batch-mode --no-transfer-progress --update-snapshots verify

Copilot AI Apr 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
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

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants