Skip to content

Commit dad7235

Browse files
dmsnellclaude
andcommitted
HTML API: Stream whole WARC files for the CommonCrawl analysis.
CommonCrawl's CDN blocked the runner outright ("Request blocked." for every path, ranged or not) after the fetch had sampled its URL index with about 2,000 requests. Fetching 10,000 records one request each would draw the same block, so go back to streaming whole WARC files, which takes a handful of requests in all, and lower the default to 2,000 documents to reduce the demand of each run. One WARC file holds around 20,000 HTML documents, so the default reads about a tenth of one. Rebuild cc-analyzer.phar from a version which keeps the documents a WARC file delivered even if its download fails, lists the failure, and finishes with what it has. Remove the temporary access check. See #66430. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent fcae06b commit dad7235

4 files changed

Lines changed: 16 additions & 59 deletions

File tree

‎.github/workflows/html-api-commoncrawl.yml‎

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ on:
3131
description: 'How many documents to fetch from CommonCrawl'
3232
required: false
3333
type: number
34-
default: 10000
34+
default: 2000
3535
fetch-duration:
3636
description: 'Longest time to spend fetching documents, e.g. 90s, 30m, 1h'
3737
required: false
@@ -64,7 +64,7 @@ permissions: {}
6464

6565
env:
6666
# The analysis stops fetching documents when it has this many or when the fetch duration has passed, whichever is first.
67-
HTML_API_BENCH_DOCUMENTS: ${{ inputs.documents || 10000 }}
67+
HTML_API_BENCH_DOCUMENTS: ${{ inputs.documents || 2000 }}
6868
HTML_API_BENCH_FETCH_DURATION: ${{ inputs.fetch-duration || '30m' }}
6969
HTML_API_BENCH_ROUNDS: ${{ inputs.rounds || 3 }}
7070
HTML_API_BENCH_SMALL_MAX_BYTES: ${{ inputs.small-max-bytes || 32768 }}
@@ -118,32 +118,24 @@ jobs:
118118
extensions: curl, mbstring, pdo_sqlite, zlib
119119
ini-values: memory_limit=1G
120120

121-
# Temporary: shows whether CommonCrawl serves WARC records to this runner before anything else is requested.
122-
- name: Check CommonCrawl access
123-
run: bash "$SCRIPTS/check-commoncrawl-access.sh"
124-
125-
# Samples successful HTML captures from random blocks of the crawl's URL index, from many hosts across the whole crawl,
126-
# and downloads only those records, four at a time. When CommonCrawl asks to slow down, with HTTP 429 or 503, no
127-
# request is sent until its Retry-After or the backoff has passed. A record which still can't be downloaded is listed
128-
# and skipped, and a 403, which means this runner has been blocked, stops fetching; the analysis then runs on the
129-
# documents already fetched. The cache limit is raised so that pruning never runs during the fetch.
121+
# Streams whole WARC files, a handful of requests in all: CommonCrawl blocks runners which send many requests, such as
122+
# one per record. Each WARC file from a crawl holds around 20,000 HTML documents, so documents are taken from up to
123+
# 10,000 per file. When CommonCrawl asks to slow down, with HTTP 429 or 503, no request is sent until its Retry-After
124+
# or the backoff has passed. A download which still fails is listed, and the analysis runs on the documents already
125+
# fetched. The cache limit is raised so that pruning never runs during the fetch.
130126
- name: Fetch documents from CommonCrawl
131127
run: |
128+
warcs=$(( ( HTML_API_BENCH_DOCUMENTS + 9999 ) / 10000 ))
132129
php "$CC_ANALYZER" --workspace "$RUNNER_TEMP/cc-analyzer" batch fetch corpus \
133-
--sample index \
134130
--resource-types html \
135-
--limit "$HTML_API_BENCH_DOCUMENTS" \
136-
--concurrency 4 \
131+
--limit "$(( ( HTML_API_BENCH_DOCUMENTS + warcs - 1 ) / warcs ))" \
132+
--limit-warcs "$warcs" \
133+
--max-jobs "$warcs" \
137134
--http-retries 6 \
138135
--cache-max-bytes 17179869184 \
139136
--duration "$HTML_API_BENCH_FETCH_DURATION" \
140137
--progress text
141138
142-
# Temporary: shows whether CommonCrawl still serves this runner after a failed fetch.
143-
- name: Check CommonCrawl access after the fetch
144-
if: ${{ failure() }}
145-
run: bash "$SCRIPTS/check-commoncrawl-access.sh"
146-
147139
- name: Time parsing with both checkouts
148140
run: |
149141
for round in $( seq 1 "$HTML_API_BENCH_ROUNDS" ); do

‎tools/html-api-commoncrawl/README.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The report is left as a comment on the pull request. Each new analysis replaces
1313

1414
## Files
1515

16-
- `cc-analyzer.phar`: [cc-analyzer](#rebuilding-cc-analyzerphar), which fetches documents from CommonCrawl into a local batch, and replays a batch through an analysis script. It samples random blocks of the crawl's URL index, keeps successful `text/html` captures from up to ten different hosts in each block, and downloads only those records, four at a time. It honors CommonCrawl's rate limiting, skips and lists any record it can't download, and stops fetching if CommonCrawl blocks the runner with HTTP 403; the analysis then runs on the documents it has.
16+
- `cc-analyzer.phar`: [cc-analyzer](#rebuilding-cc-analyzerphar), which fetches documents from CommonCrawl into a local batch, and replays a batch through an analysis script. It streams whole WARC files and keeps their HTML responses. That takes only a handful of requests: CommonCrawl blocks runners which send many, such as one per record. It honors CommonCrawl's rate limiting, and if a download still fails, it lists the failure and the analysis runs on the documents it has.
1717
- `bootstrap.php`: loads the HTML API, and what `wp_kses()` needs, from the `src/` directory in `HTML_API_BENCH_WP_SRC`, without loading WordPress. It presents a UTF-8 site at example.com. When a change adds a file to the HTML API, add it to the list of files here.
1818
- `benchmark.php`: an analysis script which times the Tag Processor, the HTML Processor, and `wp_kses( $html, 'post' )` on each document and writes `benchmark.csv`.
1919
- `analysis.php`: an analysis script which records whether the HTML Processor supports each document and writes `analysis.csv`.
@@ -26,7 +26,7 @@ This needs PHP 8.5, as used by the workflow, with the `curl`, `pdo_sqlite`, and
2626
```sh
2727
# Fetch 1,000 documents, or as many as can be fetched in 5 minutes.
2828
php -d memory_limit=1G tools/html-api-commoncrawl/cc-analyzer.phar --workspace /tmp/cc batch fetch corpus \
29-
--sample index --resource-types html --limit 1000 --concurrency 4 --http-retries 6 --duration 5m --progress text
29+
--resource-types html --limit 1000 --limit-warcs 1 --max-jobs 1 --http-retries 6 --duration 5m --progress text
3030

3131
# Time each document three times with each checkout, and record support once.
3232
for checkout in base merge; do
@@ -52,15 +52,15 @@ The workflow reads these environment variables. When it is run manually, each on
5252

5353
| Variable | Default | Meaning |
5454
| --- | --- | --- |
55-
| `HTML_API_BENCH_DOCUMENTS` | `10000` | How many documents to fetch. |
56-
| `HTML_API_BENCH_FETCH_DURATION` | `30m` | Longest time to spend fetching. Fetching stops at whichever limit is reached first. At most half of it is spent sampling the index. |
55+
| `HTML_API_BENCH_DOCUMENTS` | `2000` | How many documents to fetch. |
56+
| `HTML_API_BENCH_FETCH_DURATION` | `30m` | Longest time to spend fetching. Fetching stops at whichever limit is reached first. |
5757
| `HTML_API_BENCH_ROUNDS` | `3` | How many times to time each document with each checkout. Each document's time is its median. |
5858
| `HTML_API_BENCH_SMALL_MAX_BYTES` | `32768` | Documents smaller than this are small. |
5959
| `HTML_API_BENCH_LARGE_MIN_BYTES` | `262144` | Documents at least this large are large. Everything between is medium. |
6060

6161
## Rebuilding `cc-analyzer.phar`
6262

63-
`cc-analyzer.phar` was built from cc-analyzer commit `1237e83` (branch `index-sampled-fetch`) with `tools/build-phar.php`. Before building, the default HTTP identity was removed so that requests carry only a generic `User-Agent` and no `From` header:
63+
`cc-analyzer.phar` was built from cc-analyzer commit `a17b1f6` (branch `index-sampled-fetch`) with `tools/build-phar.php`. Before building, the default HTTP identity was removed so that requests carry only a generic `User-Agent` and no `From` header:
6464

6565
- `src/Http/CurlStreamClient.php`: `DEFAULT_USER_AGENT` set to `'cc-analyzer/0.1 PHP-cURL'` and `DEFAULT_CONTACT_HEADER` set to `''`.
6666
- `src/Cli/Application.php`: the `--user-agent` and `--contact-email` defaults set to the same values, and the help text to match.
156 Bytes
Binary file not shown.

‎tools/html-api-commoncrawl/check-commoncrawl-access.sh‎

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)