<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:39:11 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CSHARP-1290] MongoClient Connection Pooling</title>
                <link>https://jira.mongodb.org/browse/CSHARP-1290</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;What&apos;s the best practice for ensuring that the connection pool works properly with version 2.0 and async requests.  I have a prototype application built using the new driver that creates a new MongoClient object on each request.  The app is not using a connection string, rather it is building a MongoClientSettings object and using that when creating the MongoClient.  Under load, my app creates an enormous number of connections to Mongo causing me to have to increase the maximum pool size and, as a result, it uses too many resources and bogs down fairly quickly. &lt;/p&gt;

&lt;p&gt;Does the new driver use the same pool if I create a new MongoClient with the same settings set on the constructor or does it use a separate pool for each MongoClient object?  I am trying to determine if I need to store the connection at the application level vs. per request (which normally I would do anyway) or if the problem is related to the async processes.  &lt;/p&gt;</description>
                <environment>ASP.NET MVC 5 with Mongo on Windows Server 2012 (test server)</environment>
        <key id="205865">CSHARP-1290</key>
            <summary>MongoClient Connection Pooling</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="9">Done</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="pgordon@truckdown.com">Peter Gordon</reporter>
                        <labels>
                            <label>question</label>
                    </labels>
                <created>Thu, 21 May 2015 20:23:51 +0000</created>
                <updated>Fri, 5 Apr 2019 13:57:45 +0000</updated>
                            <resolved>Fri, 22 May 2015 13:08:55 +0000</resolved>
                                    <version>2.0</version>
                                                    <component>Connectivity</component>
                                        <votes>0</votes>
                                    <watches>1</watches>
                                                                                                                <comments>
                            <comment id="921538" author="craiggwilson" created="Fri, 22 May 2015 13:08:55 +0000"  >&lt;p&gt;Hi Peter,&lt;/p&gt;

&lt;p&gt;I was wrong. Removing the reference will not work. We currently don&apos;t offer a way to shut down a cluster. I&apos;ve created &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-1293&quot; title=&quot;Add support for shutting down a MongoClient that is no longer useful.&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-1293&quot;&gt;&lt;del&gt;CSHARP-1293&lt;/del&gt;&lt;/a&gt; to track this feature. I&apos;m going to close out this ticket as Works as Designed and you can track the other one for when this feature gets implemented.&lt;/p&gt;

&lt;p&gt;Thanks for the report and the questions,&lt;br/&gt;
Craig&lt;/p&gt;</comment>
                            <comment id="921223" author="craiggwilson" created="Fri, 22 May 2015 01:46:11 +0000"  >&lt;p&gt;We don&apos;t currently offer a way to dispose of that thing. However, if you remove the reference, they&apos;ll get cleaned up by the GC eventually.&lt;/p&gt;</comment>
                            <comment id="921118" author="pgordon@truckdown.com" created="Thu, 21 May 2015 23:25:09 +0000"  >&lt;p&gt;Craig - one last question on this - if I store a list of MongoClients in the application, is there a way in the API to dispose of connections properly ... I.e if I determine that a given client has not been used in a certain amount of time - or should I just remove the MongoClient and rely on garbage collection.  &lt;/p&gt;</comment>
                            <comment id="921005" author="pgordon@truckdown.com" created="Thu, 21 May 2015 21:39:54 +0000"  >&lt;p&gt;Sounds good - thanks for the quick response.&lt;/p&gt;</comment>
                            <comment id="920966" author="craiggwilson" created="Thu, 21 May 2015 21:08:57 +0000"  >&lt;p&gt;Yes, different credentials can also cause problems because we store them securely. Your best bet, in a system like this, is still to use Singletons. You can store them globally somewhere in a dictionary. You know best about what should be the same in your system. That&apos;s my advice.&lt;/p&gt;</comment>
                            <comment id="920957" author="pgordon@truckdown.com" created="Thu, 21 May 2015 21:02:52 +0000"  >&lt;p&gt;Yes - I mean different servers.   For instance, our dev team can use the UI to connect to their personal dev server, our test servers, or in some cases our production servers. &lt;/p&gt;</comment>
                            <comment id="920954" author="pgordon@truckdown.com" created="Thu, 21 May 2015 20:59:49 +0000"  >&lt;p&gt;Craig - is it also possible that the system cannot compare the Credentials other than a referential equality?  I removed the ClusterConfigurator and the error still occurs and the only other setting other than server name on the connection is I am manually creating the client credential (MongoCredential.CreateCredential) on each one.  &lt;/p&gt;</comment>
                            <comment id="920949" author="craiggwilson" created="Thu, 21 May 2015 20:57:03 +0000"  >&lt;p&gt;In theory, if your ClusterConfigurator was a defined method somewhere and you didn&apos;t use a lambda expression for it, then it should compare equally. Regardless, I think it&apos;d be best to manage them in a ConcurrentDictionary somewhere anyways.&lt;/p&gt;

&lt;p&gt;When you say different database... do you mean different servers?&lt;/p&gt;</comment>
                            <comment id="920938" author="pgordon@truckdown.com" created="Thu, 21 May 2015 20:50:40 +0000"  >&lt;p&gt;One thought - if I create a singleton ClusterConfigurator, would I then be safe to create a connection on each request provided I use the same referenced ClusterConfigurator on each MongoClient?&lt;/p&gt;</comment>
                            <comment id="920933" author="pgordon@truckdown.com" created="Thu, 21 May 2015 20:48:13 +0000"  >&lt;p&gt;My prototype app includes a small web based Mongo admin utility which allows you to create connections to different databases and run queries, inserts, etc... against that database.  As a result, each user could be working on a different connection.  The problem is likely related to the ClusterConfigurator as I am using that to set the serverSelectionTimeout to something less than the default 30 seconds.  I&apos;ll remove that and see if that is the root cause of the problem.  Sounds like I&apos;ll have to refactor it so that it stores a MongoClient object either per session or a thread safe list of them on the application in some fashion.  &lt;/p&gt;</comment>
                            <comment id="920907" author="craiggwilson" created="Thu, 21 May 2015 20:27:30 +0000"  >&lt;p&gt;The driver will, for the most part, use the same connection settings. However, certain connection settings cannot be compared (like ClusterConfigurator which is a delegate and can only be compared for referential equality, not content). Hence, the best practice will be to only instantiate 1 MongoClient at app startup and use that. Put it in an IoC container, create a static variable somewhere, etc... Essentially, make it a singleton.&lt;/p&gt;

&lt;p&gt;Is there any reason you are constructing a new client for every request?&lt;/p&gt;

&lt;p&gt;Craig&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                                                <inwardlinks description="is related to">
                                        <issuelink>
            <issuekey id="206009">CSHARP-1293</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hs9lbb:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>