개요
MongoDB 드라이버는 MongoDB Server 와 주고받는 메시지를 압축할 수 있습니다. 이렇게 하면 각 작업에 대해 전송되는 데이터 양이 줄어듭니다. 압축은 제한된 네트워크에서 성능을 향상시키고 MongoDB Atlas 실행 과 관련된 데이터 전송 비용을 낮출 수 있습니다.
압축은 유선 프로토콜 수준에서 작동하므로 애플리케이션 수행하는 모든 작업에 적용됩니다. 알고리즘 두 개 이상 지정하는 경우 운전자 MongoDB Server 도 지원하는 목록의 첫 번째 알고리즘 사용합니다.
압축 알고리즘
MongoDB 드라이버는 다음 압축 알고리즘을 지원 .
네트워크 압축의 이점
MongoDB Atlas charges for data transferred across cloud regions, cloud providers, and between your infrastructure and MongoDB Atlas. Network compression reduces the amount of data that your application sends and receives, which can lower these data transfer costs. To learn more about pricing, see Data Transfer Costs.
네트워크 압축은 생산성 이점도 있습니다. 압축된 메시지는 네트워크를 통해 전송되는 데 시간이 덜 걸리므로 애플리케이션의 응답 시간을 개선할 수 있습니다. 또한 압축은 MongoDB 트래픽이 사용하는 대역폭을 줄여 동일한 네트워크의 다른 애플리케이션에서 사용할 수 있는 대역폭을 더 많이 확보합니다.
압축 알고리즘 선택할 때 다음 지침을 고려하세요.
압축 효율성 과 리소스 사용량의 균형을 맞추려면 Zstandard를 사용하세요. Zstandard는 대부분의 애플리케이션에 적합한 기본값 선택입니다.
최소한의 계산 오버헤드 필요한 지연 시간에 민감한 애플리케이션에는 Snappy를 사용하세요.
MongoDB 드라이버 및 환경 전반에서 광범위한 호환성을 위해 Zlib를 사용하세요.
팁
CPU 사용량 모니터링
Compression trades network bandwidth for CPU usage. After you enable network compression, monitor your application's CPU utilization to confirm that the trade-off benefits your workload. To learn more about these trade-offs, see the CPU Utilization and Network Compression in MongoDB blog post.
버전 호환성
다음 표에는 각 압축 알고리즘 에 대해 지원되는 최소 운전자 및 MongoDB Server 버전이 나열되어 있습니다.
압축 알고리즘 지정
MongoDB 인스턴스에 대한 연결에 압축을 활성화하려면 다음 방법 중 하나를 사용하여 사용할 알고리즘을 지정합니다.
연결 문자열에 알고리즘을 매개 변수로 추가합니다.
MongoClientSettings객체의Compressors속성에 알고리즘을 지정합니다.
연결 문자열을 사용하여 압축을 활성화하려면 연결 문자열에 compressors 매개 변수를 추가합니다. 쉼표로 구분하여 하나 이상의 압축 알고리즘을 지정할 수 있습니다.
const string connectionUri = "mongodb+srv://<db_username>:<db_password>@<cluster-url>/?compressors=snappy,zlib,zstd"; var client = new MongoClient(connectionUri);
To enable compression by using MongoClientSettings, set the Compressors property of your MongoClientSettings object to a List of one or more CompressorConfiguration objects. Each CompressorConfiguration object in the List represents an algorithm you want to use:
var settings = new MongoClientSettings() { Scheme = ConnectionStringScheme.MongoDB, Server = new MongoServerAddress("<cluster-url>"), Compressors = new List<CompressorConfiguration>() { new CompressorConfiguration(CompressorType.Snappy), new CompressorConfiguration(CompressorType.Zlib), new CompressorConfiguration(CompressorType.Zstandard) } }; var client = new MongoClient(settings);