Join us Sept 17 at .local NYC! Use code WEB50 to save 50% on tickets. Learn more >
MongoDB Event
Docs Menu
Docs Home
/ / /
C#/.NET ドライバー
/ /

接続プール

このガイドでは、 .NET/ C#ドライバーが接続プールを使用してMongoDBデプロイへの接続を管理する方法と、アプリケーションで接続プール設定を構成する方法について学習できます。

接続プールはとはオープンデータベース接続のキャッシュであり、 .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

次へ

Amazon Web Services Lambdaからの接続

項目一覧