Parallelize Query Execution Across Segments
On this page
The concurrent
option enables intra-query parallelism. In this mode,
Atlas Search utilizes more resources, but improves each individual query
latency. This feature is only available for dedicated Search Nodes.
Syntax
concurrent
has the following syntax:
{ "$searchMeta"|"$search": { "index": "<index name>", // optional, defaults to "default" "<operator>": { <operator-specifications> }, "concurrent": true | false, ... } }
Behavior
The concurrent
boolean option allows you to request Atlas Search to
parallelize query execution across segments, which, in many cases,
improves the response time. You can set one of the following values for
the concurrent
option:
true
- to request Atlas Search to run the query multi-threadedfalse
- to run the query single-threaded (default)
Atlas Search provides you control over this behavior on a per-query basis to enable concurrent execution only for heavy and long-running queries, which minimizes the contention and improves overall query throughput. Concurrent execution is especially efficient on large datasets, as there is a larger amount of segments.
Limitation
When you run queries with the concurrent
option, Atlas Search doesn't
guarantee that each query will be executed concurrently. For example,
when too many concurrent queries are queued, Atlas Search
might fallback to single-threaded execution.
Example
Consider the following query against the sample_mflix.movies collection in the sample data. The query indicates a
concurrent search for movies that contain the term new york
in the
title
.
1 db.movies.aggregate([ 2 { 3 "$search": { 4 "text": { 5 "path": "title", 6 "query": "new york" 7 }, 8 "concurrent": true 9 } 10 } 11 ])