A opção concurrent habilita o paralelismo intraconsulta. Nesse modo, o MongoDB Search utiliza mais recursos, mas melhora cada latência de query individual. Esse recurso está disponível apenas para nós de pesquisa dedicados.
concurrent Limitações de opção
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.
Sintaxe
concurrent tem a seguinte sintaxe:
{ "$searchMeta"|"$search": { "index": "<index name>", // optional, defaults to "default" "<operator>": { <operator-specifications> }, "concurrent": true | false, ... } }
Comportamento
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- para solicitar o MongoDB Search para executar a query em várias threadsfalse- para executar a query de thread único (padrão)
O MongoDB Search oferece controle sobre esse comportamento por query para permitir a execução simultânea somente para queries pesadas e de longa duração, o que minimiza a contenção e melhora a taxa de transferência geral da query. A execução simultânea é especialmente eficiente em grandes conjuntos de dados, pois há uma quantidade maior de segmentos.
Uso da 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.
Exemplo
Considere a seguinte query na coleção sample_mflix.movies nos dados de exemplo. A query indica uma pesquisa simultânea de filmes que contêm o termo new york no title.
1 db.movies.aggregate([ 2 { 3 "$search": { 4 "text": { 5 "path": "title", 6 "query": "new york" 7 }, 8 "concurrent": true 9 } 10 } 11 ])