Feature request: bounded parallel blob fetch when indexing one account (S3 stores, v1.1.1)

Feature request, not a bug: the docs say one partition is indexed by one worker, and the code does that. On a remote blob store it caps one account at ~4-5 docs/s. Measured cause and a small proposed change below.

Setup. 3 nodes, v1.1.1. PostgreSQL data + search store (Patroni). Blobs on Backblaze B2 s3.us-east-005, path style. Indexing pacing tried at two settings (batch x tasks 10x1 and 100x4): no change in the per-account rate.

What we see. After switching the search store, each account reindexes at about 4-5 docs/s (6.4-6.7 at best), whatever the pacing settings. The nodes are idle. PG has 0 busy backends in 30 one-second samples, data store reads take 0.6 ms and writes 1.4 ms. Stalwart’s own metrics show blob read mean 222-356 ms and index batch mean 11-18 s.

B2 measurement. We ran GETs on 200 real message blobs per round, from one node, with keep-alive connections, stratified by size (5 KB to 5 MB):

parallel obj/s p50 total latency
1 3.55 ~180-280 ms
8 22.8 ~155-283 ms
16 47.4 ~190-276 ms
  • Time to first byte is ~180-250 ms whatever the size; transfer of a 5 MB object is ~26 ms.
  • Per-request latency is flat up to 16 parallel, with 0 errors. The store scales, so the limit is the serial fetch.

Cause in source (v1.1.1).

  • services/src/index_queue/index.rs:341-351: process_email_items awaits build_email_document for one item at a time.
  • document.rs:37: each item does one full get_blob.
  • So one partition runs at about 1/(GET latency + parse).
  • maxConcurrentIndexTasks (manager.rs:44, :249) runs several partitions at once, but doesn’t speed up one account. docs/performance/search-indexing.md says the same. indexBatchSize only changes the flush size.

Why this is different from topic 1725. That one was about a client fetching blobs to show a list, and you said the client should not, or should parallelize its own requests. Here no client is involved. It’s the server’s own background reindex, and nothing outside Stalwart can make it fetch in parallel. The same limit hits a large mailbox after a search-store change or an FTS reindex. Your stalwart-migrate verify already checks blobs 16 at a time for the same reason (topic 2124).

Ask. Bounded concurrent blob fetch inside process_email_items. For example, map the round’s insert items to build_email_document futures and drive them with buffer_unordered(N) (or buffered(N) to keep order). N would be configurable with a small default such as 8 and maybe 1 for local blob stores. The FlushBudget check would apply as results arrive, and the per-node partition limit would stay as it is. Total GETs in flight per node would then be at most maxConcurrentIndexTasks x N.

Expected effect (estimate, from the table above, not from a patched build). About 20-25 docs/s per account at N=8 and about 40 at N=16, if parse stays cheap. For a 100k-message account that would be roughly 6 h down to about 1-1.5 h.

Tested and written with AI help.