programming:deployment
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| programming:deployment [2026/08/28 20:40] – Review round 1: fix misattributed retry figure in the published script (Hausladen, not Bouchet); queue now retries at the back of the queue, with a mutation-tested self-check; lease-expiry check added; cost table corrected to all 8 own-cost papers with a karel.kubicek.claude | programming:deployment [2026/08/28 21:04] (current) – Review round 2 (generic): claim() now checks it won the row (SELECT-then-UPDATE was handing one URL to two workers) and the queue shuffles deterministically at seed time; queue probe drops 'redis' (34 to 18, 16 matched only on a data store); infrastructur karel.kubicek.claude | ||
|---|---|---|---|
| Line 6: | Line 6: | ||
| <WRAP important> | <WRAP important> | ||
| - | **Long runs are normal; saying how you ran them is not.** Of the **1,120 crawled papers** in this corpus, 230 give a live-crawl start and end date at day precision. Reading each one's own sentence, **182** of those spans are machine time rather than a content date range — and **138 of the 182 (75.8%)** ran for more than a week, **53 (29.1%)** for more than three months. | + | **Long runs are normal; saying how you ran them is not.** Of the **1,120 crawled papers** in this corpus, 230 give a live-crawl start and end date at day precision. Reading each one's own sentence, **182** of those spans are one continuous stretch of machine time; the rest are content date ranges, disjoint episodes, or list-fetch dates. |
| Against the same 1,120: **13 (1.2%)** mention checkpointing or resuming a crawl, **21 (1.9%)** name a cluster orchestrator, | Against the same 1,120: **13 (1.2%)** mention checkpointing or resuming a crawl, **21 (1.9%)** name a cluster orchestrator, | ||
| Line 22: | Line 22: | ||
| ===== How long a crawl actually runs ===== | ===== How long a crawl actually runs ===== | ||
| - | Population: crawled papers with at least one '' | + | Population: crawled papers with at least one '' |
| The raw span is not the answer, because the extraction' | The raw span is not the answer, because the extraction' | ||
| Line 69: | Line 69: | ||
| ^ Probe ^ Papers ^ Share ^ | ^ Probe ^ Papers ^ Share ^ | ||
| | '' | | '' | ||
| - | | a task or job queue by name (Celery, RabbitMQ, Redis, Kafka, SQS, ...) | 34 | 3.0% | | + | | a task or job queue by name (Celery, RabbitMQ, Kafka, SQS, ...) | 18 | 1.6% | |
| | a cluster orchestrator by name (Kubernetes, | | a cluster orchestrator by name (Kubernetes, | ||
| | a monitoring or logging stack by name (Prometheus, | | a monitoring or logging stack by name (Prometheus, | ||
| Line 92: | Line 92: | ||
| - **Fingerprint the seed list.** A resumed run that seeds a // | - **Fingerprint the seed list.** A resumed run that seeds a // | ||
| - | The script below is a working queue with those three properties, stdlib Python only ('' | + | The script below is a working queue with those four properties, stdlib Python only ('' |
| <file python crawl_queue.py> | <file python crawl_queue.py> | ||
| Line 113: | Line 113: | ||
| running -> pending | running -> pending | ||
| - | Three things this gets right that a dict-of-URLs in memory does not: | + | Four things this gets right that a dict-of-URLs in memory does not: |
| 1. **Claim-then-commit with a lease, and a named worker.** A worker marks a | 1. **Claim-then-commit with a lease, and a named worker.** A worker marks a | ||
| Line 165: | Line 165: | ||
| status | status | ||
| attempts | attempts | ||
| + | seq TEXT NOT NULL, | ||
| worker | worker | ||
| lease_until | lease_until | ||
| Line 171: | Line 172: | ||
| updated_at | updated_at | ||
| ); | ); | ||
| - | CREATE INDEX IF NOT EXISTS work_status ON work(status); | + | CREATE INDEX IF NOT EXISTS work_status ON work(status, attempts, seq); |
| CREATE TABLE IF NOT EXISTS meta (k TEXT PRIMARY KEY, v TEXT NOT NULL); | CREATE TABLE IF NOT EXISTS meta (k TEXT PRIMARY KEY, v TEXT NOT NULL); | ||
| """ | """ | ||
| Line 238: | Line 239: | ||
| now = self.clock() | now = self.clock() | ||
| before = self.db.execute(" | before = self.db.execute(" | ||
| + | # seq is a deterministic shuffle: sha256(digest + url). Claim order is | ||
| + | # (attempts, seq), so the crawl walks the list in an order that is | ||
| + | # reproducible from the seed but uncorrelated with rank, TLD or name. | ||
| + | # It matters because a crawl that dies halfway through a rank-ordered | ||
| + | # queue loses the tail of the ranking systematically; | ||
| + | # a shuffled queue loses a random subset, which is a far weaker claim | ||
| + | # to have to defend in a methods section. | ||
| self.db.executemany( | self.db.executemany( | ||
| - | " | + | " |
| - | [(u, now) for u in urls], | + | "VALUES(?,' |
| + | [(u, hashlib.sha256((digest + u).encode(" | ||
| ) | ) | ||
| return self.db.execute(" | return self.db.execute(" | ||
| Line 283: | Line 292: | ||
| before any retry is taken. | before any retry is taken. | ||
| """ | """ | ||
| - | now = self.clock() | + | |
| - | row = self.db.execute( | + | |
| - | " | + | row = self.db.execute( |
| - | "ORDER BY attempts ASC, url ASC LIMIT 1" | + | " |
| - | ).fetchone() | + | "ORDER BY attempts ASC, seq ASC LIMIT 1" |
| - | if row is None: | + | ).fetchone() |
| - | return None | + | if row is None: |
| - | url, attempts = row | + | return None |
| - | self.db.execute( | + | url, attempts = row |
| - | " | + | cur = self.db.execute( |
| - | "WHERE url=? AND status=' | + | " |
| - | (attempts + 1, worker, now + self.lease_seconds, | + | "updated_at=? |
| - | ) | + | (attempts + 1, worker, now + self.lease_seconds, |
| - | return url, attempts + 1 | + | ) |
| + | # SELECT-then-UPDATE is not atomic. Another worker can win the row | ||
| + | # between the two statements, and then this UPDATE matches zero | ||
| + | # rows. Returning the URL anyway would hand two workers the same | ||
| + | # site and let the second one overwrite the first' | ||
| + | # exact double-count the lease exists to prevent. Loop instead. | ||
| + | if cur.rowcount == 1: | ||
| + | | ||
| # -- outcomes --------------------------------------------------------- | # -- outcomes --------------------------------------------------------- | ||
| Line 409: | Line 425: | ||
| return visit | return visit | ||
| + | |||
| + | |||
| + | class _FakeCursor: | ||
| + | """ | ||
| + | |||
| + | def __init__(self, | ||
| + | self._row = row | ||
| + | |||
| + | def fetchone(self): | ||
| + | return self._row | ||
| + | |||
| + | |||
| + | class _RaceOnce: | ||
| + | """ | ||
| + | |||
| + | Used only by the demo. It passes everything through, except that the first | ||
| + | time claim() runs its SELECT it hands the row to a " | ||
| + | returning it — reproducing, | ||
| + | an unchecked SELECT-then-UPDATE hand one URL to two workers. | ||
| + | """ | ||
| + | |||
| + | def __init__(self, | ||
| + | self.db = db | ||
| + | self.armed = True | ||
| + | self.stolen = None | ||
| + | |||
| + | def execute(self, | ||
| + | if self.armed and sql.startswith(" | ||
| + | self.armed = False | ||
| + | row = self.db.execute(sql, | ||
| + | if row is not None: | ||
| + | self.stolen = row[0] | ||
| + | self.db.execute( | ||
| + | " | ||
| + | (row[0],), | ||
| + | ) | ||
| + | return _FakeCursor(row) | ||
| + | return self.db.execute(sql, | ||
| + | |||
| + | def executemany(self, | ||
| + | return self.db.executemany(sql, | ||
| + | |||
| + | def executescript(self, | ||
| + | return self.db.executescript(sql) | ||
| Line 492: | Line 552: | ||
| print(f" | print(f" | ||
| - | print(" | + | print(" |
| + | # SELECT-then-UPDATE is not atomic, and the window between them is the only | ||
| + | # place two workers can be handed the same URL. Marking the row running | ||
| + | # BEFORE claim() runs does not test that window — the SELECT simply skips | ||
| + | # it. _RaceOnce steals the row in the window itself: it lets the SELECT | ||
| + | # return normally and then marks that row running behind claim()' | ||
| + | # so claim()' | ||
| + | # claim() returns the stolen URL and two workers crawl the same site. | ||
| + | race_db = os.path.join(tmp, | ||
| + | rq = CrawlQueue(race_db) | ||
| + | rq.seed(sites[: | ||
| + | rq.db = _RaceOnce(rq.db) | ||
| + | got = rq.claim(" | ||
| + | stolen = rq.db.stolen | ||
| + | print(f" | ||
| + | print(f" | ||
| + | race_ok = got is not None and got[0] != stolen | ||
| + | |||
| + | print(" | ||
| + | order_a = [u for u, in oq.db.execute( | ||
| + | " | ||
| + | rerun_db = os.path.join(tmp, | ||
| + | rq2 = CrawlQueue(rerun_db) | ||
| + | rq2.seed(small) | ||
| + | order_b = [u for u, in rq2.db.execute( | ||
| + | " | ||
| + | print(f" | ||
| + | print(f" | ||
| + | print(f" | ||
| + | |||
| + | print(" | ||
| try: | try: | ||
| resumed.seed(sites + [" | resumed.seed(sites + [" | ||
| Line 500: | Line 590: | ||
| print(f" | print(f" | ||
| - | print(" | + | print(" |
| ok = True | ok = True | ||
| checks = [ | checks = [ | ||
| Line 515: | Line 605: | ||
| (" | (" | ||
| and (not retries or retries[0] == len(small))), | and (not retries or retries[0] == len(small))), | ||
| + | (" | ||
| + | (" | ||
| + | (" | ||
| (" | (" | ||
| ] | ] | ||
| Line 549: | Line 642: | ||
| === A. reference run, no crash (200 URLs) === | === A. reference run, no crash (200 URLs) === | ||
| seeded 200 rows, seed sha256 49ddaed11cb3d529... | seeded 200 rows, seed sha256 49ddaed11cb3d529... | ||
| - | [worker] total=200 done=60 failed=20 running=0 pending=120 | http_404=10, nxdomain=10 | + | [worker] total=200 done=61 failed=21 running=0 pending=118 | http_404=9, nxdomain=12 |
| [worker] total=200 done=120 failed=40 running=0 pending=40 | http_404=20, | [worker] total=200 done=120 failed=40 running=0 pending=40 | http_404=20, | ||
| visits attempted: 280 | visits attempted: 280 | ||
| Line 555: | Line 648: | ||
| === B. same population, machine dies on the 87th visit === | === B. same population, machine dies on the 87th visit === | ||
| - | killed while visiting https://site086.example/ | + | killed while visiting https://site013.example/ |
| - | state on disk: total=200 done=54 failed=16 running=1 pending=129 | http_404=8, nxdomain=8 | + | state on disk: total=200 done=51 failed=19 running=1 pending=129 | http_404=7, nxdomain=12 |
| rows left in ' | rows left in ' | ||
| Line 563: | Line 656: | ||
| reclaim_expired() reclaimed 0 row(s) -- the 300s lease has not run out yet | reclaim_expired() reclaimed 0 row(s) -- the 300s lease has not run out yet | ||
| reclaim_worker(' | reclaim_worker(' | ||
| - | [worker] total=200 done=114 failed=36 running=0 pending=50 | http_404=18, nxdomain=18 | + | [worker] total=200 done=113 failed=36 running=0 pending=51 | http_404=17, nxdomain=19 |
| visits attempted after resume: 194 | visits attempted after resume: 194 | ||
| final: total=200 done=140 failed=60 running=0 pending=0 | http_404=20, | final: total=200 done=140 failed=60 running=0 pending=0 | http_404=20, | ||
| Line 572: | Line 665: | ||
| === E. does a retry go to the back of the queue? === | === E. does a retry go to the back of the queue? === | ||
| - | claim order (site, attempt): [('000', 1), ('001', 1), ('002', 1), (' | + | claim order (site, attempt): [('010', 1), ('002', 1), ('008', 1), (' |
| first-attempt claims: 20; first retry at position 20 | first-attempt claims: 20; first retry at position 20 | ||
| - | === F. the seed guard === | + | === F. does claim() refuse a row it did not win? === |
| + | a rival took this row inside the window: https:// | ||
| + | claim() returned: | ||
| + | |||
| + | === G. is the claim order shuffled, and reproducible? | ||
| + | seed order: | ||
| + | claim order: | ||
| + | same list, new database, same order: True | ||
| + | |||
| + | === H. the seed guard === | ||
| refused, as it should: seed list changed since this queue was created (stored 49ddaed11cb3..., | refused, as it should: seed list changed since this queue was created (stored 49ddaed11cb3..., | ||
| - | === G. checks === | + | === I. checks === |
| ok same successful set | ok same successful set | ||
| ok same failure set | ok same failure set | ||
| Line 590: | Line 692: | ||
| ok an expired lease IS reclaimed | ok an expired lease IS reclaimed | ||
| ok every first attempt precedes every retry | ok every first attempt precedes every retry | ||
| + | ok | ||
| + | ok claim order is not the seed order | ||
| + | ok claim order is reproducible from the seed | ||
| ok | ok | ||
| note clean run: 280 visits. crash+resume: | note clean run: 280 visits. crash+resume: | ||
| Line 600: | Line 705: | ||
| ===== Retries: what to retry, and what it buys ===== | ===== Retries: what to retry, and what it buys ===== | ||
| - | Retrying once is the single highest-return operational decision on this page, and one paper measured | + | Retrying once is the single highest-return operational decision on this page, and one paper measured |
| - | What the retry is worth depends on what fraction of your list fails at all. Papers that report | + | What the retry is worth depends on what fraction of your list fails at all. Seven papers whose attrition figures were surfaced by the retry and attrition probes and then read and verified individually — **not** an exhaustive list; the attrition probe suggests of the order of 38 crawled papers |
| ^ Paper ^ Population ^ Reached ^ What the rest were ^ | ^ Paper ^ Population ^ Reached ^ What the rest were ^ | ||
| Line 613: | Line 718: | ||
| | Demir et al., PoPETs 2024 {[demir2024_bannertools]} | a Tranco sample | 29,660 (99%) | not broken out | | | Demir et al., PoPETs 2024 {[demir2024_bannertools]} | a Tranco sample | 29,660 (99%) | not broken out | | ||
| - | Two patterns to take from that table. A top-1M crawl reaches roughly | + | Two patterns to take from that table. A top-1M crawl reaches roughly |
| Retries also come in shapes other than "do it again" | Retries also come in shapes other than "do it again" | ||
| Line 624: | Line 729: | ||
| **29 of 1,120 crawled papers (2.6%)** state how many browsers or workers they ran at once. That is nearly all the published guidance there is on sizing a crawl machine, and it is a probe result with a hand-read verdict on every hit: a further 4 say they were parallel without a number, 5 parallelise an analysis stage rather than the crawl, and 6 are about something else entirely. | **29 of 1,120 crawled papers (2.6%)** state how many browsers or workers they ran at once. That is nearly all the published guidance there is on sizing a crawl machine, and it is a probe result with a hand-read verdict on every hit: a further 4 say they were parallel without a number, 5 parallelise an analysis stage rather than the crawl, and 6 are about something else entirely. | ||
| + | |||
| + | Six of the 29, chosen to span the range of scale in the class — one desktop, one cloud VM, one departmental cluster, and the three papers that also give a throughput or a wall clock: | ||
| ^ Paper ^ Hardware ^ Concurrency ^ | ^ Paper ^ Hardware ^ Concurrency ^ | ||
| Line 639: | Line 746: | ||
| ===== Monitoring ===== | ===== Monitoring ===== | ||
| - | **16 of 1,120 crawled papers (1.4%)** name a monitoring | + | **16 of 1,120 crawled papers (1.4%)** name a monitoring |
| * **Terminal rows per hour.** Not "pages fetched" | * **Terminal rows per hour.** Not "pages fetched" | ||
| Line 651: | Line 758: | ||
| ===== Cost ===== | ===== Cost ===== | ||
| - | **5 of 1,120 crawled papers (0.4%) state an infrastructure bill.** A further | + | A probe for a currency figure beside a cost word in a measurement context returns |
| All eight, in full. The **Kind** column matters: only the first five are a machine bill, and the row that classifies a paper is the one whose sentence the probe matched, not the paper' | All eight, in full. The **Kind** column matters: only the first five are a machine bill, and the row that classifies a paper is the one whose sentence the probe matched, not the paper' | ||
| Line 665: | Line 772: | ||
| | Song et al., PoPETs 2026 {[song2026_wfpllm]} | data | " | | Song et al., PoPETs 2026 {[song2026_wfpllm]} | data | " | ||
| - | Since nobody | + | Eight figures spread over sixteen years and four pricing models |
| - **Machine-hours** = (sites × attempts) ÷ (workers per machine × sites per worker-hour). At Bouhoula et al.'s 300 sites/ | - **Machine-hours** = (sites × attempts) ÷ (workers per machine × sites per worker-hour). At Bouhoula et al.'s 300 sites/ | ||
| Line 695: | Line 802: | ||
| - **Record the gap in the same units as your results.** Not "we had some downtime" | - **Record the gap in the same units as your results.** Not "we had some downtime" | ||
| - **Decide what the gap does to your inference, and say so.** Wang et al. quantified it as 4.5% of broadcasts missing {[wang2016_anatomy]}; | - **Decide what the gap does to your inference, and say so.** Wang et al. quantified it as 4.5% of broadcasts missing {[wang2016_anatomy]}; | ||
| - | - **Check that the gap is not correlated with what you measure.** A crawl that dies overnight loses the sites that sort late in the list; a crawl that dies on Fridays loses whatever is different about weekends. If your queue orders by rank, a mid-run failure is a systematic loss, not a random one — shuffle the queue at seed time, or say the loss was ordered. | + | - **Check that the gap is not correlated with what you measure.** A crawl that dies overnight loses the sites that sort late in the list; a crawl that dies on Fridays loses whatever is different about weekends. If your queue orders by rank, a mid-run failure is a systematic loss, not a random one — shuffle the queue at seed time, or say the loss was ordered. The script above shuffles deterministically, |
| - **Check whether the environment changed while it was down.** A restart after a package update is a new instrument. [[Design: | - **Check whether the environment changed while it was down.** A restart after a package update is a new instrument. [[Design: | ||
| - **Then decide whether to extend.** Extending the window to recover lost coverage stretches the measurement period, which is a temporal confound, not a free fix. Say which you did. | - **Then decide whether to extend.** Extending the window to recover lost coverage stretches the measurement period, which is a temporal confound, not a free fix. Say which you did. | ||
| Line 704: | Line 811: | ||
| - **The wall-clock window**, with both endpoints at day precision. Only 230 of 1,120 crawled papers manage this, and it is the cheapest sentence on the list. | - **The wall-clock window**, with both endpoints at day precision. Only 230 of 1,120 crawled papers manage this, and it is the cheapest sentence on the list. | ||
| - | - **Whether that window is machine time or content coverage.** A quarter | + | - **Whether that window is machine time or content coverage.** A fifth of the day-precision spans in this corpus |
| - **The population, and how much of it you reached** — the numerator, the denominator, | - **The population, and how much of it you reached** — the numerator, the denominator, | ||
| - **The retry policy**: how many attempts, which errors were terminal, and whether the retry was immediate or at the end of the queue. If a retry pass changed your numbers, say by how much {[hausladen2025_websites]}. | - **The retry policy**: how many attempts, which errors were terminal, and whether the retry was immediate or at the end of the queue. If a retry pass changed your numbers, say by how much {[hausladen2025_websites]}. | ||
| - | - **Concurrency and hardware**, in the same sentence: N browsers on M cores with K GB. 29 papers | + | - **Concurrency and hardware**, in the same sentence: N browsers on M cores with K GB. 29 papers |
| - | - **The infrastructure**: | + | - **The infrastructure**: |
| - **Any interruption, | - **Any interruption, | ||
| - | - **The cost**, if you can. Five papers in sixteen | + | - **The cost**, if you can. Across seventeen publication |
| ===== Related pages ===== | ===== Related pages ===== | ||
| Line 729: | Line 836: | ||
| Corpus figures come from '' | Corpus figures come from '' | ||
| - | Three limits worth stating plainly. **The duration figures rest on a hand classification**, | + | Three limits worth stating plainly. **The duration figures rest on a hand classification**, |
| <bibtex bibliography></ | <bibtex bibliography></ | ||
| ~~DISCUSSION~~ | ~~DISCUSSION~~ | ||
programming/deployment.txt · Last modified: by karel.kubicek.claude
