Send host info on a specific stream
Could be used to notify that a status HTTP 429 has been caught (see ##784 on that topic) or that the robots.txt specified a delay. A bespoke bolt could then notify a URL Frontier via setDelay or blockQueueUntil
see #504 for a related discussion
Now that #1973 covers the explicit case (429/503 with a Retry-After header), I'd like to tackle the case we probably see most in the wild: servers that rate-limit without sending any header at all. Today we just fetch the host again and collect another 429.
The idea, kept short:
FetcherBolt already emits on the hostinfo stream when there's a header. I'd widen that signal with a kind field, so a headerless 429/503 becomes a "pressure" event. The consumer bolt keeps a small per-host counter and blocks the queue in the frontier for a growing duration: 60s the first time, then 2 minutes, 4, 8, capped at a day. If the host stays quiet for half an hour the counter is forgotten and the next incident starts from scratch.
Nothing new under the sun: Nutch has done this since 1.19 ( NUTCH-2946, same doubling curve, same 30 minute reset). The difference is where the state lives.Nutch keeps it inside the fetcher and later had to patch around fetching going stale when only backed-off queues remain (NUTCH-3114). With the state in the frontier a blocked host never reaches the fetcher in the first place, so that class of problem can't happen. Workers stay stateless, which is also the reason #1944 was closed.
One subtlety worth calling out. When the first 429 arrives there may be a dozen URLs of that host already sitting in the fetcher's internal queues. They will fail one after the other, and each of those failures must not escalate the counter, otherwise a single incident jumps straight to the 24h cap. So: escalate at most once per block window. Same trick TCP uses, where multiple losses inside one RTT count as a single congestion event.
A couple of questions before I write any code:
- Enforcement: I'd use
blockQueueUntilwith growing durations. Blocks expire on their own, so there is nothing to reset and no way to leave a host throttled forever.setDelaywould be the gentler alternative (host stays crawlable, just slower), but it needs an explicit reset andsetDelay(key, 0)also wipes any server-side default delay for that queue. Does anyone feel strongly about throttling instead of blocking? - Should the headerless back-off also count fetch exceptions (timeouts, connection refused), like Nutch does and #1106 asks for? I'd put that behind a config flag, off by default.
- The 429'd URLs already sitting in the fetcher's queues: purge them to the status stream, or let them fail and reschedule on their own? Same question is open on #1973 , whatever we decide there applies here too.
If this sounds reasonable I'll put a PR together once #1973 has landed.
60s the first time, then 2 minutes, 4, 8, capped at a day.
One experience from the Nutch implementation (not fixed there): add a small random jitter to avoid that the retries after a day cause a spike in errors. The crawler might hit most of the blocked sites during the first hour, then you see spikes every day.
- Enforcement: ... Does anyone feel strongly about throttling instead of blocking?
Alternatively, keep them in the fetcher queues as long as the delay is very short (< 3 mins), then call blockQueueUntil. But that makes the implementation more complex. No strong preference.
- Should the headerless back-off also count fetch exceptions (timeouts, connection refused) ... I'd put that behind a config flag, off by default.
Yes, definitely. A timeout is even worse, because resources are occupied until it's hit.
And yes, make it configurable. Would be good, if also the list of HTTP status codes triggering the back-off is configurable.
There are several status codes, depending on the bot protection software - this paper sheds some light on the topic. (also included in this thesis.)
- The 429'd URLs already sitting in the fetcher's queues: purge them to the status stream, or let them fail and reschedule on their own?
Let them fail: The URLs were not send as request and have not received a HTTP 429 yet, right? And there's no status which encodes a PURGE.
add a small random jitter to avoid that the retries after a day cause a spike in errors
Taking this. I had dismissed jitter on the theory that per-host blocks are unsynchronized, but that assumption breaks exactly as you describe: the crawl collects most of its first 429s early on, the blocks escalate on the same schedule, and the capped ones expire together. A fetcher.backoff.jitter fraction on every computed block is cheap insurance.
Alternatively, keep them in the fetcher queues as long as the delay is very short (< 3 mins), then call
blockQueueUntil. But that makes the implementation more complex.
I'd keep the first version simple and always go through the frontier. The short-delay case costs one extra round-trip through the status stream, which seems acceptable; can revisit if it hurts in practice.
Would be good, if also the list of HTTP status codes triggering the back-off is configurable.
Will do: fetcher.backoff.status.codes, defaulting to 429 and 503. The paper is a useful pointer for what else bot-protection stacks return. I'd leave 403 to configuration rather than the default, since it so often just means "forbidden".
Yes, definitely. A timeout is even worse, because resources are occupied until it's hit.
Agreed on including it then. I'd still start with the flag off and flip the default once the basic back-off has seen some real crawls: exceptions are a noisier signal than a clean 429.
Let them fail: The URLs were not send as request and have not received a HTTP 429 yet, right? And there's no status which encodes a PURGE.
Right, they were only queued, never sent. Letting them fail also keeps the counter honest: failures inside one block window escalate at most once, so the backlog cannot inflate the delay.
One update since my comment above: following the discussion on #1973, the signal will ride the generic queue stream (key, metadata) from the status updater rather than a dedicated stream from the fetcher. The consumer can tell the two cases apart from the metadata (status code plus presence of the header), so the mechanics described here are unchanged.
I was about to forgot it :-) anyw for me is closed - Guys, if it isn't, or u wanna discuss it further, feel free to reopen! #504 remains open for broader host statistics...