active; $this->active = true; return ['action' => $opened ? 'opened' : 'updated', 'id' => 1]; } public function resolveAlert(string $fingerprint, string $endedAt, ?array $context = null): array { $resolved = $this->active; $this->active = false; return ['action' => $resolved ? 'resolved' : 'noop', 'id' => 1]; } } $waiters = []; for ($i = 0; $i < 53; $i++) { $waiters[] = [ 'ID' => (string)(9917600 + $i), 'USER' => $i % 3 === 0 ? 'bench_user_a' : 'bench_user_b', 'HOST' => '10.1.1.'.(100 + $i).':45000', 'DB' => 'bench_db', 'TIME' => (string)(5553.827 - $i), 'TIME_MS' => (string)((5553.827 - $i) * 1000), 'STATE' => $i % 2 === 0 ? 'Waiting for table metadata lock' : 'WAITING FOR TABLE METADATA LOCK', 'INFO' => $i < 12 ? 'LOCK TABLES support WRITE /* '.str_repeat('x', 600).' */' : 'SELECT * FROM support WHERE id='.(1000 + $i), ]; } $healthy = array_map(static function (array $row): array { $row['STATE'] = 'Sending data'; return $row; }, $waiters); $json = json_encode($waiters, JSON_THROW_ON_ERROR); $store = new BenchIncidentStore(); $server = ['id' => 327, 'name' => 'benchmark-server']; $at = '2026-09-28 00:00:00'; $cases = [ 'json_decode_53_rows' => [2000, static fn () => json_decode($json, true, 512, JSON_THROW_ON_ERROR), null], 'detect_53_waiters' => [2000, static fn () => MetadataLockDetector::analyze($waiters, 30), null], 'healthy_callback' => [500, static fn () => AlertFeed::processMetadataLocks($store, $server, $healthy, $at), static function () use ($store): void { $store->active = false; }], 'open_callback' => [500, static fn () => AlertFeed::processMetadataLocks($store, $server, $waiters, $at), static function () use ($store): void { $store->active = false; }], 'refresh_callback' => [500, static fn () => AlertFeed::processMetadataLocks($store, $server, $waiters, $at), static function () use ($store): void { $store->active = true; }], 'resolve_callback' => [500, static fn () => AlertFeed::processMetadataLocks($store, $server, $healthy, $at), static function () use ($store): void { $store->active = true; }], ]; $analysis = MetadataLockDetector::analyze($waiters, 30); if ($analysis['waiting_count'] !== 53 || $analysis['omitted_waiters'] !== 43 || $analysis['ddl_waiting_count'] !== 12) { throw new RuntimeException('Fixture correctness check failed'); } $summary = []; foreach ($cases as $name => [$iterations, $callback, $before]) { $trials = []; for ($trial = 0; $trial < 5; $trial++) { for ($warm = 0; $warm < 10; $warm++) { if ($before) { $before(); } $callback(); } $samples = []; for ($i = 0; $i < $iterations; $i++) { if ($before) { $before(); } $start = hrtime(true); $callback(); $samples[] = (hrtime(true) - $start) / 1_000_000; } sort($samples, SORT_NUMERIC); $n = count($samples); $trials[] = [ 'mean_ms' => array_sum($samples) / $n, 'median_ms' => ($samples[intdiv($n-1, 2)] + $samples[intdiv($n, 2)]) / 2, 'p95_ms' => $samples[(int)floor(($n - 1) * .95)], 'max_ms' => $samples[$n - 1], ]; } $summary[$name] = ['iterations_per_trial' => $iterations, 'trials' => $trials]; } echo json_encode([ 'revision' => $revision, 'php' => PHP_VERSION, 'os' => file_get_contents('/etc/os-release'), 'snapshot_rows' => 53, 'snapshot_bytes' => strlen($json), 'correctness' => ['waiting_count' => 53, 'omitted_waiters' => 43, 'ddl_waiting_count' => 12], 'cases' => $summary, ], JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR), "\n";