From 196b04a39c9d4a23bf97ce169f7da80cd7b242a5 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Tue, 21 Apr 2026 17:49:50 +0530 Subject: [PATCH] Polish benchmark comment details --- .github/workflows/ci.yml | 38 +++++++++++++++++++++++--------------- tests/benchmarks/http.php | 25 +++++++++++++++++-------- 2 files changed, 40 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5db20064dc..9e1a79cb3d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -837,17 +837,24 @@ jobs: return '| ' . $label . ' | ' . format_value($beforeValue, $suffix) . ' | ' . format_value($afterValue, $suffix) . ' | ' . delta($beforeValue, $afterValue, $suffix) . ' |'; } - function detail(array $after, string $label, string $metric, string $suffix = 'ms'): string + function format_detail_value(mixed $value, string $suffix = ''): string + { + return $value === null ? 'n/a' : number_format((float) $value, 2, '.', '') . $suffix; + } + + function detail_row(array $after, string $label, string $metric, string $suffix = 'ms'): string { $values = $after['metrics'][$metric]['values'] ?? null; if (!is_array($values)) { - return '- **' . $label . ':** no samples'; + return '| ' . $label . ' | n/a | n/a | n/a | n/a |'; } - return '- **' . $label . ':** avg=' . format_value($values['avg'] ?? null, $suffix) - . ' p90=' . format_value($values['p(90)'] ?? null, $suffix) - . ' p95=' . format_value($values['p(95)'] ?? null, $suffix) - . ' max=' . format_value($values['max'] ?? null, $suffix); + return '| ' . $label + . ' | ' . format_detail_value($values['avg'] ?? null, $suffix) + . ' | ' . format_detail_value($values['p(90)'] ?? null, $suffix) + . ' | ' . format_detail_value($values['p(95)'] ?? null, $suffix) + . ' | ' . format_detail_value($values['max'] ?? null, $suffix) + . ' |'; } $rows = [ @@ -857,8 +864,6 @@ jobs: row('TablesDB worker p95', metric_value($before, 'appwrite_worker_tables_duration', 'p(95)'), metric_value($after, 'appwrite_worker_tables_duration', 'p(95)'), 'ms'), row('Mail worker p95', metric_value($before, 'appwrite_worker_mails_duration', 'p(95)'), metric_value($after, 'appwrite_worker_mails_duration', 'p(95)'), 'ms'), row('Messaging worker p95', metric_value($before, 'appwrite_worker_messaging_duration', 'p(95)'), metric_value($after, 'appwrite_worker_messaging_duration', 'p(95)'), 'ms'), - row('Flow failures', metric_value($before, 'appwrite_benchmark_flow_failures', 'count'), metric_value($after, 'appwrite_benchmark_flow_failures', 'count')), - row('Check failures', metric_value($before, 'checks', 'fails'), metric_value($after, 'checks', 'fails')), ]; echo "\n"; @@ -871,13 +876,16 @@ jobs: echo "| --- | ---: | ---: | ---: |\n"; echo implode("\n", $rows) . "\n\n"; echo "
\n"; - echo "Current run details\n\n"; - echo detail($after, 'HTTP total', 'http_req_duration') . "\n"; - echo detail($after, 'API endpoints', 'appwrite_api_duration') . "\n"; - echo detail($after, 'Database worker schema jobs', 'appwrite_worker_database_duration') . "\n"; - echo detail($after, 'TablesDB worker schema jobs', 'appwrite_worker_tables_duration') . "\n"; - echo detail($after, 'Mail worker delivery', 'appwrite_worker_mails_duration') . "\n"; - echo detail($after, 'Messaging worker delivery', 'appwrite_worker_messaging_duration') . "\n\n"; + echo "Current run details\n\n"; + echo "
\n\n"; + echo "| Scenario | Avg | P90 | P95 | Max |\n"; + echo "| --- | ---: | ---: | ---: | ---: |\n"; + echo detail_row($after, 'HTTP total', 'http_req_duration') . "\n"; + echo detail_row($after, 'API endpoints', 'appwrite_api_duration') . "\n"; + echo detail_row($after, 'Database worker schema jobs', 'appwrite_worker_database_duration') . "\n"; + echo detail_row($after, 'TablesDB worker schema jobs', 'appwrite_worker_tables_duration') . "\n"; + echo detail_row($after, 'Mail worker delivery', 'appwrite_worker_mails_duration') . "\n"; + echo detail_row($after, 'Messaging worker delivery', 'appwrite_worker_messaging_duration') . "\n\n"; echo "
\n"; PHP diff --git a/tests/benchmarks/http.php b/tests/benchmarks/http.php index c71991a062..7924351409 100644 --- a/tests/benchmarks/http.php +++ b/tests/benchmarks/http.php @@ -897,17 +897,17 @@ final class HttpBenchmark return $response; } - private function rawRequest(string $method, string $path, mixed $body, array $headers, string $name): BenchmarkResponse + private function rawRequest(string $method, string $path, mixed $body, array $headers, string $name, bool $recordHttpDuration = true): BenchmarkResponse { - return $this->send($method, str_starts_with($path, 'http') ? $path : $this->endpoint . $path, $body, $headers, $name, false); + return $this->send($method, str_starts_with($path, 'http') ? $path : $this->endpoint . $path, $body, $headers, $name, false, $recordHttpDuration); } private function rawMultipartRequest(string $method, string $path, array $fields, array $headers, string $name): BenchmarkResponse { - return $this->send($method, $this->endpoint . $path, $fields, $headers, $name, true); + return $this->send($method, $this->endpoint . $path, $fields, $headers, $name, true, true); } - private function send(string $method, string $url, mixed $body, array $headers, string $name, bool $multipart): BenchmarkResponse + private function send(string $method, string $url, mixed $body, array $headers, string $name, bool $multipart, bool $recordHttpDuration): BenchmarkResponse { $handle = curl_init($url); if ($handle === false) { @@ -936,7 +936,9 @@ final class HttpBenchmark $started = hrtime(true); $raw = curl_exec($handle); $duration = (hrtime(true) - $started) / 1_000_000; - $this->metrics->addTrend('http_req_duration', $duration); + if ($recordHttpDuration) { + $this->metrics->addTrend('http_req_duration', $duration); + } if ($raw === false) { $error = curl_error($handle); @@ -960,8 +962,15 @@ final class HttpBenchmark while ($this->nowMs() - $started < $timeoutMs) { $response = $this->rawRequest('GET', $path, null, $headers, "wait{$path}"); - if ($response->status === 200 && $response->json('status') === $wantedStatus) { - return $response; + if ($response->status === 200) { + $status = $response->json('status'); + if ($status === $wantedStatus) { + return $response; + } + + if ($status === 'failed') { + throw new RuntimeException("Resource {$path} failed while waiting for {$wantedStatus}"); + } } usleep(500_000); @@ -997,7 +1006,7 @@ final class HttpBenchmark $started = $this->nowMs(); while ($this->nowMs() - $started < $timeoutMs) { - $response = $this->rawRequest('GET', $this->maildevEndpoint, null, [], 'maildev.email.list'); + $response = $this->rawRequest('GET', $this->maildevEndpoint, null, [], 'maildev.email.list', false); if ($response->status === 200) { $emails = $response->json();