<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 22:00:55 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>[CXX-965] C++11 driver 3.0.1 so much slower than legacy C++ driver 2.6.11?</title>
                <link>https://jira.mongodb.org/browse/CXX-965</link>
                <project id="11980" key="CXX">C++ Driver</project>
                    <description>&lt;p&gt;C+&lt;ins&gt;11 driver 3.0.1 slower than legacy C&lt;/ins&gt;+ driver 2.6.11, we tried to write 2 millions of simple document to MongoDB, with C++ driver 2.6.11 it costs 41 seconds, and 3.0.1 takes more than 189 seconds.&lt;/p&gt;</description>
                <environment></environment>
        <key id="298518">CXX-965</key>
            <summary>C++11 driver 3.0.1 so much slower than legacy C++ driver 2.6.11?</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="david23123">David</reporter>
                        <labels>
                    </labels>
                <created>Tue, 5 Jul 2016 13:44:33 +0000</created>
                <updated>Mon, 8 Jan 2024 15:30:21 +0000</updated>
                            <resolved>Wed, 13 Jul 2016 23:04:45 +0000</resolved>
                                    <version>3.0.1</version>
                                                    <component>Performance</component>
                                        <votes>0</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="1314921" author="david23123" created="Wed, 6 Jul 2016 05:18:00 +0000"  >&lt;p&gt;OK, I understood, it&apos;s synchronized method. I&apos;ll try to use insert_many() instead.&lt;/p&gt;</comment>
                            <comment id="1314878" author="david.golden" created="Wed, 6 Jul 2016 03:24:12 +0000"  >&lt;p&gt;The 2.6.11 driver doesn&apos;t ask the DB for an acknowledgement of the write.  Think of it like UDP.  You send the packet and hope the other side gets it.  The default with drivers now is to acknowledge writes, which means in addition to the actual time to send the document over the wire, the driver waits for the server to send an &quot;ok&quot; response (and has to deserialize and check it).  That confirmation adds safety but also adds overhead, which is why batching with insert_many helps so much. &lt;/p&gt;

&lt;p&gt;I&apos;m not sure what you mean by &quot;save objects to database immediately&quot; &amp;#8211; whether you mean that every line must be individually inserted before processing the next line or whether you mean there&apos;s just too much data to create documents for the entire file and only insert_many at the end, or something else entirely.&lt;/p&gt;

&lt;p&gt;One technique that some people in your situation use is to batch at least &lt;b&gt;some&lt;/b&gt; of the insertions during processing.  I.e. queue up a few hundred or a thousand documents, and then only issue an insert_many periodically through the loop (or file).  If you batched every 1000 (assuming they all fit into a single write of &amp;lt; 16MB), then rather than 2 million database roundtrips inserting line by line, you&apos;d have 2 thousand roundtrips.&lt;/p&gt;</comment>
                            <comment id="1314769" author="david23123" created="Wed, 6 Jul 2016 00:36:39 +0000"  >&lt;p&gt;Here is the sample codes with created a index for &apos;age&apos;.&lt;br/&gt;
Actually, we are trying to parsing large XML files and store each marks as an object and build relationships of them, about 2 million of objects/relationships created while XML being parsed line by line with a XML Reader. So we cannot use insert_many() but insert_one() due to we need save objects to database immediately when it was created. But with C++ Driver 2.6.11 the insert() method faster (41s), does it run asynchronously? or act as insert_many() that 3.0.1 does?&lt;/p&gt;</comment>
                            <comment id="1314540" author="david.golden" created="Tue, 5 Jul 2016 21:01:14 +0000"  >&lt;p&gt;Hello.  Thanks for contacting us.  Without seeing your sample code for the two cases, we can&apos;t give you much guidance beyond what we see in the screen shots.&lt;/p&gt;

&lt;p&gt;I suspect what you&apos;re seeing is the change to having acknowledged writes be the default insert behavior for all drivers.   There are two articles discussing the evolution from the 2.6 driver to the &quot;legacy&quot; driver to the new C++11 driver that you might wish to review:&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;&lt;a href=&quot;https://www.mongodb.com/blog/post/introducing-legacy-c-driver-10&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Introducing the Legacy C++ driver 1.0&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;https://www.mongodb.com/blog/post/introducing-new-c-driver&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Introducing the New C++11 driver&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;With modern drivers, we recommend the use of &lt;tt&gt;insert_many&lt;/tt&gt; when &quot;bulk loading&quot; documents rather than repeated calls to &lt;tt&gt;insert_one&lt;/tt&gt; to avoid a database round-trip for every document.  If you retry your test with &lt;tt&gt;insert_many&lt;/tt&gt;, you should see a significant improvement.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                            <outwardlinks description="duplicates">
                                        <issuelink>
            <issuekey id="158823">CXX-344</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                            <attachment id="129471" name="Screen Shot 2016-07-05 at 9.41.20 PM.png" size="337074" author="david23123" created="Tue, 5 Jul 2016 13:44:33 +0000"/>
                            <attachment id="129474" name="Screen Shot 2016-07-05 at 9.47.54 PM.png" size="390884" author="david23123" created="Tue, 5 Jul 2016 13:49:21 +0000"/>
                            <attachment id="129609" name="main.cpp" size="2177" author="david23123" created="Wed, 6 Jul 2016 00:36:39 +0000"/>
                            <attachment id="129610" name="main2.cpp" size="1945" author="david23123" created="Wed, 6 Jul 2016 00:36:39 +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|hsn6e7:</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>