<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:19:06 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>[CDRIVER-3808] SRV polling thread uses 100% CPU when connected to a replica set</title>
                <link>https://jira.mongodb.org/browse/CDRIVER-3808</link>
                <project id="10030" key="CDRIVER">C Driver</project>
                    <description>&lt;p&gt;Implementation of the client pool has resulted in a runaway thread consuming 100% of CPU on a task (from what I can gather by tracing it is &lt;b&gt;srv_polling_run&lt;/b&gt; within the libmongoc-1.0.0 dynamic library). It is reproducible on my macOS development machine and my docker 18 and 20 distribution containers.&#160;&lt;/p&gt;

&lt;p&gt;My use of the mongocxx:: pool class is standard with the documentation.&#160;&lt;/p&gt;</description>
                <environment>Ubuntu 18 / 20 and macOS </environment>
        <key id="1523414">CDRIVER-3808</key>
            <summary>SRV polling thread uses 100% CPU when connected to a replica set</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="2" iconUrl="https://jira.mongodb.org/images/icons/priorities/critical.svg">Critical - P2</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="13201">Fixed</resolution>
                                        <assignee username="kevin.albertson@mongodb.com">Kevin Albertson</assignee>
                                    <reporter username="rylandva@med.umich.edu">Ryan Landvater</reporter>
                        <labels>
                    </labels>
                <created>Fri, 23 Oct 2020 03:46:30 +0000</created>
                <updated>Sat, 28 Oct 2023 11:28:37 +0000</updated>
                            <resolved>Mon, 2 Nov 2020 15:43:37 +0000</resolved>
                                    <version>1.17.0</version>
                                    <fixVersion>1.17.2</fixVersion>
                                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="3471756" author="xgen-internal-githook" created="Mon, 2 Nov 2020 15:47:07 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Kevin Albertson&apos;, &apos;email&apos;: &apos;kevin.albertson@mongodb.com&apos;, &apos;username&apos;: &apos;kevinAlbs&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CDRIVER-3808&quot; title=&quot;SRV polling thread uses 100% CPU when connected to a replica set&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CDRIVER-3808&quot;&gt;&lt;del&gt;CDRIVER-3808&lt;/del&gt;&lt;/a&gt; fix srv polling thread from spinning (#692)&lt;/p&gt;

&lt;p&gt;If an SRV URI is used to connect to a deployment other than a sharded cluster&lt;br/&gt;
the SRV polling thread spins since it bypasses the poll due to the topology&lt;br/&gt;
type being ineligible. This change terminates the thread when the topology&lt;br/&gt;
type is discovered to be ineligible.&lt;br/&gt;
Branch: r1.17&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-c-driver/commit/2946e344e8c67c31b2b632259198eaa61941f844&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-c-driver/commit/2946e344e8c67c31b2b632259198eaa61941f844&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="3471713" author="xgen-internal-githook" created="Mon, 2 Nov 2020 15:32:51 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Kevin Albertson&apos;, &apos;email&apos;: &apos;kevin.albertson@mongodb.com&apos;, &apos;username&apos;: &apos;kevinAlbs&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CDRIVER-3808&quot; title=&quot;SRV polling thread uses 100% CPU when connected to a replica set&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CDRIVER-3808&quot;&gt;&lt;del&gt;CDRIVER-3808&lt;/del&gt;&lt;/a&gt; fix srv polling thread from spinning (#692)&lt;/p&gt;

&lt;p&gt;If an SRV URI is used to connect to a deployment other than a sharded cluster&lt;br/&gt;
the SRV polling thread spins since it bypasses the poll due to the topology&lt;br/&gt;
type being ineligible. This change terminates the thread when the topology&lt;br/&gt;
type is discovered to be ineligible.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-c-driver/commit/ae50db1422567058902d18ef3e12af1b6bf89d67&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-c-driver/commit/ae50db1422567058902d18ef3e12af1b6bf89d67&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="3461591" author="kevin.albertson" created="Fri, 23 Oct 2020 17:59:11 +0000"  >&lt;p&gt;PR: &lt;a href=&quot;https://github.com/mongodb/mongo-c-driver/pull/692&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-c-driver/pull/692&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="3461412" author="kevin.albertson" created="Fri, 23 Oct 2020 16:15:24 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=rylandva%40med.umich.edu&quot; class=&quot;user-hover&quot; rel=&quot;rylandva@med.umich.edu&quot;&gt;rylandva@med.umich.edu&lt;/a&gt;, thank you for the report!&lt;/p&gt;

&lt;p&gt;SRV polling is handled by libmongoc. I was able to reproduce this with a small application in the C driver.&lt;/p&gt;

&lt;p&gt;I did not observe this when connected to a sharded cluster. But I did observe high CPU usage in the SRV polling thread when connected to a replica set. Period SRV polling is skipped for replica sets, but the &lt;a href=&quot;#L638&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;check that bypasses the SRV poll&lt;/a&gt; returns to the SRV polling thread early, which ends up repeatedly calling to attempt to rescan.&lt;/p&gt;

&lt;p&gt;I am moving this to the CDRIVER project. We will fix this very soon.&lt;/p&gt;</comment>
                            <comment id="3461286" author="JIRAUSER1257370" created="Fri, 23 Oct 2020 15:21:26 +0000"  >&lt;p&gt;I have upgraded to 3.6.0 and the problem still persists. For reference:&lt;/p&gt;

&lt;p&gt;My base class that wraps the driver is QBMongoDriver. It uses a &quot;run&quot; function to iterate through a list of transactions (mostly JSON objects) that have been deposited by threads controlled by boost::asio. When a transaction is added the conditional variable is released (for one thread; notify_one). Within QBMongoDriver::transaction, a client is acquired from the pool.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;class&lt;/b&gt; QBMongoDriver : &lt;b&gt;public&lt;/b&gt; QBObject &lt;/p&gt;
{

&#160; &#160; *friend* *class* QBRootServer;

&#160; &#160; *friend* *class* QBClientSession;

&#160;&#160; &#160;

&#160; &#160; // Wrapper around mongo-cxx basic client objects

&#160; &#160;&#160;

&#160; &#160; mongocxx::uri &#160; &#160; &#160; URI;

&#160; &#160; mongocxx::instance&#160; inst;

&#160; &#160; mongocxx::pool&#160; &#160; &#160; pool;

&#160;&#160; &#160;

&#160; &#160; // Queue and mutex for mongo_transactions

&#160; &#160; boost::mutex&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; _queueMTX;

&#160; &#160; boost::condition_variable &#160; &#160; &#160; _queueCV;

&#160; &#160; std::vector&amp;lt;

&#160; &#160; boost::shared_ptr&amp;lt;

&#160; &#160; QBMongoTransaction&amp;gt;&amp;gt;&#160; &#160; &#160; &#160; &#160; &#160; _queue;

&#160; &#160; std::vector&amp;lt;boost::thread&amp;gt;&#160; &#160; &#160; _queueThreads;

&#160; &#160; std::default_random_engine&#160; &#160; &#160; _generator;

&#160; &#160; uint16_t&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; _threadCount;

&#160;&#160; &#160;

&#160; &#160; *bool* _accepting = *true*;

&#160;&#160; &#160;

*public*:

&#160; &#160; *explicit* QBMongoDriver(std::string&amp;amp; URL,

&#160;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; uint16_t thread_count = 2,

&#160;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; QBObject* parent = *nullptr*);

&#160;

*private*:

&#160; &#160; *void* run();

}

&lt;p&gt;&lt;b&gt;void&lt;/b&gt; QBMongoDriver::run() {&lt;/p&gt;

&lt;p&gt;&#160; &#160; &lt;b&gt;while&lt;/b&gt; (_accepting) {&lt;/p&gt;

&lt;p&gt;&#160; &#160; &#160; &#160; boost::shared_ptr&amp;lt;QBMongoTransaction&amp;gt; transaction_;&lt;/p&gt;

&lt;p&gt;&#160; &#160; &#160; &#160; boost::unique_lock&amp;lt;boost::mutex&amp;gt; lock (_queueMTX);&lt;/p&gt;

&lt;p&gt;&#160;&#160; &#160; &#160; &#160;&lt;/p&gt;

&lt;p&gt;&#160; &#160; &#160; &#160; // Iterate through items in the queue until it is empty&lt;/p&gt;

&lt;p&gt;&#160; &#160; &#160; &#160; &lt;b&gt;while&lt;/b&gt; (!_queue.empty()) &lt;/p&gt;
{

&#160;&#160; &#160; &#160; &#160; &#160; &#160;

&#160; &#160; &#160; &#160; &#160; &#160; // Pull the first transaction from the queue

&#160; &#160; &#160; &#160; &#160; &#160; transaction_ = _queue.front();

&#160; &#160; &#160; &#160; &#160; &#160; _queue.erase(_queue.begin());

&#160; &#160; &#160; &#160; &#160; &#160; lock.unlock();

&#160;&#160; &#160; &#160; &#160; &#160; &#160;

&#160; &#160; &#160; &#160; &#160; &#160; // PROCESS THE TRANSACTION

&#160; &#160; &#160; &#160; &#160; &#160; transaction(transaction_);

&#160;&#160; &#160; &#160; &#160; &#160; &#160;

&#160; &#160; &#160; &#160; &#160; &#160; //Reinstate the lock

&#160; &#160; &#160; &#160; &#160; &#160; lock.lock();

&#160; &#160; &#160; &#160; }

&lt;p&gt;&#160;&#160; &#160; &#160; &#160;&lt;/p&gt;

&lt;p&gt;&#160; &#160; &#160; &#160; // if there are no outstanding requests, unlock and wait...&lt;/p&gt;

&lt;p&gt;&#160; &#160; &#160; &#160; _queueCV.wait_for(lock, boost::chrono::seconds(1));&lt;/p&gt;

&lt;p&gt;&#160; &#160; }&lt;/p&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                            <attachment id="284186" name="image-2020-10-22-23-43-06-010.png" size="930426" author="rylandva@med.umich.edu" created="Fri, 23 Oct 2020 03:43:07 +0000"/>
                    </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|hy0f0v:</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>