Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tools/healthsamurai-bench/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# The repository ignores *.log; the k6 logs under results/ are the evidence for
# the numbers in README.md and must be tracked.
!results/**/*.log
103 changes: 103 additions & 0 deletions tools/healthsamurai-bench/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# HealthSamurai benchmark harness (HFS next to WSO2)

Local harness used on 2026-11-18 to run HFS against the upstream
[HealthSamurai FHIR Server Performance Benchmark](https://github.com/HealthSamurai/fhir-server-performance-benchmark),
next to WSO2, with upstream's own Docker Compose stack, k6 suites and container
limits. It is separate from the CI workflow `.github/workflows/fhir-benchmark.yml`,
which runs HFS natively on a runner. Tracked in #2612.

Nothing here is pushed to or proposed to HealthSamurai.

## What is here

| Path | What |
|---|---|
| `hfs/Dockerfile`, `hfs/Dockerfile.dockerignore` | Release build of HFS (R4 only, clang + lld, 8 MB stack). `FEATURES` build arg picks the Cargo features. The own ignore file is needed because the build context's `.dockerignore` excludes `**/*.rs`. |
| `docker-compose.hfs.yaml` | HFS on Postgres: 8 CPU / 24 GB, database `hfs` on upstream's shared `postgres:18`, `HFS_PG_MAX_CONNECTIONS=32`. |
| `docker-compose.hfses.yaml` | HFS on Postgres + Elasticsearch, Elasticsearch **inside** the 8 CPU / 24 GB budget: HFS 6 CPU / 20 GB, Elasticsearch 2 CPU / 4 GB (2 GB heap). |
| `docker-compose.hfses-wide.yaml` | The same, with Elasticsearch on **its own** 8 CPU / 30 GB, like upstream's database containers (HFS keeps 8 CPU / 24 GB). |
| `upstream-e6a4941.patch` | The two upstream files that must change: `runner.sh` (adds the `hfs` and `hfses` servers) and `infra/postgres/init/create-database.sql` (`CREATE DATABASE hfs;`). Apply on upstream commit `e6a4941`. |
| `scripts/run-matrix.sh` | HFS (Postgres) and WSO2, 3 rounds, alternating which goes first, fresh database before each run. |
| `scripts/run-es.sh` | HFS Postgres + Elasticsearch, 3 rounds, fresh Elasticsearch volume and database per round, drain gate between import and search. |
| `scripts/report.py`, `scripts/analyze.py` | Medians of 3 rounds, spread and ratios. `analyze.py` also writes `bench-runs.json` (one row per server x suite x round). |
| `results/` | k6 logs per run (`R<round>-<server>-<suite>.log`) and the JSON metrics in `results/data/`. |

`results/es-shared-budget/failed-R2-import-9-errors/` is the first attempt of
round 2 (9 of 2005 import requests failed, cause unknown). It is kept as
evidence and is not part of any median.

## How to rerun

1. Clone upstream and apply the patch:
```bash
git clone https://github.com/HealthSamurai/fhir-server-performance-benchmark
cd fhir-server-performance-benchmark
git checkout e6a4941
git apply <hfs>/tools/healthsamurai-bench/upstream-e6a4941.patch
cp -r <hfs>/tools/healthsamurai-bench/hfs .
cp <hfs>/tools/healthsamurai-bench/docker-compose.hfs*.yaml .
```
2. Build the images from a clean `git archive` export of the HFS commit to
measure (the working tree can hold build output and secrets):
```bash
git -C <hfs> archive --format=tar --prefix=ctx/ <commit> | tar -x -C <ctx-parent>
docker build -f hfs/Dockerfile -t hfs-bench:main-c52ff36 <ctx>
docker build -f hfs/Dockerfile --build-arg FEATURES="R4,sqlite,postgres,elasticsearch" \
-t hfs-bench:main-c52ff36-es <ctx>
```
The tags are the ones the compose files use; change both if you build another commit.
3. Run, one server at a time on a quiet machine:
```bash
export BENCH=$PWD
bash <hfs>/tools/healthsamurai-bench/scripts/run-matrix.sh # HFS Postgres + WSO2
ES_COMPOSE=docker-compose.hfses.yaml OUT=$PWD/results-local-es \
bash <hfs>/tools/healthsamurai-bench/scripts/run-es.sh # ES inside the budget
ES_COMPOSE=docker-compose.hfses-wide.yaml OUT=$PWD/results-local-es-wide \
bash <hfs>/tools/healthsamurai-bench/scripts/run-es.sh # ES on its own budget
```
Round counts come from `ROUNDS` (default `1 2 3`). The scripts start the
`postgres`, `prometheus` and `tgz` containers they need, and abort a round
if HFS does not log `Composite storage initialized`. On Windows run them
from Git Bash; they set `MSYS2_ARG_CONV_EXCL="*"`.
4. Analyse: point `RESULTS_PG`, `RESULTS_ES_SHARED` and `RESULTS_ES_OWN` at the
new result folders (by default the scripts read `results/` next to them) and
run `python scripts/analyze.py`.

## Conditions of the recorded run

- HFS built from main commit `c52ff36`, FHIR R4, release profile.
- Host: Docker Desktop on WSL2, VM with 44 GiB of memory and 20 vCPU. Upstream's
reference machine has 64 cores, 500 GB of memory and NVMe, so compare ratios,
not absolute values.
- Upstream suites and order: prewarm (10 VUs, 30 s), CRUD (300 VUs, 4 min),
import (20 VUs, 1000 Bundles), search (30 VUs, 2 min); no VACUUM.
- Postgres: upstream's `postgres:18` (8 CPU / 30 GB, `postgres.conf` unchanged),
one database per server, recreated before each run.
- Elasticsearch: `elasticsearch:8.15.0`, single node, 2 GB heap, synchronous
composite mode (`HFS_COMPOSITE_SYNC_MODE=synchronous`, write refresh `wait_for`,
refresh interval 50 ms, repair interval 60 s), the setting the CI benchmark uses.
- WSO2: `ghcr.io/wso2/fhir-server:latest` (reports 2.2.0). WSO2 was measured once,
not repeated for the Elasticsearch runs, because the conditions are identical.

## Results (medians of 3 rounds)

| Suite | HFS Postgres | HFS + ES, shared budget | HFS + ES, own budget | WSO2 |
|---|---:|---:|---:|---:|
| Prewarm, req/s | 2033 | 81 | 173 | 1826 |
| CRUD, req/s | 2567 | 267 | 964 | 2793 |
| Import, total seconds (lower is better) | 736 | 657 | 496 | 833 |
| Search, req/s | 2646 | 238 | 1094 | 2273 |

Run `scripts/analyze.py` for the full table with round ranges, p50/p95 and ratios.

## Caveats

- With Elasticsearch, writes are capped by the synchronous refresh. An
asynchronous run was not done.
- Search with Elasticsearch is slower than HFS on Postgres alone in both
budgets (p50 102 ms shared and 16.8 ms own, against 7.9 ms); the cause was not investigated.
- The k6 import check accepts any HTTP 200, and k6 reports p90 and p95 only.
- The elasticsearch document count after import (1,965,870) differs from the
Postgres resource count (1,632,062); it was not reconciled and probably
counts contained and nested documents.
- Which of the two Elasticsearch budgets HealthSamurai would accept is unknown.
41 changes: 41 additions & 0 deletions tools/healthsamurai-bench/docker-compose.hfs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Local override: adds HFS (Helios FHIR Server) to the benchmark stack.
# Same shape as the wso2 service: 8 CPU / 24G, shared postgres:18, own database.
# Use with: ./runner.sh -f docker-compose.yaml -f docker-compose.hfs.yaml ...
# Image is built locally (see hfs/Dockerfile); it is never pulled.
services:
hfs:
container_name: perf-hfs
image: hfs-bench:main-c52ff36
pull_policy: never
depends_on:
postgres:
condition: service_healthy
deploy:
resources:
limits:
cpus: '8'
memory: 24G
ports:
- "13130:8080"
environment:
HFS_STORAGE_BACKEND: postgres
HFS_DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/hfs"
HFS_PG_MAX_CONNECTIONS: 32
HFS_REQUEST_TIMEOUT: 900
HFS_MAX_BODY_SIZE: 209715200
HFS_LOG_LEVEL: info

# Sidecar healthcheck (same pattern as wso2-checker): the hfs image has no curl.
hfs-checker:
container_name: perf-hfs-hc
image: curlimages/curl
command: ["-c", "trap : TERM INT; sleep infinity & wait"]
depends_on:
hfs:
condition: service_started
entrypoint: /bin/sh
healthcheck:
test: curl -f http://hfs:8080/metadata
interval: 10s
start_period: 30s
retries: 10
72 changes: 72 additions & 0 deletions tools/healthsamurai-bench/docker-compose.hfses-wide.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Local override: HFS with Postgres (storage) + Elasticsearch (search), next to WSO2.
# Variant B: ES is a separate engine like postgres and mssql upstream (8 CPU / 30G each): HFS 8 CPU / 24G + ES 8 CPU / 30G.
# Use with: ./runner.sh -f docker-compose.yaml -f docker-compose.hfs.yaml -f docker-compose.hfses.yaml ...
services:
elasticsearch:
container_name: perf-es
image: elasticsearch:8.15.0
deploy:
resources:
limits:
cpus: '8'
memory: 30G
environment:
discovery.type: single-node
xpack.security.enabled: "false"
ES_JAVA_OPTS: "-Xms2g -Xmx2g -Xlog:disable -Xlog:all=warning:stderr"
ports:
- "13132:9200"
volumes:
- perf_esdata:/usr/share/elasticsearch/data
healthcheck:
test: curl -sf "http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=1s" -o /dev/null
interval: 5s
timeout: 5s
retries: 40

hfses:
container_name: perf-hfses
image: hfs-bench:main-c52ff36-es
pull_policy: never
depends_on:
postgres:
condition: service_healthy
elasticsearch:
condition: service_healthy
deploy:
resources:
limits:
cpus: '8'
memory: 24G
ports:
- "13131:8080"
environment:
HFS_STORAGE_BACKEND: postgres-elasticsearch
HFS_DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/hfses"
HFS_ELASTICSEARCH_NODES: "http://elasticsearch:9200"
HFS_ELASTICSEARCH_INDEX_PREFIX: hfs
HFS_COMPOSITE_SYNC_MODE: synchronous
HFS_ELASTICSEARCH_WRITE_REFRESH: wait_for
HFS_ELASTICSEARCH_REFRESH_INTERVAL: 50ms
HFS_COMPOSITE_SYNC_REPAIR_INTERVAL: 60
HFS_PG_MAX_CONNECTIONS: 32
HFS_REQUEST_TIMEOUT: 900
HFS_MAX_BODY_SIZE: 209715200
HFS_LOG_LEVEL: info

hfses-checker:
container_name: perf-hfses-hc
image: curlimages/curl
command: ["-c", "trap : TERM INT; sleep infinity & wait"]
depends_on:
hfses:
condition: service_started
entrypoint: /bin/sh
healthcheck:
test: curl -f http://hfses:8080/metadata
interval: 10s
start_period: 60s
retries: 60

volumes:
perf_esdata:
72 changes: 72 additions & 0 deletions tools/healthsamurai-bench/docker-compose.hfses.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Local override: HFS with Postgres (storage) + Elasticsearch (search), next to WSO2.
# Budget decision: ES counts INSIDE the 8 CPU / 24G that WSO2 gets: HFS 6 CPU / 20G + ES 2 CPU / 4G.
# Use with: ./runner.sh -f docker-compose.yaml -f docker-compose.hfs.yaml -f docker-compose.hfses.yaml ...
services:
elasticsearch:
container_name: perf-es
image: elasticsearch:8.15.0
deploy:
resources:
limits:
cpus: '2'
memory: 4G
environment:
discovery.type: single-node
xpack.security.enabled: "false"
ES_JAVA_OPTS: "-Xms2g -Xmx2g -Xlog:disable -Xlog:all=warning:stderr"
ports:
- "13132:9200"
volumes:
- perf_esdata:/usr/share/elasticsearch/data
healthcheck:
test: curl -sf "http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=1s" -o /dev/null
interval: 5s
timeout: 5s
retries: 40

hfses:
container_name: perf-hfses
image: hfs-bench:main-c52ff36-es
pull_policy: never
depends_on:
postgres:
condition: service_healthy
elasticsearch:
condition: service_healthy
deploy:
resources:
limits:
cpus: '6'
memory: 20G
ports:
- "13131:8080"
environment:
HFS_STORAGE_BACKEND: postgres-elasticsearch
HFS_DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/hfses"
HFS_ELASTICSEARCH_NODES: "http://elasticsearch:9200"
HFS_ELASTICSEARCH_INDEX_PREFIX: hfs
HFS_COMPOSITE_SYNC_MODE: synchronous
HFS_ELASTICSEARCH_WRITE_REFRESH: wait_for
HFS_ELASTICSEARCH_REFRESH_INTERVAL: 50ms
HFS_COMPOSITE_SYNC_REPAIR_INTERVAL: 60
HFS_PG_MAX_CONNECTIONS: 32
HFS_REQUEST_TIMEOUT: 900
HFS_MAX_BODY_SIZE: 209715200
HFS_LOG_LEVEL: info

hfses-checker:
container_name: perf-hfses-hc
image: curlimages/curl
command: ["-c", "trap : TERM INT; sleep infinity & wait"]
depends_on:
hfses:
condition: service_started
entrypoint: /bin/sh
healthcheck:
test: curl -f http://hfses:8080/metadata
interval: 10s
start_period: 60s
retries: 60

volumes:
perf_esdata:
28 changes: 28 additions & 0 deletions tools/healthsamurai-bench/hfs/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Local-only image for benchmarking HFS next to WSO2.
# Build context = a clean `git archive` export of HFS main (see ../README-hfs.md).
# Same release build and linker flags as HFS's own fhir-benchmark workflow
# (clang + lld, 8 MB stack), FHIR R4 only, `ui` left out.
FROM rust:1-trixie AS build
RUN apt-get update && \
apt-get install -y --no-install-recommends clang lld cmake pkg-config libssl-dev && \
rm -rf /var/lib/apt/lists/*
WORKDIR /src
COPY . .
RUN mkdir -p /root/.cargo && printf '[target.x86_64-unknown-linux-gnu]\nlinker = "clang"\nrustflags = ["-C", "link-arg=-fuse-ld=lld", "-C", "link-arg=-Wl,-zstack-size=8388608"]\n' > /root/.cargo/config.toml
ARG FEATURES="R4,sqlite,postgres"
RUN cargo build --release -p helios-hfs --no-default-features --features "${FEATURES}"

FROM debian:trixie-slim
RUN apt-get update && \
apt-get install -y --no-install-recommends libssl3t64 ca-certificates && \
rm -rf /var/lib/apt/lists/*
RUN groupadd -g 1000 helios && useradd -u 1000 -g helios -m helios
WORKDIR /app
COPY --from=build /src/target/release/hfs /app/hfs
COPY --from=build /src/data /app/data
ENV HFS_SERVER_HOST=0.0.0.0 \
HFS_SERVER_PORT=8080 \
HFS_DATA_DIR=/app/data
USER helios
EXPOSE 8080
ENTRYPOINT ["/app/hfs"]
6 changes: 6 additions & 0 deletions tools/healthsamurai-bench/hfs/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Used instead of the context's own .dockerignore (which excludes **/*.rs because
# HFS's regular image only copies a prebuilt binary). Here we compile from source.
target/
.git/
**/node_modules/
**/__pycache__/
Loading