Limits | rust-crawler | Spatie       

 SPATIE  

rust-crawler
============

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Rust-crawler](https://spatie.be/docs/rust-crawler/v1)  Configuring-the-crawler  Limits

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/rust-crawler/v1) 

  Limits    
- [ Introduction ](https://spatie.be/docs/rust-crawler/v1/introduction)
- [ Installation &amp; setup ](https://spatie.be/docs/rust-crawler/v1/installation-setup)
- [ Support us ](https://spatie.be/docs/rust-crawler/v1/support-us)
- [ Questions and issues ](https://spatie.be/docs/rust-crawler/v1/questions-issues)
- [ Changelog ](https://spatie.be/docs/rust-crawler/v1/changelog)
- [ About us ](https://spatie.be/docs/rust-crawler/v1/about-us)

Basic usage
-----------

- [ Your first crawl ](https://spatie.be/docs/rust-crawler/v1/basic-usage/starting-your-first-crawl)
- [ Crawl responses ](https://spatie.be/docs/rust-crawler/v1/basic-usage/handling-crawl-responses)
- [ Using observers ](https://spatie.be/docs/rust-crawler/v1/basic-usage/using-observers)
- [ Collecting URLs ](https://spatie.be/docs/rust-crawler/v1/basic-usage/collecting-urls)
- [ Filtering URLs ](https://spatie.be/docs/rust-crawler/v1/basic-usage/filtering-urls)
- [ Testing ](https://spatie.be/docs/rust-crawler/v1/basic-usage/testing)
- [ Tracking progress ](https://spatie.be/docs/rust-crawler/v1/basic-usage/tracking-progress)

Configuring the crawler
-----------------------

- [ Concurrency &amp; throttling ](https://spatie.be/docs/rust-crawler/v1/configuring-the-crawler/crawl-behavior)
- [ Limits ](https://spatie.be/docs/rust-crawler/v1/configuring-the-crawler/setting-crawl-limits)
- [ Extracting resources ](https://spatie.be/docs/rust-crawler/v1/configuring-the-crawler/extracting-resources)
- [ Configuring requests ](https://spatie.be/docs/rust-crawler/v1/configuring-the-crawler/configuring-requests)
- [ Response filtering ](https://spatie.be/docs/rust-crawler/v1/configuring-the-crawler/handling-responses)
- [ Respecting robots.txt ](https://spatie.be/docs/rust-crawler/v1/configuring-the-crawler/respecting-robots-txt)

Advanced usage
--------------

- [ JavaScript rendering ](https://spatie.be/docs/rust-crawler/v1/advanced-usage/rendering-javascript)
- [ Custom link extraction ](https://spatie.be/docs/rust-crawler/v1/advanced-usage/extracting-custom-links)
- [ Custom request handlers ](https://spatie.be/docs/rust-crawler/v1/advanced-usage/custom-request-handlers)
- [ Crawling across requests ](https://spatie.be/docs/rust-crawler/v1/advanced-usage/crawling-across-requests)
- [ Custom crawl queue ](https://spatie.be/docs/rust-crawler/v1/advanced-usage/using-a-custom-crawl-queue)
- [ Graceful shutdown ](https://spatie.be/docs/rust-crawler/v1/advanced-usage/graceful-shutdown)

 Limits
======

###  On this page 

1. [ Crawl depth ](#content-crawl-depth)
2. [ Execution and cumulative budgets ](#content-execution-and-cumulative-budgets)
3. [ Combining limits with a checkpoint ](#content-combining-limits-with-a-checkpoint)
4. [ Time limits are not process deadlines ](#content-time-limits-are-not-process-deadlines)

By default, the crawler continues until its frontier is empty. Set page, depth and time budgets explicitly for large or untrusted sites.

Crawl depth
-----------------------------------------------------------------------------------------

The seed has depth 0. `max_depth(0)` fetches the seed without following its discoveries; `max_depth(1)` also fetches its direct links. Additional `seed_urls` are independent roots at depth 0.

```
use spatie_crawler::Crawler;

fn shallow_crawler() -> spatie_crawler::Result {
    Crawler::builder("https://example.com")?
        .max_depth(2)
        .build()
}
```

The crawler fetches pages at the maximum depth but does not schedule their discoveries. XML sitemap discoveries preserve the sitemap's depth rather than adding an HTML-link level, but discovery scheduling still stops at the configured maximum depth. First discovery wins during deduplication; concurrency does not guarantee that the recorded depth is the shortest path.

Execution and cumulative budgets
--------------------------------------------------------------------------------------------------------------------------------------------------------

MethodBudget`max_pages(count)`URL jobs in this execution`max_pages_total(count)`Persisted URL-attempt budget across executions`time_limit(duration)`Elapsed time in this execution`time_limit_total(duration)`Cumulative elapsed time across executionsAll four default to unlimited. When both execution and cumulative limits are set, the tighter remaining budget wins. Zero pages is valid and fetches nothing.

Page budgets count URL jobs, including HTTP/transport failures, MIME skips and noindex skips. A retry stays in the same job. Scope, depth and robots.txt refusals before fetching do not consume page attempts. Robots requests are not page attempts. Attempt slots are reserved before concurrent work, preventing page-budget overshoot. Persisted attempts are not refunded when an in-flight job is cancelled.

Combining limits with a checkpoint
--------------------------------------------------------------------------------------------------------------------------------------------------------------

This reusable function processes at most 5 URL jobs per invocation, up to 10 persisted attempts in total. Reopening the same database resumes remaining work.

```
use std::path::Path;
use std::time::Duration;
use spatie_crawler::{CrawlEvent, Crawler, FinishReason, SqliteStore};

async fn run_batch(database: &Path) -> Result {
    let mut crawl = Crawler::builder("https://example.com")?
        .store(SqliteStore::open(database)?)
        .max_pages(5)
        .max_pages_total(10)
        .time_limit(Duration::from_secs(30))
        .time_limit_total(Duration::from_secs(60))
        .build()?
        .crawl();

    let mut reason = FinishReason::Completed;
    while let Some(event) = crawl.next().await {
        if let CrawlEvent::Finished {
            reason: finished,
            error,
            ..
        } = event
        {
            if let Some(error) = error {
                return Err(error.into());
            }
            reason = finished;
        }
    }
    Ok(reason)
}
```

Page-budget exhaustion with queued work produces `FinishReason::PageLimit`. Time-budget exhaustion produces `FinishReason::TimeLimit`. Inspect the final event's `error` as well as its reason for storage or scheduler failures.

Use one scheduler per store. Wait for the old stream to finish before reopening its checkpoint, and keep the same seed. Configuration is not stored, so apply the desired limits on each invocation. Completed, failed and skipped URLs remain terminal. Use a new checkpoint for a fresh crawl. A checkpoint stores the frontier and budgets, not an acknowledged archive of page events.

`Progress::attempted` and stored success/failure/discovery counts are cumulative. `elapsed_ms` and retry count describe this execution; `total_elapsed_ms` includes prior executions. Elapsed time includes initialization and output backpressure and is persisted on graceful completion. A hard crash can lose elapsed time since the last completion, but does not refund stored attempts.

Time limits are not process deadlines
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

Time budgets use `Duration`. They stop scheduling work and recover pending claims, but do not guarantee the process exits or output flushes at that instant. A blocked observer or event consumer can delay completion. Already-running blocking extraction can outlive cancellation. Keep draining the stream after cancellation to receive the final event.

Use [request timeouts](configuring-requests) to bound individual asynchronous fetches and renderer calls. Use [response limits](handling-responses) to bound individual bodies. Neither those limits nor the event buffer provide a global memory bound, and there is no total-frontier-size limit.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
