Repository navigation
fix(ingest): bounded window concurrency for neural _bulk embedding (#938 slice 1) - #995
Merged
Merged
Conversation
slice 1) Motivation: with --embed-mode neural, one _bulk stream into a semantic_text field kept only ~3 of 32 threads busy. The _bulk embedding loop cut each request into scheduling windows of onnx_scheduling_window passages and then awaited them strictly in sequence (engine/crates/xerj-engine/src/index.rs, the pre-change for-loop in apply_semantic_embeddings_batch); the only concurrent scheduler, collect_ordinal_buffered_two, is gated on dual_session_scheduler_enabled = onnx_pinned && pool_size == 2 and therefore never applies to the neural backend. At any instant one request had exactly one BERT forward pass in flight, and the only parallelism was Candle's intra-op threading, which tops out near 3.5 cores (#938). What changed (slice 1 of the issue's plan — window-level data parallelism, no dependency changes; Candle intra-op pinning and pool sizing stay open): - New collect_ordinal_buffered(count, bound, launch) in index.rs next to collect_ordinal_buffered_two: a bounded-concurrency, order-preserving scheduler over std::future::poll_fn. At most bound futures are in flight, finished futures are retired strictly from the front, results return in ordinal order, and a window that fails as a value neither cancels nor displaces its neighbours (same contract as the pair scheduler). - The _bulk embedding loop now routes every non-dual-ONNX backend through it with bound = embedding.neural_window_concurrency. Default 1 preserves the historical serial loop exactly; the ONNX pool-size-2 path is untouched. - New [embedding] key neural_window_concurrency (default 1, range 1..=64) in xerj-common config.rs with validation, plus xerj.default.toml documentation; user-facing settings count 120 -> 121 (section table, module header, lib.rs, default toml, EXPECTED_SETTINGS all updated in step, as the counting tests require). - Each window is still embedded as its own batch and reassembled by position, so per-passage vectors are identical to the serial loop; a unit test pins that (same window batches, same vectors at bounds 1/2/8). Measured in THIS sandbox (shared box, loadavg 6-13 of 32 threads; release build, all-MiniLM-L6-v2 via candle on CPU; synthetic corpus of 300 docs, mean 1,470 chars ~= 4 passages each, one _bulk stream of 50 docs; harness benchmarks/neural-path-triage/window_concurrency_bench.py, warmup pass excluded, wall + server utime+stime from /proc): neural_window_concurrency docs/s server_cpu_s avg_cores_busy 1 (default, = main) 14.1/13.6 67.1 3.2/3.0 2 21.3 66.2 4.7 4 39.1 68.9 9.0 8 38.9 68.9 8.9 1, eight clients 54.0 71.3 12.8 4, eight clients 83.9 78.3 21.9 2.8x from one stream at the same CPU-seconds; one stream with the fix now reaches ~72% of what eight client streams extract from the serial server. 8 == 4 because a 50-doc _bulk at this shape holds ~4 windows of <=64 passages, so 4 is the per-request ceiling (cross-request pool sharing is the issue's slice 3). These are my numbers on this box; the issue's 6.1 docs/s at 3.4 cores is its own measurement on different hardware and is not verification of this change. Tests: 3 new scheduler tests (full-window concurrency proven via an in-flight gate, reversed completion + failure atomicity, bound-independent output) and 2 new config tests (serial default, bounded range) — fail-before proven by rebuilding with the production code stripped: E0432 unresolved import collect_ordinal_buffered, E0609 no field neural_window_concurrency. xerj-common 114 passed/0 failed, xerj-engine lib 686/0, engine es_compat 65/0 and integration 132/0 over the touched path, product_experience journey_zero_config green at 121 settings. ES-YAML conformance on a private port with a throwaway data dir: 1371 passed / 0 failed / 3 skipped (was 1371/0/3 on main). cargo clippy -D warnings clean, cargo fmt applied.
This was referenced Sep 21, 2026
Amakurai
pushed a commit
to Amakurai/xerj
that referenced
this pull request
Sep 27, 2026
…, rc.78 queue The 2026-09-21 review of this file was stale within hours: xerj-org#950 closed 19:33, xerj-org#941 19:38, xerj-org#1015 20:49 (all 2026-09-21), xerj-org#874 2026-09-22, and the stage-1 gating trio xerj-org#937/xerj-org#938/xerj-org#939 closed the same evening — every one recorded here as open or "under way". This pass re-checks every status claim against live tracker state and rolls the file forward: - Next release: the two "in flight" items (xerj-org#1015, xerj-org#950) are closed with fixes on main riding to rc.78 — the section now records what actually landed since the rc.77 tag (xerj-org#1009, xerj-org#1017, xerj-org#1018, xerj-org#1020, xerj-org#1021, xerj-org#1023, xerj-org#1025, xerj-org#1026, xerj-org#1033, xerj-org#1034) with PR links, including xerj-org#874's budget met at ~3x margin (206 -> 64 kB per idle index) and discussion xerj-org#1012's email-labelling measurement (1.000 templated tier / 0.625 at 0.902 confidence on the hard tier — wrong-and-confident). - Open defects: now xerj-org#1031 and xerj-org#1032 only; xerj-org#1015/xerj-org#950 removed (closed); trackers sentence corrected (xerj-org#941, xerj-org#874 closed — only xerj-org#298 remains by design). - GA gate: "Close the CHANGELOG gap" marked closed 2026-09-26 (the rc.19-rc.70 backfill, PR xerj-org#1035); the record-complete note replaces the gap warning under "Shipping today". - Zero-token: stage-1 gating trio recorded as fixed (xerj-org#991, xerj-org#995, xerj-org#979) with the old measured costs kept as the before-state; the xerj-org#940 hash-seed spread annotated as a pre-fix measurement; stage-2 object storage marked done (xerj-org#965 wired in rc.77 — the old bullet contradicted this file's own "Shipping today" section); mail ingest "unreleased" corrected to "shipped in rc.75"; three stale "In flight:" labels on landed stage-1 items relabelled "History:". - Mail-ingest memory line: xerj-org#948's runaway is fixed (xerj-org#1002) — the line now carries the fixed numbers and points at xerj-org#1032 for the residual. Review line updated to 2026-09-26 (machine-checked format), scoped honestly as a desk review. The milestones line is true again: rc.78 milestone created, all four open issues triaged (xerj-org#1030/xerj-org#1031/xerj-org#1032 -> rc.78, xerj-org#298 -> GA).
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.
Problem
With
--embed-mode neural, one_bulkstream into asemantic_textfield kept only ~3 of 32 hardware threads busy (#938). The_bulkembedding loop cut each request into scheduling windows ofonnx_scheduling_windowpassages and then awaited them strictly one after another; the only concurrent scheduler in that function,collect_ordinal_buffered_two, is gated ondual_session_scheduler_enabled=onnx_pinned && pool_size == 2, which never applies to the neural backend. At any instant one request had exactly one BERT forward pass in flight, and the only parallelism was Candle's intra-op threading, which tops out near 3.5 cores.Root cause
engine/crates/xerj-engine/src/index.rs,apply_semantic_embeddings_batch: window boundaries are computed up front (semantic_embedding_window_end) and each window'sembed_batchcall is awaited in a serialforloop. The neural embedder is&selfand safe to call concurrently (NeuralEmbedder::embed_blockingbehindArc, onespawn_blockingper call), so the serialization is purely the caller-side loop.Fix (slice 1 of the issue's plan — no dependency changes)
collect_ordinal_buffered(count, bound, launch)beside the existing pair scheduler: a bounded-concurrency, order-preserving scheduler overstd::future::poll_fn. At mostboundfutures in flight; finished futures retire strictly from the front; results return in ordinal order; a window that fails as a value neither cancels nor displaces its neighbours (same per-window failure contract as the pair scheduler, whose ONNX dual-session path is untouched)._bulkembedding loop routes every non-dual-ONNX backend through it withbound = embedding.neural_window_concurrency. Default 1 preserves the historical serial loop exactly.[embedding]keyneural_window_concurrency(default1, range1..=64) with validation inxerj-common/src/config.rs, documented inxerj.default.toml; user-facing settings count 120 → 121 updated in lockstep everywhere the counting tests pin it (SETTINGS_BY_SECTION, module header,lib.rs,EXPECTED_SETTINGS).benchmarks/neural-path-triage/window_concurrency_bench.py(synthetic corpus, no BEIR download; same reported columns as the existingingest_bench.py: docs/s,server_cpu_sfrom/proc, avg cores busy).Measurements (this sandbox, shared box loadavg 6–13 of 32 threads; release build; all-MiniLM-L6-v2 via candle on CPU — genuinely neural, not the lexical default; 300 synthetic docs, mean 1,470 chars ≈ 4 passages, one
_bulkstream of 50; warmup pass excluded)2.8× from one stream at the same CPU-seconds (67.1 → 68.9 for 14.1 → 39.1 docs/s). One stream with the fix reaches ~72% of what eight client streams extract from the serial server. 8 == 4 because a 50-doc
_bulkat this corpus shape holds ~4 windows of ≤64 passages, so 4 is the per-request ceiling — cross-request pool sharing is the issue's slice 3, as are Candle intra-op pinning (slice 2) and a non-serial default. These are my numbers on this box; the issue's 6.1 docs/s at 3.4 cores is its own measurement on different, more contended hardware and is context, not verification.Test evidence
boundfutures are simultaneously in flight; reversed completion drained in ordinal order with failure atomicity; output independence from the bound) and 2 new config tests (serial default round-trip, bounded range 0/65 rejected).E0432 unresolved import super::collect_ordinal_buffered,E0609 no field neural_window_concurrency on EmbeddingConfig; restored and green after.es_compat_tests65/0 andintegration132/0 over the touched path,product_experience::journey_zero_configgreen at 121 settings.cargo clippy -D warningsclean on both touched crates;cargo fmtapplied.Fixes #938