Skip to content
Merged
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
9 changes: 9 additions & 0 deletions LIMITATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ weights and remeasure overhead before presenting historical observations as
current-version claims. This short probe does not establish sampling accuracy,
capacity, or 72h stability.

## Experimental ZTS compatibility

The [PHP ZTS/ext-parallel experiment](reports/2026-11-19-zts-parallel.md) covers one pinned
Linux/PHP/extension combination; its per-runtime collection/spool scenarios pass. JSON returns
the harness's diagnostics, not profiler output, and is not a library requirement. A separate
Future array-result control crashes without either Excimer or Tracewick loaded; that API is
outside Tracewick's profiling/spool path. Long-term stability, arbitrary objects crossing
runtimes and other versions are untested. No NTS/ZTS overhead comparison was measured.

## Comparisons

- No marketing bake-off against Arc Lamp, Excimetry, or eBPF agents in v1.
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ Pinned k6: `grafana/k6:1.8.2` (`make k6-version`). First `make up` compiles Exci
| [scenarios/](scenarios/) | Named profiles |
| [reports/](reports/) | Checked-in reports + template |

The [PHP ZTS/ext-parallel experiment](reports/2026-11-19-zts-parallel.md) records
passing thread-local Excimer/Tracewick collection/spool checks and a separate Future
result-transfer crash outside the profiling path. It is exploratory compatibility evidence,
not a capacity or overhead result.

## Recorded overhead and long-run behavior

**Historical measurements on core/agent 0.1.0, not current-version performance claims.**
Expand Down
14 changes: 14 additions & 0 deletions experiments/zts-parallel/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ARG PHP_IMAGE=php:8.5.12-zts-bookworm@sha256:c6a2606c831a21992c2cdd0ae5a4e87af02348c4c3f66621bfb8b87702977ee3
FROM ${PHP_IMAGE}

# Supply the pinned public extension checkouts as named build contexts.
COPY --from=excimer / /tmp/excimer/
COPY --from=parallel / /tmp/parallel/
RUN cd /tmp/excimer \
&& phpize && ./configure --enable-excimer && make -j2 && make install \
&& cd /tmp/parallel \
&& phpize && ./configure --enable-parallel && make -j2 && make install \
&& docker-php-ext-enable excimer parallel \
&& rm -rf /tmp/excimer /tmp/parallel

CMD ["php", "--version"]
95 changes: 95 additions & 0 deletions experiments/zts-parallel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# PHP ZTS / ext-parallel compatibility probe

Opt-in experiment: [methodology](../../METHOD.md), [limitations](../../LIMITATIONS.md),
[recorded results](../../reports/2026-11-19-zts-parallel.md).
This uses fixed-duration CLI work instead of k6 because it tests interpreter/thread isolation,
not HTTP capacity or application overhead. Nothing runs on the occupied soak server.

The tested per-runtime profiling/spool scenarios pass. JSON messages return only the harness's
diagnostics through Future; the library writes its profiles inside the runtime and requires no
JSON result-transfer protocol. The standalone array-result crash is outside that profiling path.

## Build and run

Requirements: Docker with named build contexts, Git, Python 3, a local core checkout with
Composer runtime dependencies installed, and Linux `/proc`. The image pins PHP 8.5.12 ZTS
by digest, Excimer 1.2.7 and parallel 1.2.15 by verified source commits. No PHP code is patched.

```bash
bash experiments/zts-parallel/build.sh
python3 experiments/zts-parallel/run.py \
--core /absolute/path/to/tracewick --core-ref '<full-tested-commit>' \
--output "$PWD/reports/_local/zts-parallel" --repeats 3
python3 -m unittest discover -s experiments/zts-parallel -p 'test_*.py' -v
```

Use an unchanged checkout and record its exact commit. The runner hashes `src/` before and
after the campaign. The recorded campaign used a `git archive` of the report's core revision
and its runtime `psr/log` 3.0.2 dependency. A version label alone is not source verification.

Each case gets a separate container, no network, a 2-CPU quota, 512 MiB memory and 128-PID
limit. Two case containers may run simultaneously on the shared host. A 20-second container
timeout escalates to KILL; a 30-second host watchdog also removes the named container.
Elapsed container startup/teardown time is retained for debugging, not an overhead result.

The recorded containers use the image's default root user and only disposable output mounts.
Spool directories/files are intentionally `0700`/`0600`; to export them without changing modes,
read the output mount from a container, for example:

```bash
docker run --rm --network none -v "$PWD/reports/_local/zts-parallel:/data:ro" \
tracewick-zts-parallel:8.5 tar -czf - -C /data . > dataset.tar.gz
```

## Scenarios and checks

- Unprofiled control, native Excimer, UoW and Continuous: four worker interpreters and the
parent execute distinct marker functions, wall and CPU modes, three repeats.
- Parent-only profiling checks that unprofiled worker stacks do not appear in the parent.
- One sleeping worker beside a busy worker distinguishes wall time from thread CPU time.
- UoW reuse: one profiler per runtime, 25 sequential tasks; no per-task profiler creation.
- Churn: 20 generations of four runtimes with native/UoW profilers; thread count after close.
- UoW shutdown: register shutdown delivery and leave profiling active until runtime close.

Checks require marker presence and absence of foreign markers, at least 50 ms of common work
overlap in concurrent cases, correct labels, no sampler/swallowed/drop/skip/failure diagnostics,
exact profile-to-decoded-spool weights, shutdown spool presence and no surviving worker threads
after churn. Sleeping CPU cases may correctly have zero events. Short reuse tasks may also be
empty; aggregate presence is checked, not a guarantee that every task receives a sample.
Native callbacks read an interpreter-local actor marker; OS TIDs are read outside callbacks.

`ProbeSink` writes real spool v2/compact-stacks and pprof outside the callback. The report's
dataset retains both, stdout/stderr and the complete numerical results. To check pprof files
after extracting the archive, use `go tool pprof -raw FILE.pprof`. Delivery to Pyroscope/agent
is not exercised here. Each runtime creates and owns its profiler; objects are never shared
between interpreters. The main matrix returns scalar JSON strings through Future.

## Standalone controls

These use the same image and a read-only mount of this experiment at `/probe`:

```bash
docker run --rm --network none -v "$PWD/experiments/zts-parallel:/probe:ro" \
tracewick-zts-parallel:8.5 timeout --kill-after=2s 15s php /probe/minimal.php concurrent-trace

# Independent crash reproducer: only parallel is loaded, no core mount or Excimer.
docker run --rm --network none -v "$PWD/experiments/zts-parallel:/probe:ro" \
tracewick-zts-parallel:8.5 timeout --kill-after=2s 15s \
php -n -d extension=parallel.so /probe/literal-return.php array
# Change the last argument to json for the matched serialized-result control.
```

`literal-bootstrap.php` / `literal-return.php` reduce the initial probe crash to userland
fixtures and parallel. The array case is expected to exit 139 on the measured combination;
keep that failure as evidence, not a successful profiling result. JSON avoided this particular
reproducer; it is not a universal workaround or proof of the root C-level cause.

`edge.php MODE KIND` adds isolated active-profiler exception/kill checks. Supply the same
`/probe` and `/core` mounts plus a writable `/output`; MODE is `native` or `uow`, KIND is
`exception` or `kill`. A Channel barrier confirms sampling has started before kill. Use an
outer timeout as above. Kill does not promise profile delivery; normal exception cleanup uses
`finally`, and the runtime is then checked for reuse. The report records one run per edge case.

This is not an ASan/TSan run, long memory soak, production support declaration, cross-version
matrix, or test of forking with existing timers. Bootstrap/core sources must remain available
to every runtime. No automatic ZTS CI or production dependency is introduced.
15 changes: 15 additions & 0 deletions experiments/zts-parallel/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -euo pipefail

probe_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
source_dir=$(mktemp -d)
trap 'rm -rf -- "$source_dir"' EXIT
git clone --quiet --depth 1 --branch 1.2.7 \
https://github.com/wikimedia/mediawiki-php-excimer.git "$source_dir/excimer"
git clone --quiet --depth 1 --branch v1.2.15 \
https://github.com/krakjoe/parallel.git "$source_dir/parallel"
test "$(git -C "$source_dir/excimer" rev-parse HEAD)" = 23f541b9d970db0524a1b2506b4df727e5e59998
test "$(git -C "$source_dir/parallel" rev-parse HEAD)" = f62fab1225f687de60d789002c9b49467d3e04de
docker build --build-context "excimer=$source_dir/excimer" \
--build-context "parallel=$source_dir/parallel" \
-f "$probe_dir/Dockerfile" -t tracewick-zts-parallel:8.5 "$probe_dir"
79 changes: 79 additions & 0 deletions experiments/zts-parallel/case.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

declare(strict_types=1);

require __DIR__ . '/probe.php';

$mode = $argv[1] ?? 'native';
$event = $argv[2] ?? 'wall';
$scenario = $argv[3] ?? 'concurrent';
$wire = $argv[4] ?? 'json';
$actors = ['alpha', 'beta', 'gamma', 'delta'];
$rows = [];
$threadCounts = [];
$cycles = $scenario === 'churn' ? 20 : 1;
$sequences = $scenario === 'reuse' ? 25 : 1;
$caught = [];
for ($cycle = 0; $cycle < $cycles; ++$cycle) {
$runtimes = [];
$futures = [];
$workers = $scenario === 'idle-cpu' ? 2 : ($scenario === 'one' ? 1 : 4);
for ($i = 0; $i < $workers; ++$i) {
$runtimes[] = new parallel\Runtime(__DIR__ . '/probe.php');
}
for ($sequence = 0; $sequence < $sequences; ++$sequence) {
foreach ($runtimes as $i => $runtime) {
$futures[$i] = $runtime->run(static function ($m, $e, $a, $ms, $sleep, $shutdown, $wire) {
$result = probeTask($m, $e, $a, $ms, $sleep, $shutdown);
return $wire === 'array' ? $result : json_encode($result, JSON_THROW_ON_ERROR);
}, [$scenario === 'parent-only' ? 'off' : $mode, $event, $actors[$i],
$scenario === 'reuse' || $scenario === 'churn' ? 30 : 300,
$scenario === 'idle-cpu' && $i === 0, $scenario === 'shutdown', $wire]);
}
if ($scenario === 'concurrent' || $scenario === 'parent-only') {
$parent = new ProbeSession($mode, $event, 'parent');
$rows[] = $parent->run(300, false);
unset($parent);
}
foreach ($futures as $future) {
$value = $future->value();
$rows[] = $wire === 'array' ? $value : json_decode($value, true, flags: JSON_THROW_ON_ERROR);
}
}
foreach ($runtimes as $runtime) {
$runtime->close();
}
unset($futures, $future, $runtimes, $runtime);
gc_collect_cycles();
$status = file_get_contents('/proc/self/status');
preg_match('/^Threads:\s+(\d+)/m', $status, $matches);
$threadCounts[] = (int) ($matches[1] ?? 0);
}

$spool = [];
if (is_dir('/output/spool')) {
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('/output/spool', FilesystemIterator::SKIP_DOTS));
foreach ($iterator as $file) {
if (!$file->isFile() || !str_ends_with($file->getFilename(), '.spool')) {
continue;
}
$wire = Tracewick\Sink\SpoolFile::fromBytes(file_get_contents($file->getPathname()));
$parts = (new Tracewick\Encoder\CompactStacksCodec())->decode($wire->payload);
$markers = [];
foreach ($parts->stacks as $stack) {
foreach ($stack->frameIds as $id) {
$name = $parts->frames[$id]->function ?? '';
if (str_starts_with($name, 'probe')) {
$markers[$name] = ($markers[$name] ?? 0) + $stack->count;
}
}
}
$spool[] = ['labels' => $wire->labels, 'bytes' => $file->getSize(), 'format' => $wire->format,
'markers' => $markers,
'events' => array_sum(array_map(static fn($stack) => $stack->count, $parts->stacks))];
}
}
echo json_encode(['php' => PHP_VERSION, 'zts' => PHP_ZTS, 'excimer' => phpversion('excimer'),
'parallel' => phpversion('parallel'), 'mode' => $mode, 'event' => $event,
'scenario' => $scenario, 'pid' => getmypid(), 'rows' => $rows, 'spool' => $spool,
'threads_after_close' => $threadCounts, 'caught' => $caught], JSON_THROW_ON_ERROR) . "\n";
46 changes: 46 additions & 0 deletions experiments/zts-parallel/edge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

require __DIR__ . '/probe.php';
$mode = $argv[1] ?? 'native';
$kind = $argv[2] ?? 'exception';
$ready = new parallel\Channel();
$runtime = new parallel\Runtime(__DIR__ . '/probe.php');
$future = $runtime->run(static function ($mode, $kind, $ready): string {
$session = new ProbeSession($mode, 'wall', 'alpha');
if ($session->native !== null) {
$session->native->start();
} else {
$session->profiler->start(['actor' => 'alpha']);
}
$ready->send('profiling-started');
try {
probeAlpha($kind === 'kill' ? 5000 : 100, false);
throw new RuntimeException('expected-worker-exception');
} finally {
$session->stop();
}
}, [$mode, $kind, $ready]);
$started = $ready->recv();
if ($kind === 'kill') {
usleep(20_000);
$runtime->kill();
}
$caught = null;
try {
$future->value();
} catch (Throwable $error) {
$caught = ['class' => $error::class, 'message' => $error->getMessage()];
}
$reused = null;
if ($kind === 'exception') {
$reused = $runtime->run(static fn(): int => 42)->value();
$runtime->close();
}
unset($future, $runtime, $ready);
gc_collect_cycles();
preg_match('/^Threads:\s+(\d+)/m', file_get_contents('/proc/self/status'), $matches);
echo json_encode(['mode' => $mode, 'kind' => $kind, 'started' => $started,
'caught' => $caught, 'reused' => $reused, 'threads_after' => (int) ($matches[1] ?? 0)],
JSON_THROW_ON_ERROR) . "\n";
21 changes: 21 additions & 0 deletions experiments/zts-parallel/literal-bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

function literalThreadId(): string { return 'unavailable'; }

final class LiteralFixture
{
public array $items = [];
public string $tid;

public function __construct() { $this->tid = literalThreadId(); }
public function payload(): array { return ['tid' => $this->tid, 'items' => $this->items]; }
}

function literalTask(): array
{
static $fixture;
$fixture ??= new LiteralFixture();
return $fixture->payload();
}
25 changes: 25 additions & 0 deletions experiments/zts-parallel/literal-return.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

require __DIR__ . '/literal-bootstrap.php';
$runtimes = $futures = $rows = [];
$wire = $argv[1] ?? 'array';
for ($i = 0; $i < 4; ++$i) {
$runtimes[$i] = new parallel\Runtime(__DIR__ . '/literal-bootstrap.php');
$task = $wire === 'array'
? static fn(): array => literalTask()
: static fn(): string => json_encode(literalTask(), JSON_THROW_ON_ERROR);
$futures[$i] = $runtimes[$i]->run($task);
}
$rows[] = (new LiteralFixture())->payload();
foreach ($futures as $future) {
$rows[] = $wire === 'array' ? $future->value()
: json_decode($future->value(), true, flags: JSON_THROW_ON_ERROR);
}
foreach ($runtimes as $runtime) {
$runtime->close();
}
unset($futures, $future, $runtimes, $runtime);
gc_collect_cycles();
echo json_encode($rows, JSON_THROW_ON_ERROR) . "\n";
28 changes: 28 additions & 0 deletions experiments/zts-parallel/minimal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

require __DIR__ . "/native.php";

$mode = $argv[1] ?? 'worker';
if ($mode === 'main') {
echo json_encode(nativeWork(true)) . "\n";
} else {
$runtimes = $futures = $rows = [];
for ($i = 0; $i < (str_starts_with($mode, 'concurrent') ? 4 : 1); ++$i) {
$runtimes[$i] = new parallel\Runtime(__DIR__ . "/native.php");
$futures[$i] = $runtimes[$i]->run(static function (bool $profile, bool $trace): array {
return nativeWork($profile, $trace);
}, [$mode !== 'off', str_ends_with($mode, 'trace')]);
}
if (str_starts_with($mode, 'concurrent')) {
$rows[] = nativeWork(true, str_ends_with($mode, 'trace'));
}
foreach ($futures as $f) {
$rows[] = $f->value();
}
foreach ($runtimes as $r) {
$r->close();
}
echo json_encode($rows) . "\n";
}
30 changes: 30 additions & 0 deletions experiments/zts-parallel/native.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

function nativeWork(bool $profile, bool $trace = false): array
{
$events = 0;
$p = null;
if ($profile) {
$p = new ExcimerProfiler();
$p->setEventType(EXCIMER_REAL);
$p->setPeriod(0.001);
$p->setFlushCallback(static function (ExcimerLog $log) use (&$events, $trace): void {
$events += $log->getEventCount();
if ($trace) {
foreach ($log as $entry) {
$entry->getTrace();
}
}
}, 16);
$p->start();
}
$until = hrtime(true) + 200_000_000;
while (hrtime(true) < $until) {}
if ($p !== null) {
$p->stop();
$p->flush();
}
return ['events' => $events];
}
Loading