Skip to content

SOLR-17841: Use DocSetCollector for multithreaded DocSet(Faceted) search - #4724

Open
punAhuja wants to merge 1 commit into
apache:mainfrom
SearchScale:puneet/SOLR-17841
Open

SOLR-17841: Use DocSetCollector for multithreaded DocSet(Faceted) search#4724
punAhuja wants to merge 1 commit into
apache:mainfrom
SearchScale:puneet/SOLR-17841

Conversation

@punAhuja

@punAhuja punAhuja commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

https://issues.apache.org/jira/browse/SOLR-17841

Description

Multithreaded(MT) search was slower than Singlethreaded(ST) search in the case of faceted queries. Faceted queries need a DocSet. ST already builds that with DocSetCollector. MT used a custom FixedBitSetCollector instead, and that made faceted search slower with MT on.

This PR fixes that DocSet path so enabling MT no longer makes faceting worse.

Solution

Two changes in MultiThreadedSearcher / SolrIndexSearcher:

  1. Multithreaded DocSet search now uses DocSetCollector, same as the single-threaded path. Each thread collects its own DocSet, then we OR them together. The old FixedBitSetCollector was only used here, so I removed it.
  2. multiThreaded=true now also needs a searcher thread pool. If indexSearcherExecutorThreads=0, we used to take the multithreaded path anyway and it could get very slow. That case now falls back to single-threaded.
    I used an AI coding assistant (Cursor) while investigating and drafting the change. I reviewed the diff, ran the tests, and did the benchmarks myself.

Tests

Unit test: TestMultiThreadedSearcher.testMultiThreadedDocSetMatchesSingleThreaded — same query, needDocSet=true, ST vs MT DocSets must match on a multi-segment index.

Latency was measured with solr-bench (one client query at a time; searcher
pool -Dsolr.searchThreads=-1). Suites, generator, NoMerge configset, and
how to run it:

https://github.com/SearchScale/solr-bench/tree/puneet/SOLR-17841-mt-search

I compared the same 1M-doc index merged vs forced to ~500 segments
(NoMergePolicy, flush every 2000 docs). Queries are event_time range +
event_type filter, with and without facets.

mean p50 p95
facet, few segments, MT before ~15.1 ~6.0 ~66
facet, few segments, after (ST / MT) 7.14 / 7.65 6.38 / 6.86 12.43 / 13.80
plain, many segments (ST / MT) 4.55 / 3.36 2.75 / 2.78 21.56 / 7.75
facet, many segments (ST / MT) 15.79 / 14.78 12.22 / 12.44 38.28 / 30.59

After the fix, facet MT is no longer worse on a normal index. With many
segments MT can win, especially on plain queries and p95.

NOTE: Still investigating whether MT can actually beat ST more broadly.

This PR only addresses the DocSet collector used for faceting. After the change, facet MT is no longer worse on a normal index, and with many segments MT can win (especially plain queries and p95).
Renato's findings on SOLR-17841 look like a separate bottleneck. Even with 50M docs force-merged to 5 segments, range queries were ~5× slower under MT; the profile pointed at SolrRangeQuery / FixedBitSet.or, not this collector. I want to look at that next.

Checklist

Please review the following and check all that apply:

  • I have reviewed the guidelines for How to Contribute and my code conforms to the standards described there to the best of my ability.
  • I have created a Jira issue and added the issue ID to my pull request title.
  • I have given Solr maintainers access to contribute to my PR branch. (optional but recommended, not available for branches on forks living under an organisation)
  • I have developed this patch against the main branch.
  • I have run ./gradlew check.
  • I have added tests for my changes.
  • I have added documentation for the Reference Guide
  • I have added a changelog entry for my change

@punAhuja punAhuja changed the title SOLR-17841: Use DocSetCollector for multithreaded DocSet search SOLR-17841: Use DocSetCollector for multithreaded DocSet(Faceted) search Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant