probe: measure Function Response sizes and encodingsUnverified
a107587 parent: c9280af modified
probe/README.md +20 -0 | @@ -82,6 +82,25 @@ sleep 330; curl -sS "$PROBE_URL/?mode=history" > 09-history.ndjson | ||
| 82 | 82 | curl -sS "$PROBE_URL/" -H 'X-Example-Cron-Header: forged' > 11-forged-cron-marker.json |
| 83 | 83 | ``` |
| 84 | 84 | |
| 85 | +12. Static Files: the largest Function Response, and what the platform does with response encodings. | |
| 86 | + | |
| 87 | +```sh | |
| 88 | +# Text and base64 bodies of 5 to 12 MiB (decoded size): which sizes reach the client whole? | |
| 89 | +for size in 5 6 7 8 10 12; do | |
| 90 | + for encoding in text base64; do | |
| 91 | + curl -sS -o /dev/null -w "${size} MiB ${encoding}: HTTP %{http_code}, %{size_download} bytes\n" \ | |
| 92 | + "$PROBE_URL/?mode=size&encoding=${encoding}&bytes=$((size * 1024 * 1024))" | |
| 93 | + done | |
| 94 | +done > 12-response-sizes.txt | |
| 95 | +# Does the platform compress responses itself? Look for Content-Encoding in the headers. | |
| 96 | +curl -sS -o /dev/null -D 12-platform-compression.txt -H 'Accept-Encoding: gzip, br' "$PROBE_URL/?mode=size&bytes=102400" | |
| 97 | +# Does a Content-Encoding set by the function reach the client, with a body that decodes to X-Probe-Sha256? | |
| 98 | +for encoding in gzip zstd br; do | |
| 99 | + curl -sS -D 12-encoded-$encoding.headers -o 12-encoded-$encoding.body -H "Accept-Encoding: $encoding" "$PROBE_URL/?mode=encoded&encoding=$encoding" | |
| 100 | +done | |
| 101 | +php -r 'echo hash("sha256", gzdecode(file_get_contents("12-encoded-gzip.body"))), PHP_EOL;' > 12-encoded-gzip.sha256 | |
| 102 | +``` | |
| 103 | + | |
| 85 | 104 | ## Report back |
| 86 | 105 | |
| 87 | 106 | - All files of `probe-results/` (except `random.bin` and `body-*.txt`) and the exported logs. |
| @@ -104,6 +123,7 @@ The answers the files settle: | ||
| 104 | 123 | | Read-only code dir, writable `/tmp`, free space | `01-facts.json` `filesystem` | |
| 105 | 124 | | Shipped `vendor/` kept, Composer run at deploy (scripts, `--no-dev`) | `01-facts.json` `vendorMarkerKept`, `composerLockPresent`, `composerRun`, `vendorListing` | |
| 106 | 125 | | stdout, uncaught exceptions | `07-*.txt`, logs | |
| 126 | +| Largest Function Response, platform compression, `Content-Encoding` pass-through, `brotli` extension | `12-*`, `01-facts.json` `extensions` | | |
| 107 | 127 | |
| 108 | 128 | ## Clean up |
| 109 | 129 | |
| @@ -82,6 +82,25 @@ sleep 330; curl -sS "$PROBE_URL/?mode=history" > 09-history.ndjson | |||
| 82 | curl -sS "$PROBE_URL/" -H 'X-Example-Cron-Header: forged' > 11-forged-cron-marker.json | 82 | curl -sS "$PROBE_URL/" -H 'X-Example-Cron-Header: forged' > 11-forged-cron-marker.json |
| 83 | ``` | 83 | ``` |
| 84 | 84 | ||
| 85 | +12. Static Files: the largest Function Response, and what the platform does with response encodings. | ||
| 86 | + | ||
| 87 | +```sh | ||
| 88 | +# Text and base64 bodies of 5 to 12 MiB (decoded size): which sizes reach the client whole? | ||
| 89 | +for size in 5 6 7 8 10 12; do | ||
| 90 | + for encoding in text base64; do | ||
| 91 | + curl -sS -o /dev/null -w "${size} MiB ${encoding}: HTTP %{http_code}, %{size_download} bytes\n" \ | ||
| 92 | + "$PROBE_URL/?mode=size&encoding=${encoding}&bytes=$((size * 1024 * 1024))" | ||
| 93 | + done | ||
| 94 | +done > 12-response-sizes.txt | ||
| 95 | +# Does the platform compress responses itself? Look for Content-Encoding in the headers. | ||
| 96 | +curl -sS -o /dev/null -D 12-platform-compression.txt -H 'Accept-Encoding: gzip, br' "$PROBE_URL/?mode=size&bytes=102400" | ||
| 97 | +# Does a Content-Encoding set by the function reach the client, with a body that decodes to X-Probe-Sha256? | ||
| 98 | +for encoding in gzip zstd br; do | ||
| 99 | + curl -sS -D 12-encoded-$encoding.headers -o 12-encoded-$encoding.body -H "Accept-Encoding: $encoding" "$PROBE_URL/?mode=encoded&encoding=$encoding" | ||
| 100 | +done | ||
| 101 | +php -r 'echo hash("sha256", gzdecode(file_get_contents("12-encoded-gzip.body"))), PHP_EOL;' > 12-encoded-gzip.sha256 | ||
| 102 | +``` | ||
| 103 | + | ||
| 85 | ## Report back | 104 | ## Report back |
| 86 | 105 | ||
| 87 | - All files of `probe-results/` (except `random.bin` and `body-*.txt`) and the exported logs. | 106 | - All files of `probe-results/` (except `random.bin` and `body-*.txt`) and the exported logs. |
| @@ -104,6 +123,7 @@ The answers the files settle: | |||
| 104 | | Read-only code dir, writable `/tmp`, free space | `01-facts.json` `filesystem` | | 123 | | Read-only code dir, writable `/tmp`, free space | `01-facts.json` `filesystem` | |
| 105 | | Shipped `vendor/` kept, Composer run at deploy (scripts, `--no-dev`) | `01-facts.json` `vendorMarkerKept`, `composerLockPresent`, `composerRun`, `vendorListing` | | 124 | | Shipped `vendor/` kept, Composer run at deploy (scripts, `--no-dev`) | `01-facts.json` `vendorMarkerKept`, `composerLockPresent`, `composerRun`, `vendorListing` | |
| 106 | | stdout, uncaught exceptions | `07-*.txt`, logs | | 125 | | stdout, uncaught exceptions | `07-*.txt`, logs | |
| 126 | +| Largest Function Response, platform compression, `Content-Encoding` pass-through, `brotli` extension | `12-*`, `01-facts.json` `extensions` | | ||
| 107 | 127 | ||
| 108 | ## Clean up | 128 | ## Clean up |
| 109 | 129 | ||
modified
probe/function/handler.php +31 -0 | @@ -46,6 +46,37 @@ function handle($event, $context) | ||
| 46 | 46 | 'isBase64Encoded' => true, |
| 47 | 47 | ]; |
| 48 | 48 | |
| 49 | + case 'size': | |
| 50 | + // The largest Function Response the platform accepts bounds the Static Files the runtime can serve. | |
| 51 | + // Capped so the public probe cannot exhaust its memory. | |
| 52 | + $bytes = min(max((int) ($query['bytes'] ?? 0), 0), 32 << 20); | |
| 53 | + if ('base64' === ($query['encoding'] ?? 'text')) { | |
| 54 | + return [ | |
| 55 | + 'statusCode' => 200, | |
| 56 | + 'headers' => ['Content-Type' => 'application/octet-stream'], | |
| 57 | + 'body' => base64_encode(str_repeat("\xFF", $bytes)), | |
| 58 | + 'isBase64Encoded' => true, | |
| 59 | + ]; | |
| 60 | + } | |
| 61 | + | |
| 62 | + return ['statusCode' => 200, 'headers' => ['Content-Type' => 'text/plain'], 'body' => str_repeat('a', $bytes)]; | |
| 63 | + | |
| 64 | + case 'encoded': | |
| 65 | + // Does a Content-Encoding set by the function reach the client with the body untouched? | |
| 66 | + $text = str_repeat("Static File compressed by the function.\n", 1000); | |
| 67 | + $encoders = ['gzip' => 'gzencode', 'br' => 'brotli_compress', 'zstd' => 'zstd_compress']; | |
| 68 | + $encoding = isset($encoders[$query['encoding'] ?? '']) ? $query['encoding'] : 'gzip'; | |
| 69 | + if (!function_exists($encoders[$encoding])) { | |
| 70 | + return ['statusCode' => 501, 'headers' => ['Content-Type' => 'text/plain'], 'body' => "No extension compresses with {$encoding}.\n"]; | |
| 71 | + } | |
| 72 | + | |
| 73 | + return [ | |
| 74 | + 'statusCode' => 200, | |
| 75 | + 'headers' => ['Content-Type' => 'text/plain', 'Content-Encoding' => $encoding, 'Vary' => 'Accept-Encoding', 'X-Probe-Sha256' => hash('sha256', $text)], | |
| 76 | + 'body' => base64_encode($encoders[$encoding]($text)), | |
| 77 | + 'isBase64Encoded' => true, | |
| 78 | + ]; | |
| 79 | + | |
| 49 | 80 | case 'status': |
| 50 | 81 | return ['statusCode' => (int) ($query['code'] ?? 418), 'headers' => ['Content-Type' => 'text/plain'], 'body' => "status\n"]; |
| 51 | 82 | |
| @@ -46,6 +46,37 @@ function handle($event, $context) | |||
| 46 | 'isBase64Encoded' => true, | 46 | 'isBase64Encoded' => true, |
| 47 | ]; | 47 | ]; |
| 48 | 48 | ||
| 49 | + case 'size': | ||
| 50 | + // The largest Function Response the platform accepts bounds the Static Files the runtime can serve. | ||
| 51 | + // Capped so the public probe cannot exhaust its memory. | ||
| 52 | + $bytes = min(max((int) ($query['bytes'] ?? 0), 0), 32 << 20); | ||
| 53 | + if ('base64' === ($query['encoding'] ?? 'text')) { | ||
| 54 | + return [ | ||
| 55 | + 'statusCode' => 200, | ||
| 56 | + 'headers' => ['Content-Type' => 'application/octet-stream'], | ||
| 57 | + 'body' => base64_encode(str_repeat("\xFF", $bytes)), | ||
| 58 | + 'isBase64Encoded' => true, | ||
| 59 | + ]; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + return ['statusCode' => 200, 'headers' => ['Content-Type' => 'text/plain'], 'body' => str_repeat('a', $bytes)]; | ||
| 63 | + | ||
| 64 | + case 'encoded': | ||
| 65 | + // Does a Content-Encoding set by the function reach the client with the body untouched? | ||
| 66 | + $text = str_repeat("Static File compressed by the function.\n", 1000); | ||
| 67 | + $encoders = ['gzip' => 'gzencode', 'br' => 'brotli_compress', 'zstd' => 'zstd_compress']; | ||
| 68 | + $encoding = isset($encoders[$query['encoding'] ?? '']) ? $query['encoding'] : 'gzip'; | ||
| 69 | + if (!function_exists($encoders[$encoding])) { | ||
| 70 | + return ['statusCode' => 501, 'headers' => ['Content-Type' => 'text/plain'], 'body' => "No extension compresses with {$encoding}.\n"]; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + return [ | ||
| 74 | + 'statusCode' => 200, | ||
| 75 | + 'headers' => ['Content-Type' => 'text/plain', 'Content-Encoding' => $encoding, 'Vary' => 'Accept-Encoding', 'X-Probe-Sha256' => hash('sha256', $text)], | ||
| 76 | + 'body' => base64_encode($encoders[$encoding]($text)), | ||
| 77 | + 'isBase64Encoded' => true, | ||
| 78 | + ]; | ||
| 79 | + | ||
| 49 | case 'status': | 80 | case 'status': |
| 50 | return ['statusCode' => (int) ($query['code'] ?? 418), 'headers' => ['Content-Type' => 'text/plain'], 'body' => "status\n"]; | 81 | return ['statusCode' => (int) ($query['code'] ?? 418), 'headers' => ['Content-Type' => 'text/plain'], 'body' => "status\n"]; |
| 51 | 82 | ||