@@ -60,64 +60,146 @@ Configure a Connection Pool
60
60
You can specify settings for your connection pool either by using a connection
61
61
string with the ``options.Client().ApplyURI()`` method.
62
62
63
- The following are connection string settings you can use to configure your
64
- connection pool :
63
+ Select the :guilabel:`Connection String` or :guilabel:`MongoClientSettings` tab to
64
+ see the corresponding syntax :
65
65
66
- .. list-table::
67
- :widths: 25,75
68
- :header-rows: 1
66
+ .. tabs::
69
67
70
- * - Setting
71
- - Description
72
-
73
- * - ``maxPoolSize``
68
+ .. tab:: Connection String
69
+ :tabid: uri
70
+
71
+ The following are connection string settings you can use to configure your
72
+ connection pool:
74
73
75
- - Maximum number of connections opened in the pool. If an operation needs a
76
- new connection while the connection pool has ``maxPoolSize`` connections
77
- open, the new operation waits for a new connection to open. To limit this
78
- waiting time, use the single timeout setting.
74
+ .. list-table::
75
+ :widths: 25,75
76
+ :header-rows: 1
79
77
80
- *Default:* ``100``
78
+ * - Setting
79
+ - Description
80
+
81
+ * - ``maxPoolSize``
81
82
82
- * - ``minPoolSize``
83
+ - Maximum number of connections opened in the pool. If an operation needs a
84
+ new connection while the connection pool has ``maxPoolSize`` connections
85
+ open, the new operation waits for a new connection to open. To limit this
86
+ waiting time, use the single timeout setting.
83
87
84
- - Minimum number of connections opened in the pool. The value of
85
- ``minPoolSize`` must be less than the value of ``maxPoolSize``.
88
+ *Default:* ``100``
86
89
87
- *Default*: ``0 ``
90
+ * - ``minPoolSize ``
88
91
89
- * - ``maxConnecting``
90
-
91
- - Maximum number of connections a pool may establish concurrently.
92
-
93
- *Default:* ``2``
94
-
95
- * - ``maxIdleTimeMS``
96
-
97
- - The maximum number of milliseconds that a connection can remain idle in
98
- the pool before being removed and closed.
92
+ - Minimum number of connections opened in the pool. The value of
93
+ ``minPoolSize`` must be less than the value of ``maxPoolSize``.
99
94
100
- *Default:* ``None`` (no limit)
95
+ *Default*: ``0``
101
96
102
- * - ``waitQueueTimeoutMS```
97
+ * - ``maxConnecting``
98
+
99
+ - Maximum number of connections a pool may establish concurrently.
100
+
101
+ *Default:* ``2``
102
+
103
+ * - ``maxIdleTimeMS``
104
+
105
+ - The maximum number of milliseconds that a connection can remain idle in
106
+ the pool before being removed and closed.
103
107
104
- - Specifies the maximum wait time in milliseconds that a thread can wait
105
- for a connection to become available.
108
+ *Default:* ``None`` (no limit)
106
109
107
- *Default*: ``0`` (no limit)
110
+ * - ``waitQueueTimeoutMS```
111
+
112
+ - Specifies the maximum wait time in milliseconds that a thread can wait
113
+ for a connection to become available.
114
+
115
+ *Default*: ``0`` (no limit)
116
+
117
+ .. tab:: ClientOptions
118
+ :tabid: ClientOptions
119
+
120
+ You can set the connection pool options directly using the ``options.Client`` methods.
121
+
122
+ The following table describes the methods you can chain to your settings
123
+ to modify the driver's behavior:
124
+
125
+ .. list-table::
126
+ :widths: 25,75
127
+ :header-rows: 1
128
+
129
+ * - Setting
130
+ - Description
131
+
132
+ * - ``SetMaxPoolSize()``
133
+
134
+ - Maximum number of connections opened in the pool. If an operation needs a
135
+ new connection while the connection pool has the configured maximum connections
136
+ open, the new operation waits for a new connection to open. To limit this
137
+ waiting time, use the single timeout setting.
138
+
139
+ *Default:* ``100``
140
+
141
+ * - ``SetMinPoolSize()``
142
+
143
+ - Minimum number of connections opened in the pool. The value of
144
+ ``MinPoolSize`` must be less than the value of ``MaxPoolSize``.
145
+
146
+ *Default*: ``0``
147
+
148
+ * - ``SetMaxConnecting()``
149
+
150
+ - Maximum number of connections a pool may establish concurrently.
151
+
152
+ *Default:* ``2``
153
+
154
+ * - ``SetMAxConnIdleTime()``
155
+
156
+ - The maximum number of milliseconds that a connection can remain idle in
157
+ the pool before being removed and closed.
158
+
159
+ *Default:* ``0`` (no limit)
108
160
109
161
Example
110
162
~~~~~~~
111
163
112
- The following code creates a client with a maximum connection pool size of
113
- ``50``, a minimum pool size of ``10``, and a maximum idle time of
114
- ``30000`` milliseconds (30 seconds):
115
-
116
- .. literalinclude:: /includes/connect/connection-pools-uri.go
117
- :language: go
118
- :start-after: start-connection-pool-uri
119
- :end-before: end-connection-pool-uri
120
- :dedent:
164
+ Select the :guilabel:`Connection String` or :guilabel:`MongoClientSettings` tab to
165
+ see the corresponding example:
166
+
167
+ .. tabs::
168
+
169
+ .. tab:: Connection String
170
+ :tabid: uriExample
171
+
172
+ The following code uses the connection string to configure the maximum
173
+ connection pool size of ``50``, a minimum pool size of ``10``, and a
174
+ maximum idle time of ``30000`` milliseconds (30 seconds):
175
+
176
+ .. literalinclude:: /includes/connect/connection-pools-uri.go
177
+ :language: go
178
+ :start-after: start-uri-variable
179
+ :end-before: end-uri-variable
180
+ :dedent:
181
+
182
+ The following code creates a client and passes the connection string to the
183
+ ``ApplyURI()`` method:
184
+
185
+ .. literalinclude:: /includes/connect/connection-pools-uri.go
186
+ :language: go
187
+ :start-after: start-apply-uri
188
+ :end-before: end-apply-uri
189
+ :dedent:
190
+
191
+ .. tab:: ClientOptions
192
+ :tabid: optionsExample
193
+
194
+ The following code creates a client and sets the connection pool options
195
+ with a maximum connection pool size of ``50``, a minimum pool size of
196
+ ``10``, and a maximum idle time of ``30000`` milliseconds (30 seconds):
197
+
198
+ .. literalinclude:: /includes/connect/connection-pools-client-options.go
199
+ :language: go
200
+ :start-after: start-client-options
201
+ :end-before: end-client-options
202
+ :dedent:
121
203
122
204
Optimize Connection Pools
123
205
-------------------------
0 commit comments