Performance and benchmarking
A useful performance measurement answers a specific question: how much work does this operation take under these conditions? For an ExecKernel integration, that might mean evaluating one choice, completing a session, saving its state or serving an HTTP request. Choose the scope first so the result describes the work your application actually cares about.
ExecKernel includes a sequential measurement harness that records individual operation samples and checks that the sessions finish correctly. It can turn those samples into a measured reference and compare a later run with it. This guide follows that path, then shows why a run with a different protocol must be kept separate.
Define the work before measuring
Section titled “Define the work before measuring”The harness in benchmarks/measure.php provides five scenarios:
| Scenario | Work exercised |
|---|---|
S1 |
A small graph, following nine transitions to its terminal. |
S2 |
A longer path through the medium graph. |
S3 |
A larger graph and a longer session path. |
S4 |
A path with a heavier set of built-in conditions. |
S5 |
The medium path with local filesystem save/load and publication after each confirmed save. |
Each scenario follows its declared path and verifies the returned nodes, payload types and complete history. Failed or incomplete runs cannot serve as valid measurement evidence. S1–S4 do not include a session store; S5 measures the supplied local filesystem integration, not your remote database or HTTP deployment.
Use a scenario that answers your question. A small graph can help compare changes to the execution path, while a storage question needs storage in the workload. For the time seen by a browser calling your API, measure that HTTP path separately, including the network, ingress, request handling and storage that you actually use.
Keep the measurement protocol
Section titled “Keep the measurement protocol”This procedure assumes an ExecKernel source checkout with its PHP dependencies available. The measurement harness and its graph fixtures live in that checkout; an application using only the installed library does not automatically have the same development tools. See Installation and requirements for setup, and run the following commands from the checkout root.
Record the source revision and give the fixed measurement environment a recognizable identity:
BENCHMARK_REVISION="$(git rev-parse HEAD)"BENCHMARK_ENVIRONMENT='my-fixed-environment'The revision identifies the code you are testing. Use the environment name for the same host/container configuration across runs; the report also records concrete fields such as PHP version, CPU, limits and harness hashes. Keep uncommitted changes separately identified, because a Git commit ID alone cannot describe them.
Measure the small scenario with twenty sessions per repetition, five repetitions and three warm-up sessions:
php benchmarks/measure.php \ --scenario=S1 \ --sessions=20 \ --repetitions=5 \ --warmup=3 \ --mode=plain \ --budget-clock=null_explicit \ --source-revision="$BENCHMARK_REVISION" \ --environment-id="$BENCHMARK_ENVIRONMENT" \ > benchmark-measure-a.jsonThe warm-up sessions run first and are excluded from the recorded samples. The measured portion completes 5 × 20 = 100 sessions. With nine transitions per session, it records 900 transition samples, as well as 100 start samples and 100 whole-session samples.
plain builds the workload without the Prometheus collector. The alternative prometheus mode includes that collector and therefore describes a different measurement environment. Keep the same mode when comparing runs.
Separate measurement time from execution budgets
Section titled “Separate measurement time from execution budgets”The harness measures elapsed durations with hrtime(). It also fixes the logical time used by the graph so time-dependent rules receive controlled input. These serve different purposes: one measures elapsed work; the other makes graph decisions repeatable.
--budget-clock controls the stopwatch used for the runtime’s execution budgets. null_explicit explicitly disables that stopwatch in the workload, while monotonic enables a monotonic runtime budget clock. The external duration measurement still runs in both modes. Choose the mode deliberately and retain it in the protocol; a budget threshold is not a measured latency. Execution budgets and circuit breakers explains what the runtime does when its own limits are reached.
Read the evidence before the summary
Section titled “Read the evidence before the summary”The measurement file uses schema execkernel.performance.v2 and kind: measurement. It retains the raw samples, so summaries can be recomputed rather than accepted from a supplied percentile field.
| Field | What it tells you |
|---|---|
source_revision |
The declared revision being measured. |
environment |
PHP and machine characteristics, resource settings, dependency and harness hashes, collector mode and budget clock. |
protocol |
Sessions per repetition, repetition count, warm-up count and measurement scope. |
workload |
Graph identity, chosen path, conditions and storage mode. |
start_ns, transition_ns, session_ns |
Individual measured durations, in nanoseconds. |
elapsed_ns |
Total measured time for one repetition, used to calculate throughput. |
memory_peak_bytes, memory_allocated_peak_bytes |
Peaks for used PHP memory and allocated memory during that repetition. |
The summarizer computes nearest-rank percentiles from the individual samples and expresses latency in milliseconds. Throughput divides the number of completed transitions or sessions by the measured elapsed time. The total includes the workload’s verification and cleanup, so it is not simply the inverse of the median transition duration.
The memory peak includes the already loaded graph and runtime. It is not a measurement of memory allocated by one particular choice.
Create a measured reference
Section titled “Create a measured reference”Generate a readable report and a reference from the first measurement:
php bin/execkernel bench --report \ --measurement=benchmark-measure-a.json \ --output=benchmark-report-a.md \ --output-json=benchmark-reference.jsonThe Markdown report helps you review the result. The JSON output has kind: reference: it contains the validated summaries, their environment and protocol, an evidence digest and comparison tolerances. Keep the original measurement alongside it so you can examine the underlying samples.
Choose new output filenames. These report output options reject an existing artifact instead of replacing it; the shell redirection used by the measurement command has different behavior and can overwrite a file.
A reference is an observation you choose to compare against. It is not a service-level objective or a promise to users. The repository’s historical benchmarks/baselines.json targets are not measured evidence for this procedure; the comparator rejects them as a measured reference.
Run and compare another measurement
Section titled “Run and compare another measurement”Repeat the same command with the same environment and protocol, writing a second file:
php benchmarks/measure.php \ --scenario=S1 \ --sessions=20 \ --repetitions=5 \ --warmup=3 \ --mode=plain \ --budget-clock=null_explicit \ --source-revision="$BENCHMARK_REVISION" \ --environment-id="$BENCHMARK_ENVIRONMENT" \ > benchmark-measure-b.jsonThen compare it with the reference:
php bin/execkernel bench --compare \ --baseline=benchmark-reference.json \ --report=benchmark-measure-b.jsonFor the recorded measurement A and independent measurement B, the selected results were:
| Measured value | A | B |
|---|---|---|
| Completed sessions | 100 | 100 |
| Completed transitions | 900 | 900 |
| Transition p50 | 0.0719 ms | 0.0723 ms |
| Transition p95 | 0.0797 ms | 0.0803 ms |
| Transition p99 | 0.0828 ms | 0.0845 ms |
| Completed transitions per second | 12703.7 | 12552.9 |
| Peak used PHP memory | 2.84 MiB | 2.84 MiB |
These are two local runs of the same revision, not a before/after optimization. They used PHP 8.3.37, a container limited to one CPU and 256 MiB, a PHP memory limit of 128M, and CLI OPcache disabled. The reports retain the exact CPU, kernel, quotas and hashes. The values illustrate how to read comparable evidence; your application workload and environment will produce their own measurements.
Using the reference generated from A, the comparison with B exited with 0 and printed:
All benchmark scenarios are within baseline.The generated reference allows a 20% increase in latency, a 10% decrease in throughput and a 20% increase in memory. Those are comparison tolerances, not limits enforced on running sessions. Latency checks cover p50, p95 and p99 for starts, transitions and whole sessions; maximum duration is retained for inspection but is not used as a regression threshold.
A comparison may use a different source revision to assess a code change. Environment, protocol and workload must still match. If a change also alters the harness or dependency fingerprint, the reports no longer describe the same controlled experiment and require a separately established reference.
Reject a different protocol
Section titled “Reject a different protocol”To see the boundary, make a third actual measurement with ten sessions per repetition instead of twenty, retaining the other settings:
php benchmarks/measure.php \ --scenario=S1 \ --sessions=10 \ --repetitions=5 \ --warmup=3 \ --mode=plain \ --budget-clock=null_explicit \ --source-revision="$BENCHMARK_REVISION" \ --environment-id="$BENCHMARK_ENVIRONMENT" \ > benchmark-measure-incompatible.json
php bin/execkernel bench --compare \ --baseline=benchmark-reference.json \ --report=benchmark-measure-incompatible.jsonThe recorded third measurement completed successfully, but the comparison exited with 2 and reported:
Incomparable benchmark protocol.The run is valid evidence for its own protocol. It cannot answer the same comparison question as the reference without changing that question. Keep it as a separate experiment or repeat the intended protocol; changing metadata to disguise the difference would discard the meaning of the measurement.
| Comparison result | What to do next |
|---|---|
Exit 0 |
Review the measured change within the selected tolerances and scope. |
Exit 1 |
Investigate the listed regressions: samples, environment activity and the code change. |
Exit 2 |
Correct invalid or missing evidence, or separate incompatible environments, protocols or workloads. |
One run cannot explain the cause of a slowdown. Inspect the distribution and the surrounding conditions, then repeat a controlled experiment when there is a concrete question to resolve.
Extend the scope when your question requires it
Section titled “Extend the scope when your question requires it”PHPBench can help inspect smaller components or repeated workloads. Its iteration averages are different evidence from the individual start/choice/session samples used here. The reporting tools also accept supported k6, Locust and metrics summaries, but an HTTP load report needs its own request mix, concurrency, persistence and environment description.
Keep those experiments separate from a sequential engine comparison. To investigate a slow production request, combine appropriately scoped measurements with Metrics and operational monitoring and Tracing and error telemetry. The useful outcome is a specific decision supported by the work you measured.