개요
이 가이드 에서는 .NET/ C# 드라이버 연결 풀을 사용하여 MongoDB deployment 에 대한 연결을 관리 방법과 애플리케이션 에서 연결 풀 설정을 구성하는 방법에 대해 학습 수 있습니다.
연결 풀 .NET/ C# 드라이버 에 의해 유지 관리되는 개방형 데이터베이스 연결의 캐시 입니다. 애플리케이션 MongoDB 에 대한 연결을 요청하면 .NET/ C# 드라이버 풀에서 원활하게 연결을 가져오고, 작업을 수행하고, 재사용을 위해 연결을 풀에 반환합니다.
연결 풀은 애플리케이션 지연 시간 줄이고 .NET/ C# 드라이버 에 의해 새 연결이 생성되는 횟수를 줄이는 데 도움이 됩니다. 다음 다이어그램은 MongoClient 가 연결 풀 관리하는 방법을 간략하게 보여줍니다.
연결 풀 구성
MongoClient 객체 또는 연결 URI에서 다음 연결 풀 설정을 지정할 수 있습니다.
설정 | 설명 |
|---|---|
| The maximum amount of time that the .NET/C# Driver waits when establishing a new connection before timing out. |
| The maximum number of connections that each pool can establish concurrently. If this limit is reached, further requests wait until a connection is established or another in-use connection is checked back into the pool. |
| The maximum time that a connection can remain idle in the pool. When a connection exceeds this limit, the .NET/C# Driver closes the connection and removes it from the pool. |
| The maximum time that a connection can be pooled. When a connection exceeds this limit, the .NET/C# Driver closes the connection and removes it from the pool. |
| The maximum number of concurrent connections that the pool maintains. If the maximum pool size is reached, further requests wait until a connection becomes available. |
| The minimum number of concurrent connections that the pool maintains. If the number of open connections falls below this value due to network errors, the .NET/C# Driver attempts to create new connections to maintain this minimum. |
| The length of time that the .NET/C# Driver waits for a response from the server before timing out. |
| How long a thread waits for a connection to become available in the connection pool before timing out. |
다음 코드는 MaxConnectionPoolSize 매개변수를 사용하여 최대 연결 풀 크기가 50 인 클라이언트 만듭니다.
var settings = MongoClientSettings.FromConnectionString("<connection URI>"); settings.MaxConnectionPoolSize = 50; var client = new MongoClient(settings);
다음 코드는 앞의 예시 와 구성이 동일하지만 연결 URI를 사용하여 클라이언트 생성합니다.
var settings = MongoClientSettings.FromConnectionString("<hostname>?maxPoolSize=50"); var client = new MongoClient(settings);
추가 정보
연결 풀에 대해 자세히 학습 MongoDB Server 매뉴얼의 연결 풀 개요를 참조하세요.
API 문서
이 가이드에서 사용되는 메서드 또는 유형에 대해 자세히 알아보려면 다음 API 설명서를 참조하세요.