Docs Menu
Docs Home
/ / /
C#/ .NET 드라이버
/ /

연결 풀

이 가이드 에서는 .NET/ C# 드라이버 연결 풀을 사용하여 MongoDB deployment 에 대한 연결을 관리 방법과 애플리케이션 에서 연결 풀 설정을 구성하는 방법에 대해 학습 수 있습니다.

연결 풀 .NET/ C# 드라이버 에 의해 유지 관리되는 개방형 데이터베이스 연결의 캐시 입니다. 애플리케이션 MongoDB 에 대한 연결을 요청하면 .NET/ C# 드라이버 풀에서 원활하게 연결을 가져오고, 작업을 수행하고, 재사용을 위해 연결을 풀에 반환합니다.

연결 풀은 애플리케이션 지연 시간 줄이고 .NET/ C# 드라이버 에 의해 새 연결이 생성되는 횟수를 줄이는 데 도움이 됩니다. 다음 다이어그램은 MongoClient 가 연결 풀 관리하는 방법을 간략하게 보여줍니다.

CMAP 다이어그램

MongoClient 객체 또는 연결 URI에서 다음 연결 풀 설정을 지정할 수 있습니다.

설정
설명

ConnectTimeout

The maximum amount of time that the .NET/C# Driver waits when establishing a new connection before timing out.

Data Type: TimeSpan
Default: 30 seconds
Connection URI Example: connectTimeoutMS=0

MaxConnecting

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.

Data Type: integer
Default: 2
Connection URI Example: maxConnecting=3

MaxConnectionIdleTime

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.

Data Type: TimeSpan
Default: 10 minutes
Connection URI Example: maxIdleTimeMS=60000

MaxConnectionLifeTime

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.

Data Type: TimeSpan
Default: 30 minutes
Connection URI Example: maxLifeTimeMS=50000

MaxConnectionPoolSize

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.

Data Type: integer
Default: 100
Connection URI Example: maxPoolSize=150

MinConnectionPoolSize

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.

Data Type: integer
Default: 0
Connection URI Example: minPoolSize=3

SocketTimeout

The length of time that the .NET/C# Driver waits for a response from the server before timing out.

Data Type: TimeSpan
Default: OS default
Connection URI Example: socketTimeoutMS=100000

WaitQueueTimeout

How long a thread waits for a connection to become available in the connection pool before timing out.

Data Type: TimeSpan
Default: 2 minutes
Connection URI Example: waitQueueTimeoutMS=100000

다음 코드는 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 설명서를 참조하세요.

돌아가기

Stable API

이 페이지의 내용