You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hugegraph.apache.org by "lokidundun (via GitHub)" <gi...@apache.org> on 2026/09/05 08:39:00 UTC
[PR] perf(docker): reuse runtime layers and scope Maven builds [hugegraph]
lokidundun opened a new pull request, #3194:
URL: https://github.com/apache/hugegraph/pull/3194
<!--
Thank you very much for contributing to Apache HugeGraph, we are happy that you want to help us improve it!
Here are some tips for you:
1. If this is your first time, please read the [contributing guidelines](https://github.com/apache/hugegraph/blob/master/docs/CONTRIBUTING.md)
2. If a PR fix/close an issue, type the message "close xxx" (xxx is the link of related
issue) in the content, GitHub will auto link it (Required)
3. Name the PR title in "Google Commit Format", start with "feat | fix | perf | refactor | doc | chore",
such like: "feat(core): support the PageRank algorithm" or "fix: wrong break in the compute loop" (module is optional)
skip it if you are unsure about which is the best component.
4. One PR address one issue, better not to mix up multiple issues.
5. Put an `x` in the `[ ]` to mark the item as CHECKED. `[x]` (or click it directly after
published)
-->
## Purpose of the PR
- close #3179 <!-- or use "fix #xxx", "xxx" is the ID-link of related issue, e.g: close #1024 -->
<!--
Please explain more context in this section, clarify why the changes are needed.
e.g:
- If you propose a new API, clarify the use case for a new API.
- If you fix a bug, you can clarify why it is a bug, and should be associated with an issue.
-->
## Main Changes
- Move runtime package installation before `COPY --from=build` in all four Dockerfiles, allowing dependency layers to survive application source changes.
- Keep configuration edits that depend on copied files after the corresponding `COPY`.
- Build the Server, PD, and Store distribution modules with `-pl` and `-am`, reducing the reactor from 38 to 27 modules while retaining required dependencies.
- Preserve existing runtime packages, configurable Maven arguments, and identical shared Maven build stages across all four Dockerfiles.
The existing single-job Bake flow and QEMU-based ARM64 build remain in place.
## Verifying these changes
- [ ] Trivial rework / code cleanup without any test coverage. (No Need)
- [x] Already covered by existing checks: multi-platform image inspection, Compose integration, Gremlin CRUD, and Standalone smoke tests.
- [x] Additional verification: before/after benchmarks and distribution/image content comparisons.
### Runtime dependency layer benchmark
Both variants used the same GitHub-hosted Ubuntu runner class and separate GHCR registry caches. After seeding each cache, identical configuration comments were added to trigger distribution changes and a full Maven rebuild.
| Scenario / metric | Before | After | Reduction |
| --- | ---: | ---: | ---: |
| Initial cache seed: image build | 552 s | 510 s | 42 s (7.6%) |
| Initial cache seed: complete job | 704 s | 669 s | 35 s (5.0%) |
| Source change: image build | 601 s | 461 s | 140 s (23.3%) |
| Source change: complete job | 755 s | 602 s | 153 s (20.3%) |
Before the change, the four ARM64 runtime package installation steps ran under QEMU and took 150.6–160.5 seconds each. After the change, all eight runtime dependency layers across amd64 and arm64 were restored from registry cache in 2.0–9.3 seconds per layer, without rerunning package installation.
Cache export was measured separately:
| Cache export vertex | Before | After |
| --- | ---: | ---: |
| Shared build cache | 205.2 s | 165.7 s |
| PD | 87.8 s | 5.5 s |
| Store | 56.1 s | 4.9 s |
| HStore Server | 83.3 s | 6.6 s |
| Standalone Server | 40.3 s | 8.1 s |
These BuildKit vertices overlap; their durations must not be added together or treated as independent end-to-end savings.
### Maven reactor benchmark
This separate experiment compared the full reactor with the scoped reactor using the same source and existing runtime layer optimization.
| Metric | Full reactor | Scoped reactor | Reduction |
| --- | ---: | ---: | ---: |
| Reactor modules | 38 | 27 | 11 modules |
| Maven-reported build time | 270 s | 176 s | 94 s (34.8%) |
| Distribution build, cache and local export | 424 s | 269 s | 155 s (36.6%) |
| Complete distribution job, including artifact upload | 492 s | 351 s | 141 s (28.7%) |
The distribution-job timings above are not complete image publication timings.
### Correctness checks
- Compared 391 distribution files, including permissions and normalized nested JAR contents.
- Compared all four images on both amd64 and arm64: 780 records per architecture covering application files, installed packages, and image configuration, with no missing, added, or changed records.
- JAR comparisons normalized ZIP timestamps, compression, entry order, and specified build-time metadata; this verifies effective content equivalence rather than byte-identical archives.
- The runtime-layer CI built and published all four images with both architectures, passing local platform inspection, Compose, Gremlin CRUD, Standalone smoke tests, and published manifest checks. Functional checks in this flow ran on amd64.
- A separate native ARM experiment passed functional checks on both architectures and final multi-platform publication. That experimental workflow is not included in this PR.
### Successful CI runs
| Validation | Result | CI run |
| --- | --- | --- |
| Runtime layer benchmark, multi-platform build and publication | All 4 jobs passed | [33950351952](https://github.com/lokidundun/incubator-hugegraph/actions/runs/33950351952) |
| Full/scoped distribution benchmark, content comparison, and native architecture validation | All 6 jobs passed | [33953324289](https://github.com/lokidundun/incubator-hugegraph/actions/runs/33953324289) |
| Full/scoped image content comparison on amd64 and arm64 | Both jobs passed | [33953049148](https://github.com/lokidundun/incubator-hugegraph/actions/runs/33953049148) |
These are fork validation runs for the implementation approach. The Maven experiments enabled the same module selection through `MAVEN_ARGS`; this PR places that selection directly in the Dockerfiles. These runs do not replace CI on the final PR commit.
Measurements are single-run observations using GHCR, not the official Docker Hub publication environment. Savings from separate experiments are not additive.
### Commands for local verification
Run from the repository root using Bash.
Build the selected distributions:
```bash
mvn install \
-pl hugegraph-server/hugegraph-dist,hugegraph-pd/hg-pd-dist,hugegraph-store/hg-store-dist \
-am -e -B -ntp \
-Dmaven.test.skip=true \
-Dmaven.javadoc.skip=true
```
Inspect the shared Bake configuration:
```bash
docker buildx bake -f docker/bake.hcl --print
```
Build all four images through the shared Bake flow:
```bash
docker buildx bake -f docker/bake.hcl --progress=plain
```
The default Bake targets include amd64 and arm64. Local multi-platform loading requires a compatible builder and the containerd image store; building ARM64 on an amd64 host also requires emulation.
Check a direct Dockerfile build:
```bash
docker buildx build \
--platform linux/amd64 \
-f hugegraph-server/Dockerfile \
-t hugegraph-standalone:pr-check \
--load .
```
The commands above are build checks; the linked CI runs provide the integration, content-comparison, and publication validation.
## Does this PR potentially affect the following parts?
- [ ] Dependencies
- [ ] Modify configurations
- [ ] The public API
- [x] Other affects: Docker build layer caching and Maven reactor selection.
- [ ] Nope
## Documentation Status
- [ ] `Doc - TODO`
- [ ] `Doc - Done`
- [x] `Doc - No Need`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] perf(docker): reuse runtime layers and scope Maven builds [hugegraph]
Posted by "imbajin (via GitHub)" <gi...@apache.org>.
imbajin merged PR #3194:
URL: https://github.com/apache/hugegraph/pull/3194
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] perf(docker): reuse runtime layers and scope Maven builds [hugegraph]
Posted by "bitflicker64 (via GitHub)" <gi...@apache.org>.
bitflicker64 commented on code in PR #3194:
URL: https://github.com/apache/hugegraph/pull/3194#discussion_r3941731435
##########
hugegraph-server/Dockerfile:
##########
@@ -59,8 +59,10 @@ RUN apt-get -q update \
iproute2 \
vim \
&& apt-get clean \
- && rm -rf /var/lib/apt/lists/* \
- && sed -i "s/^restserver.url.*$/restserver.url=http:\/\/0.0.0.0:8080/g" ./conf/rest-server.properties
+ && rm -rf /var/lib/apt/lists/*
+
+COPY --from=build /pkg/hugegraph-server/apache-hugegraph-server-*/ /hugegraph-server/
Review Comment:
⚠️ With the apt layer now ahead of this `COPY`, its cache key no longer includes the application source, so the layer is reused until the `eclipse-temurin:11-jre-jammy` digest changes. What is lost is the per-source-change reinstall: rebuilding the same commit already hit cache before, but any source change used to force a fresh `apt-get install`, and now nothing short of a base image update does.
This only bites on a registry-cache flow, and that flow is out of tree: `docker/bake.hcl` gates every `cache-to` behind `EXPORT_CACHE`, which defaults to `false`, and no workflow here runs `bake` to build or push. The PR's own numbers show the effect, with eight runtime layers restored in 2.0-9.3 s "without rerunning package installation".
Could you add a documented way to force a reinstall, for example `ARG RUNTIME_DEPS_EPOCH=1` immediately before the apt block in all four files, bumped when packages need refreshing? `--no-cache-filter` is not an option as things stand, since the runtime stage has no `AS` name. A short note on the cache behaviour in `docker/README.md` would help whoever operates the publish flow.
##########
hugegraph-server/Dockerfile:
##########
@@ -28,14 +28,14 @@ ARG MAVEN_ARGS
ARG SOURCE_REVISION=local
RUN --mount=type=cache,id=hugegraph-maven-${SOURCE_REVISION},target=/root/.m2,sharing=locked \
- mvn install $MAVEN_ARGS -e -B -ntp -Dmaven.test.skip=true -Dmaven.javadoc.skip=true \
+ mvn install -pl hugegraph-server/hugegraph-dist,hugegraph-pd/hg-pd-dist,hugegraph-store/hg-store-dist \
+ -am $MAVEN_ARGS -e -B -ntp -Dmaven.test.skip=true -Dmaven.javadoc.skip=true \
Review Comment:
🧹 The module list is hardcoded ahead of `$MAVEN_ARGS`, which is the only Maven knob `docker/bake.hcl` exposes. Maven accumulates repeated `-pl` values rather than letting a later one replace an earlier one, so `MAVEN_ARGS` can still add modules or drop them with a `!` prefix, but it can no longer set the scope outright. The PR description notes that the fork experiments "enabled the same module selection through `MAVEN_ARGS`"; that route closes here.
Drift between the four copies is already covered by the `docker-bake-check` job in `.github/workflows/docker-build-ci.yml`, so this is only about overridability.
Suggested change: hoist the list into a build arg beside the existing `ARG MAVEN_ARGS` and pass it through `_common.args` in `docker/bake.hcl`.
```dockerfile
ARG MAVEN_PROJECTS="hugegraph-server/hugegraph-dist,hugegraph-pd/hg-pd-dist,hugegraph-store/hg-store-dist"
```
with the command becoming `mvn install -pl "$MAVEN_PROJECTS" -am $MAVEN_ARGS ...`. All four files stay byte-identical, so the CI identity check still passes.
##########
hugegraph-server/Dockerfile:
##########
@@ -28,14 +28,14 @@ ARG MAVEN_ARGS
ARG SOURCE_REVISION=local
RUN --mount=type=cache,id=hugegraph-maven-${SOURCE_REVISION},target=/root/.m2,sharing=locked \
- mvn install $MAVEN_ARGS -e -B -ntp -Dmaven.test.skip=true -Dmaven.javadoc.skip=true \
+ mvn install -pl hugegraph-server/hugegraph-dist,hugegraph-pd/hg-pd-dist,hugegraph-store/hg-store-dist \
+ -am $MAVEN_ARGS -e -B -ntp -Dmaven.test.skip=true -Dmaven.javadoc.skip=true \
&& rm ./hugegraph-server/*.tar.gz ./hugegraph-pd/*.tar.gz ./hugegraph-store/*.tar.gz
Review Comment:
🧹 The reactor is scoped but the build context is not, so the caching win is smaller than the benchmark suggests. `.dockerignore` at head excludes only build output, archives, IDE and OS files, `.git`, `.github`, `**/*.md` and the compose files, so `hugegraph-test`, `hg-pd-test`, `hg-store-test`, `hugegraph-cluster-test/**`, `hugegraph-example`, `hg-pd-cli`, `hg-store-cli` and `install-dist` all still land in the context and still feed the `COPY . .` cache key on line 25. Editing any of them therefore invalidates this shared build stage and pays for a full scoped Maven run, for modules the build no longer compiles.
A follow-up rather than a change here, but worth recording. One caveat for whoever picks it up: these directories cannot be ignored wholesale, because the root pom lists them in `<modules>` and Maven fails when a listed module's `pom.xml` is absent, so only their `src/` subtrees can be excluded.
##########
hugegraph-server/Dockerfile-hstore:
##########
@@ -61,8 +57,13 @@ RUN apt-get -q update \
iproute2 \
vim \
&& apt-get clean \
- && rm -rf /var/lib/apt/lists/* \
- && sed -i "s/^restserver.url.*$/restserver.url=http:\/\/0.0.0.0:8080/g" ./conf/rest-server.properties
+ && rm -rf /var/lib/apt/lists/*
+
+COPY --from=build /pkg/hugegraph-server/apache-hugegraph-server-*/ /hugegraph-server/
+# remove hugegraph.properties and rename hstore.properties.template for default hstore backend
+RUN cd /hugegraph-server/conf/graphs \
+ && rm hugegraph.properties && mv hstore.properties.template hugegraph.properties
+RUN sed -i "s/^restserver.url.*$/restserver.url=http:\/\/0.0.0.0:8080/g" ./conf/rest-server.properties
Review Comment:
🧹 Both of these `RUN`s edit only the tree copied on line 62, so they are invalidated together and the split just costs an image layer. This is the one file where that layer is avoidable: the plain server Dockerfile also gained a standalone `sed` layer, but it has a single edit with nothing to fold into.
```suggestion
RUN cd /hugegraph-server/conf/graphs \
&& rm hugegraph.properties && mv hstore.properties.template hugegraph.properties \
&& cd /hugegraph-server \
&& sed -i "s/^restserver.url.*$/restserver.url=http:\/\/0.0.0.0:8080/g" ./conf/rest-server.properties
```
The comment on line 63 then covers only part of what the merged `RUN` does, so it is worth widening at the same time.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] perf(docker): reuse runtime layers and scope Maven builds [hugegraph]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #3194:
URL: https://github.com/apache/hugegraph/pull/3194#issuecomment-5550665798
## [Codecov](https://app.codecov.io/gh/apache/hugegraph/pull/3194?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 93.25%. Comparing base ([`3681148`](https://app.codecov.io/gh/apache/hugegraph/commit/36811483a2040f70ca6923a288a8c28cad0086c0?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`304bea1`](https://app.codecov.io/gh/apache/hugegraph/commit/304bea1c5238eaa33da40cfcf8020c9b170df547?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #3194 +/- ##
=============================================
+ Coverage 37.77% 93.25% +55.48%
+ Complexity 6560 65 -6495
=============================================
Files 800 9 -791
Lines 68960 267 -68693
Branches 9166 22 -9144
=============================================
- Hits 26052 249 -25803
+ Misses 39841 8 -39833
+ Partials 3067 10 -3057
```
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/hugegraph/pull/3194?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] perf(docker): reuse runtime layers and scope Maven builds [hugegraph]
Posted by "bitflicker64 (via GitHub)" <gi...@apache.org>.
bitflicker64 commented on code in PR #3194:
URL: https://github.com/apache/hugegraph/pull/3194#discussion_r4001043655
##########
docker/bake.hcl:
##########
@@ -19,6 +19,14 @@ variable "MAVEN_ARGS" {
default = ""
}
+variable "MAVEN_PROJECTS" {
+ default = "hugegraph-server/hugegraph-dist,hugegraph-pd/hg-pd-dist,hugegraph-store/hg-store-dist"
Review Comment:
🧹 This default is now a fifth copy of the module list, and nothing checks it against the other four. A drift here would go unnoticed.
- `docker-bake-check` diffs the `AS build` stage of the four Dockerfiles, so a change to `ARG MAVEN_PROJECTS=...` there has to land in all four. It never compares that ARG with this variable, and its jq assertion on `bake --print` checks targets, platforms and outputs but not `args`.
- The `docker-build` job runs plain `docker build --build-arg SOURCE_REVISION=...`, so CI builds with the Dockerfile default.
- `bake` always passes this value, so the images from `bake.hcl` use this copy.
If someone later adds a module to the Dockerfile list (a new dist, say) and misses this line, every CI check still passes, but bake builds a different reactor from the one CI tested. With a module like that, `rm ./hugegraph-*/*.tar.gz` or a runtime `COPY --from=build` could then fail only in the bake flow.
Requested change: keep one source of truth. Either set `default = null` here, which makes bake leave the arg unset so the Dockerfile `ARG` default applies while `MAVEN_PROJECTS=... docker buildx bake` still overrides it, or add a jq assertion to `docker-bake-check` that `.target.pd.args.MAVEN_PROJECTS` matches the `ARG MAVEN_PROJECTS` default in `hugegraph-pd/Dockerfile`. `RUNTIME_DEPS_EPOCH` on line 27 duplicates its default the same way. A drift there would only cause one extra cache miss, but the same change covers it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org