concurrent 옵션은 쿼리 내 병렬 처리를 활성화합니다. 이 모드 에서는 MongoDB Search가 더 많은 리소스를 사용하지만 각 개별 쿼리 지연 시간 향상됩니다. 이 기능은 전용 검색 노드에서만 사용할 수 있습니다.
concurrent 옵션 제한 사항
concurrent 옵션을 사용하여 쿼리를 실행하는 경우 MongoDB Search는 각 쿼리가 동시에 실행된다고 보장하지 않습니다. 예시들어 대기 중인 동시 쿼리가 너무 많으면 MongoDB Search가 단일 스레드 실행으로 대체될 수 있습니다.
구문
concurrent 의 구문은 다음과 같습니다:
{ "$searchMeta"|"$search": { "index": "<index name>", // optional, defaults to "default" "<operator>": { <operator-specifications> }, "concurrent": true | false, ... } }
행동
concurrent 불리언 옵션을 사용하면 MongoDB Search에 요청하여 여러 세그먼트에서 쿼리 실행을 병렬화할 수 있습니다. 이렇게 하면 대부분의 경우 응답 시간이 향상됩니다. concurrent 옵션에 대해 다음 값 중 하나를 설정할 수 있습니다.
true- MongoDB Search에 쿼리 멀티스레드로 실행 하도록 요청false- 쿼리를 단일 스레드로 실행(기본값)
MongoDB Search는 쿼리별로 이러한 동작을 제어하여 사용량이 많고 오래 실행되는 쿼리에 대해서만 동시 실행을 활성화 경합을 최소화하고 전체 쿼리 처리량 향상시킵니다. 동시 실행은 세그먼트 수가 많기 때문에 대규모 데이터 세트에서 특히 효율적입니다.
CPU 사용량
MongoDB Search는 다중 스레드에서 동시 쿼리를 실행합니다. 그렇기 때문에 쿼리는 더 빠르게 완료됩니다. 그러나 쿼리는 실행 동안 검색 노드에서 더 많은 CPU를 소비합니다. 다량이거나 단기 실행 쿼리에 대해 concurrent 옵션을 활성화하면 검색 노드의 CPU가 과부하거나 전체 쿼리 처리량이 감소할 수 있습니다. CPU에 미치는 영향을 제한하려면, 지연 시간을 줄이멼으로 이득을 얻는 부하가 많고 장기간 실행되는 쿼리에만 concurrent 옵션을 활성화하세요.
개별 쿼리의 CPU 비용을 측정하려면 explain으로 쿼리를 실행하고 resourceUsage 문서에서 userTimeMs, systemTimeMs, maxReportingThreads 필드를 검토하세요.
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 ])