Bound the memory search spends on --at, --latest-only and --dedup - #101
Merged
Conversation
These three each kept a map over every URL the query touched, which on a domain wildcard across every crawl is the most likely place ccrawl runs a machine out of memory. A CDX response is sorted by urlkey and every capture of a URL sits inside one urlkey group, so the winner inside a crawl can be decided as the crawl is read and the crawls merged afterwards. --at reduces each group as it goes by, keeps the per crawl winners in sorted runs, and merges the runs at the end. --latest-only writes the URLs it emitted for a crawl in the same urlkey order and checks the next crawl against them with a cursor that only moves forward. Both stay exact whatever the result size. --dedup is the exception because payload digests arrive in no order at all, so it gets a bounded exact set that forgets the coldest digests and says so. That error lets a duplicate through rather than dropping a unique record, which is the direction that matters. --max-buffer is the shared budget, 5,000,000 records by default, and it covers every crawl at once rather than each crawl on its own. Past it the run writes to temporary files under TMPDIR and removes them on the way out, and it warns once so the slowdown has an explanation. --at's result also goes out in index order rather than newest first once the result itself will not fit, since that ordering is the one thing that cannot be done without holding everything.
14 tasks
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #55.
--at,--latest-onlyand--dedupeach held a map keyed on every URL the query touched. A wildcard over a large domain across every crawl touches hundreds of millions of them, which is the most likely place ccrawl runs a machine out of memory.What changed
A CDX response is sorted by urlkey and every capture of a URL sits inside one urlkey group, so the winner inside a crawl can be decided while the crawl is being read.
--atreduces each urlkey group as it goes by, keeps the per crawl winners in sorted runs, and k-way merges the runs at the end.--latest-onlywrites the URLs it emitted for a crawl to a log in the same urlkey order, and checks the next crawl against every earlier log with a cursor that only moves forward.--dedupgets a bounded exact set instead, because payload digests arrive in no order and nothing about the index says otherwise. Past its ceiling it forgets the coldest digests and warns. That error lets a duplicate through rather than dropping a unique record, which is the direction that matters.--atand--latest-onlyare exact at any result size.--max-bufferis the shared budget, 5,000,000 records by default, and it covers every crawl at once rather than each crawl on its own, which is the difference between the ceiling the flag names and a hundred times it. Past the budget the run writes to temporary files underTMPDIR, removes them however it exits, and warns once so the slowdown has an explanation.One behaviour changes.
--atsorts its result newest first, which needs the whole result in hand. It still does up to the buffer; past it the result goes out in index order and the command says so on stderr.Real data
ccrawl search 'vi.wikipedia.org/wiki/*' -c CC-MAIN-2024-10,CC-MAIN-2023-14 -o jsonlwas pulled live and replayed through both the old maps and the new code with a 1,000 record budget, so every disk path ran:That is
TestCDXSpillAgainstRealIndexRecords, gated onCCRAWL_CDX_JSONLsince the repository does not carry a 30 MB fixture.Live against the index, at a budget small enough to force the temporary files, output matches the default budget exactly:
--at 2021-06over two crawls--max-buffer 100--latest-onlyover two crawls--max-buffer 50--dedupover two crawls--max-buffer 50Memory
TestCDXPickerScaleandTestCDXURLLogScale, gated onCCRAWL_SCALE_CDX, stream synthetic records shaped like a domain wildcard across ten crawls and sample peak heap while each implementation runs. The replacements are held to a 100,000 record budget:The map grows with the result and the picker does not. Below a couple of million records the map is the cheaper of the two, which is why the default budget is 5M rather than something small.
The 100M run is the honest limit of this machine: the picker traded the memory for disk and wanted more than the 6.5 GB free, since spilling costs roughly one line per URL per crawl. The map got to 2.5 GB and was still climbing.
Not done here
ccrawl search '*.wikipedia.org' --at 20240101 -c allin bounded RSS is the first box on the issue and it did not complete today.index.commoncrawl.orgis dropping pages, and a wide query fails the same way on both binaries:A single page failure aborting a query with no retry is worth its own issue. The box stays unticked until that query runs.
Checks
go test ./... -race,golangci-lint run ./...andscripts/docs-drift.share clean.--max-bufferis in the CLI reference with the ordering caveat and the note that the--atsort gets the same budget again.