reugn opened a new pull request, #16995:
URL: https://github.com/apache/lucene/pull/16995

   `Monitor` matches a document in two steps. It searches the queryindex for 
candidate queries, then runs each candidate against the document. 
`ParallelMatcher` and `PartitionMatcher` can move the second step to a thread 
pool, but the queryindex search itself always runs on the calling thread, one 
segment after another.
   
   This change adds `MonitorConfiguration#setExecutor`. With an executor, the 
queryindex is searched in slices like any `IndexSearcher` with an executor, and 
each slice matches its candidates on its own thread with its own 
`CandidateMatcher` from the `MatcherFactory`. Once all slices are done, the 
matches and errors of the other slices are added to the first slice's matcher, 
and matches for the same query are combined with `resolve`. Without an 
executor, behavior is unchanged.
   
   Slices are sized by query count rather than by segment, since matching a 
candidate costs much more than an ordinary collect. `QueryIndexSearcher` groups 
small segments and splits large ones into slices of about 10,000 decomposed 
queries. So a queryindex of 10,000 decomposed queries or fewer is searched in a 
single slice and does not get faster.
   
   `TestMonitorConcurrency` compares an executor Monitor with a sequential one 
for the built-in matchers, and `MonitorTestBase` now randomly enables an 
executor for the existing tests.
   
   Measured with the new `MonitorBenchmark` in benchmark-jmh, matching one 
document of 300 terms against 100k two-term conjunctions with 4 threads (ms/op, 
1 fork, 5 iterations, lower is better):
   
   | Segments | Serial | `ParallelMatcher` | `PartitionMatcher` | Executor |
   |---|---|---|---|---|
   | 1 | 19.3 | 9.1 | 9.2 | 4.9 |
   | 4 | 18.0 | 8.8 | 7.8 | 5.3 |
   | 16 | 19.0 | 9.1 | 8.0 | 5.2 |
   
   On the base commit, serial was 18.9, 17.1 and 19.3 for 1, 4 and 16 segments, 
so the default path is within about 5%. The 16-segment serial figures are from 
5 forks, the others from 1.
   
   A few choices worth explaining:
   
   - `ParallelMatcher` is rejected with an `IllegalArgumentException` when an 
executor is configured. Each slice would create its own `ParallelMatcher`, 
whose workers block until the matcher finishes, and matchers only finish after 
every slice is searched. With a small pool, a slice can wait forever on a full 
queue. The check releases the workers before throwing. A wrapped 
`ParallelMatcher` is not detected. `PartitionMatcher` works with an executor 
and can share its pool.
   - `ParallelMatcher` and `PartitionMatcher` are not deprecated. They 
parallelize per candidate, which still helps a small queryindex with expensive 
queries, where the executor gets a single slice.
   - The other slices are merged after `doFinish`, because wrapping matchers 
such as `QueryTimeListener#timingMatcher` replace their matches there with 
`copyMatches`. Only matches and errors of the other slices are kept, so any 
other state a custom matcher holds is dropped. This is documented on 
`MatcherFactory`.
   - With an executor, `MonitorQuerySerializer`, `QueryDecomposer` and 
`QueryTimeListener` are called from slice threads, so they must be thread-safe. 
The internal state they touch is now thread-safe. The executor is not shut down 
on close.
   - The new `CandidateMatcher` merge methods are package-private, so the only 
new public API is `setExecutor` and `getExecutor`. The change is additive.
   
   Not in this change:
   
   - `PartitionMatcher` workers call `reportError` from pool threads, which 
writes a plain `HashMap`. This race is already on `main` and is not specific to 
the executor.
   - Let a `MatcherFactory` say whether it supports an executor, so the 
`instanceof ParallelMatcher` check goes away and wrapped matchers are covered 
too.
   - Revisit deprecating `ParallelMatcher` and `PartitionMatcher` with a 
benchmark of a small queryindex with expensive queries.
   
   Closes #16198


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to