From 69063f5c5627798ad10a6c4620b4ce66fdbdbd74 Mon Sep 17 00:00:00 2001 From: Dmitriy Derepko Date: Mon, 9 Nov 2026 11:13:16 +0400 Subject: [PATCH] test(bench): measure the workflow lifecycle with eviction Each rev starts, signals and evicts one workflow. The bench emits ON_FINALLY itself, so it runs on master too. --- tests/Benchmark/EvictionBench.php | 62 ++++++++++++++++++++++++++++ tests/Benchmark/EvictionWorkflow.php | 41 ++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 tests/Benchmark/EvictionBench.php create mode 100644 tests/Benchmark/EvictionWorkflow.php diff --git a/tests/Benchmark/EvictionBench.php b/tests/Benchmark/EvictionBench.php new file mode 100644 index 000000000..18843a14c --- /dev/null +++ b/tests/Benchmark/EvictionBench.php @@ -0,0 +1,62 @@ + ['shape' => $shape]; + } + } + + public function createWorker(array $params): void + { + $this->factory = WorkerFactoryMock::create(); + $this->factory->newWorker()->registerWorkflowObject(new EvictionWorkflow()); + $this->shape = $params['shape']; + \gc_collect_cycles(); + } + + public function benchStartAndEvict(): void + { + $runId = 'run-' . $this->run++; + $this->dispatch(new StartWorkflow($runId, 'EvictionWorkflow', $this->shape), new InvokeSignal($runId, 'wait')); + $this->dispatch(new ServerRequest('DestroyWorkflow', new TickInfo(new \DateTimeImmutable()), ['runId' => $runId])); + } + + private function dispatch(object ...$commands): void + { + $batch = new CommandBatchMock($commands, ['taskQueue' => 'default', 'tickTime' => (new \DateTimeImmutable())->format(\DATE_ATOM)]); + $responses = (fn(): iterable => $this->dispatch($batch))->call($this->factory); + foreach ($responses as $_) { + } + + $this->factory->emit(LoopInterface::ON_FINALLY); + } +} diff --git a/tests/Benchmark/EvictionWorkflow.php b/tests/Benchmark/EvictionWorkflow.php new file mode 100644 index 000000000..8063bf89c --- /dev/null +++ b/tests/Benchmark/EvictionWorkflow.php @@ -0,0 +1,41 @@ + Workflow::timer(100); + + yield match ($shape) { + 'timer' => $timer(), + 'temporal_all' => Promise::all([$timer(), $timer(), $timer()]), + 'react_all' => all([$timer(), $timer(), $timer()]), + 'scopes' => Promise::all([ + Workflow::async(static fn(): \Generator => yield $timer()), + Workflow::async(static fn(): \Generator => yield Workflow::async(static fn(): \Generator => yield $timer())), + $timer(), + ]), + 'then_chain' => $timer()->then(static fn($v) => $v)->then(static fn($v) => $v), + 'user_deferred' => (new Deferred(static function (): void {}))->promise(), + 'signal' => Workflow::await(static fn(): bool => false), + }; + } + + #[Workflow\SignalMethod(name: 'wait')] + public function wait(): iterable + { + yield Workflow::timer(100); + } +}