concurrent オプションはクエリ内並列処理を有効にします。このモードでは 、 MongoDB Search はより多くのリソースを使用しますが、個々の クエリのレイテンシ は改善されます。この機能は 専用の検索ノードでのみ使用できます。
concurrent オプションの制限
When you run queries with the concurrent option, MongoDB Search doesn't guarantee that each query executes concurrently. For example, when too many concurrent queries are queued, MongoDB Search might fallback to single-threaded execution.
構文
concurrent の構文は次のとおりです。
{ "$searchMeta"|"$search": { "index": "<index name>", // optional, defaults to "default" "<operator>": { <operator-specifications> }, "concurrent": true | false, ... } }
動作
The concurrent boolean option allows you to request MongoDB Search to parallelize query execution across segments, which often improves the response time. You can set one of the following values for the concurrent option:
true- MongoDB Search にクエリをマルチスレッドで実行するようリクエストfalse- クエリをシングルスレッドで実行する場合(デフォルト)
MongoDB Search では、クエリごとにこの動作を制御して、重いクエリや長時間実行されるクエリのみの同時実行を有効にすることで、競合が最小限に抑えられ、クエリ全体のスループットが向上します。セグメントの量が多いため、同時実行は特に大規模なデータセットで効率的です。
CPU 使用率
MongoDB Search runs a concurrent query on multiple threads, so the query completes faster. But the query consumes more CPU on your Search Nodes while it runs. Enabling the concurrent option for high-volume or short-running queries can saturate the CPU on your Search Nodes and reduce overall query throughput. To limit the impact on CPU, enable the concurrent option only for the heavy and long-running queries that benefit from lower latency.
To measure the CPU cost of an individual query, run the query with explain and review the userTimeMs, systemTimeMs, and maxReportingThreads fields in the resourceUsage document.
To monitor CPU usage across your deployment, view the Atlas cluster metrics and the Review MongoDB Search Metrics. Atlas can also trigger MongoDB Search alerts that measure the amount of CPU that MongoDB Search processes use. If CPU usage approaches the limits of acceptable performance, scale your Search Nodes vertically or horizontally. To learn more, see Tips for Sizing and Scaling Search Nodes.
例
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 ])