Skip to content

Profiling ​

The performance test scripts of the CQL and FHIR Search sections and the transaction test of the Load Testing section can record a profile of Blaze with async-profiler while they run. This page describes how to set up Blaze for profiling and how to run the scripts.

Test Scripts ​

The test scripts under docs/performance/fhir-search and the search-all*.sh scripts under docs/performance/cql run a series of named tests against Blaze. Each script takes the Docker Compose file of the Blaze under test as first argument. The FHIR Search scripts take the base URL of Blaze as optional second argument, which defaults to http://localhost:8080/fhir:

sh
docs/performance/fhir-search/simple-code-search.sh docker-compose.yml

Between tests, the scripts restart Blaze with docker compose up --force-recreate --wait, so that every test starts with empty in-memory caches of Blaze. Each test runs once for warmup and then the number of times given in the REPEATS environment variable, which defaults to 3. Only the runs after the warmup are taken for the statistics.

Docker Setup ​

The scripts run the async-profiler command line tools inside the container of the Compose service blaze. Because the Blaze image doesn't contain async-profiler, it has to be installed on the host and mounted into the container under /opt/async-profiler. Use the Linux release of async-profiler matching the CPU architecture of the container, like linux-x64 or linux-arm64.

In addition, Blaze has to load async-profiler as agent at JVM start. To do so, add -agentpath:/opt/async-profiler/lib/libasyncProfiler.so to the JAVA_TOOL_OPTIONS environment variable. The scripts then control the already loaded agent instead of attaching to the running JVM.

The service also needs a healthcheck, so that docker compose up --wait waits until Blaze is ready.

yaml
services:
  blaze:
    image: "samply/blaze:1.14.0@sha256:fdfc93c77458b26dbfbc2cdc2cef60e285ae3870253c6aa62b783999f15c7200"
    environment:
      JAVA_TOOL_OPTIONS: "-Xmx16g -agentpath:/opt/async-profiler/lib/libasyncProfiler.so"
    ports:
    - "8080:8080"
    volumes:
    - "blaze-data:/app/data"
    - "/opt/async-profiler:/opt/async-profiler:ro"
    healthcheck:
      test: [ "CMD", "wget", "--spider", "http://localhost:8080/health" ]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 30s
      start_interval: 1s
volumes:
  blaze-data:

If async-profiler is mounted to another directory inside the container, change the agent path accordingly and set the environment variable ASYNC_PROFILER_HOME to that directory when running the scripts.

Running a Profile ​

The test to profile is selected by the PROFILE environment variable, which holds a glob pattern matching test names. The names of the tests are the second arguments of the profile calls in the scripts, like count-72514-3 in fhir-search/simple-code-search.sh or observation-17861-6 in cql/search-all.sh.

sh
PROFILE=count-72514-3 docs/performance/fhir-search/simple-code-search.sh docker-compose.yml

With PROFILE set, the scripts run only the tests matching the pattern and skip all others. A test runs on a freshly restarted Blaze. The profiler starts after the warmup run and stops after the last run, so that the profile covers only the measured runs.

The scripts write three files into the current directory, named after the test:

FileContent
<name>.jfrthe recording in the JDK Flight Recorder format, with every sample including its thread and its timestamp
<name>.foldedthe folded stacks with the thread as first frame, suitable for diffing and further processing
<name>.htmlan interactive flame graph

Environment Variables ​

VariableDescriptionDefault
PROFILEglob pattern of the names of the tests to profile; nothing is profiled if unset
PROFILE_EVENTthe async-profiler event, like wall, cpu, alloc or lockwall
REPEATSthe number of runs after the warmup, which are the profiled ones; increase it to get more samples of fast tests3
TESTglob pattern of the names of the tests to run; overrides the selection by PROFILE, like to run more tests than are profiledPROFILE
ASYNC_PROFILER_HOMEthe directory of async-profiler inside the blaze container/opt/async-profiler

For example, the following records allocations over 32 measured runs:

sh
PROFILE=count-72514-3 PROFILE_EVENT=alloc REPEATS=32 docs/performance/fhir-search/simple-code-search.sh docker-compose.yml

TEST without PROFILE runs the selected tests without profiling, which is useful to repeat a single measurement.

Transaction Load Test ​

The transaction test is run by k6 instead of a test script, so it's profiled by the profile-transaction.sh script in docs/performance/load-testing. It takes the system whose docker-compose-<system>.yml Blaze runs with as argument and profiles the single concurrency level given in the VUS environment variable, which is required, because every level has its own ratio of per-batch to per-entry work. Blaze runs the image the Compose file selects, which is the locally built blaze:latest unless IMAGE names another:

sh
VUS=128 docs/performance/load-testing/profile-transaction.sh LEA79

Like reset.sh in front of a run of the sweep, the script restarts Blaze with an empty database. It adds docker-compose-profiling.yml to the Compose file of the system, which mounts async-profiler from /opt/async-profiler on the host and loads its agent via JDK_JAVA_OPTIONS. The Java launcher reads that variable in addition to JAVA_TOOL_OPTIONS, so the JVM options of the system stay as they are, and the Compose files of the systems stay without the agent, so that the runs of the sweep aren't affected.

The script then runs transaction.js and starts the profiler once the warmup in the setup of the test has finished, so that the profile covers the measured scenario only. The profiler stops when k6 exits. In addition to the three files described above, named transaction-<system>-c<VUS>, the script writes the output of k6 into <name>.log, which contains the throughput and the latencies of the profiled run.

PROFILE_EVENT, PROFILE_INTERVAL and ASYNC_PROFILER_HOME apply as described above. BASE, DURATION and WARMUP are passed on to transaction.js.

The folded stacks start with the thread, so the profile of a single thread, like the indexer thread of the main node, can be selected by its name:

sh
grep '^\[main-indexer' transaction-LEA79-c128.folded > main-indexer.folded