URLFrontier Spout: depth metrics to observe and drive the breadth of the crawl
With URLFrontier the order of the crawl is decided entirely by the frontier: it rotates between queues (one per host) and serves each queue FIFO. The depth of a URL plays no role, so a crawl that starts broad can sink into the deep pages of a few large hosts (pagination, facets) without anything in the topology showing it. GetURLs gives no way to ask for shallow URLs either, so before adding any steering it must be possible to measure the shape of the crawl.
Proposal: have the URLFrontier Spout count the URLs handed out by the frontier per depth level, using the depth metadata written when metadata.track.depth is enabled:
- a
depthcounter with one scope per depth (depth.0,depth.1, ...), anunknownscope for URLs without a numeric depth, and a singleN+scope fromurlfrontier.depth.metric.max(default 10) upwards so that the number of scopes stays bounded; - a
depth_lecounter with cumulative counts in the style of Prometheus histograms (depth_le.X= URLs with depth <= X,depth_le.inf= total), so that P(depth <= X) is a plain ratio in a dashboard; probabilityDepthAtMost(int)andwindowProbabilityDepthAtMost(int)on the spout, returning that ratio in constant time since the spout was opened and over a sliding window ofurlfrontier.depth.window.secs(default 300), for a future control loop inpopulateBuffer(e.g. more queues with fewer URLs each when the recent share of shallow URLs drops).
No change to the behaviour of the crawl, only observability. Steering (adaptive max.buckets / urls.per.bucket, or explicit queue selection with the key parameter) can follow in a separate issue once the metric shows the drift on real crawls.
thanks @GGraziadei
With URLFrontier the order of the crawl is decided entirely by the frontier: it rotates between queues (one per host) and serves each queue FIFO
this needs checking but if I remember correctly, this is might not be the case. The priority of a queue in URLFrontier is determined by the earliest nextFetchDate of its URLs. The depth of a URL is usually reflected by its nextFetchDate.
On a more general note, the advantage of using URLFrontier is that we delegate a lot of the logic away from SC - what you are suggesting it would reintroduce some of it. If we want to change the way URLs are served by URLFrontier then it should happen there.
Having said that, if we just want to observe things, this is totally OK but I would argue that it does not have to be done within the spout if we can avoid it. Can this be done in a separate bolt? a bit like https://github.com/apache/stormcrawler/blob/main/external/opensearch/src/main/java/org/apache/stormcrawler/opensearch/metrics/StatusMetricsBolt.java
Better still, you can do similar measurements within URLFrontier itself and let it report the metrics. Other crawlers would benefit from it and not just SC.
Hi @jnioche thanks a lot for your comment. Happy to discuss here.
You're right that it isn't pure FIFO. Inside the selected queue, it pulls URLs from a heap ordered by nextFetchDate. Thanks for pointing me to StatusMetricsBolt. I'm moving the metrics code into a separate bolt and dropping my original approach.
My original idea was to improve the queue selection. The linked PR exposes the metrics needed to build a histogram of crawl depths explored so far. With that histogram, queue selection could be tuned to follow a specific crawling strategy.
This was the initial strategy, but based on your comment, I’m open to changing it to improve the outcome and make it available to other crawlers as well:
- Expose the metrics needed to build the depth histogram (this PR)
- Introduce an abstract CrawlingStrategy class
- Change the queue key from (host) to (host, depth) (*)
- When pulling, pick the depth as well as the host, based on the strategy
(*) keying queues on (host, depth) would split a host across several queues, while URLFrontier currently applies politeness per queue. what do you think about?
A strategy is defined by a target depth distribution (CDF). Below are a couple of example strategies just to explain my idea (just a sketch generated using Claude to transmit the qualitative idea):
As per your previous comment, this seems closer to the crawler-commons/url-frontier scope. If you think the idea is worth pursuing, would it be OK if I opened an issue there to discuss the design?
If you think the idea is worth pursuing, would it be OK if I opened an issue there to discuss the design?
absolutely! I think the crawl strategy should be delegated to URLFrontier when it is used. Unless it is implemented in a way that it can be used for other backend in SC (e.g. opensearch).
Can you explain what problem you are trying to solve here? Why do you think it depth matters when prioritising URLs? Isn't that what more or less what happens with the nextFetchDate approach we have in SC? (not to be the devil's advocate, just to understand why we need it)
+1 on a separate bolt. It can live in core: it only reads the depth metadata of the tuples, so it works with any backend.
(host, depth) as queue key breaks politeness, URLFrontier applies it per queue. Keep host queues and add a max depth to GetURLs frontier side; GetParams has nothing else to filter on today.
For the bolt: keep the two counters, drop the probability API until something uses it; a depth beyond the cap isn't 1.0; seeds carry no depth key, so depth.0 stays empty.
Hi @jnioche @dpol1, thanks a lot for your answers. I’m just checking whether my intuition has some grounding in the state of the art.
The general idea is to evaluate a metric that allows us to study the progress of a crawling strategy. The same idea is discussed in various papers, so I completely agree with your initial comment that this would be beneficial for the crawling process itself, not only SC.
I’ll close this comment and the linked PR, and open a new discussion thread, with a clear problem statement formulation, in the appropriate place once I have gathered enough evidence from the SOTA.
Some resources, I am evaluating:
- https://link.springer.com/chapter/10.1007/978-3-540-30216-2_13
- https://dl.acm.org/doi/abs/10.1145/371920.371965
- https://dl.acm.org/doi/10.1145/1067268.1067287
- https://www.science.org/doi/abs/10.1126/science.280.5360.95
Late to the party, but I am also wondering what is missing in practice.
Depth is tracked by default (metadata.track.depth) and MaxDepthFilter already caps it, globally or per seed via max.depth. That covers the case of a crawl sinking into pagination or facets on a few large hosts, although as a hard limit and not as an ordering.
If the goal is ordering, like in a focused crawl, that is possible today with the OpenSearch backend: the sort fields of the spout are configurable (opensearch.status.bucket.sort.field, opensearch.status.global.sort.field), so one can sort on depth or on a score instead of nextFetchDate.
The gap is with URLFrontier only. There is no priority in its API, and for DISCOVERED URLs we do not even send a date, so nothing on the SC side can influence the order in which new URLs are served. That would have to be added in URLFrontier, so +1 to discuss it there.
Hi @rzo1, Thank you very much for the detailed explanation, and apologies for the delay in getting back to you. I’ll proceed with closing this issue and the PR.