<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:08:29 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-110] support sending mongo messages on network without additional malloc where available</title>
                <link>https://jira.mongodb.org/browse/CDRIVER-110</link>
                <project id="10030" key="CDRIVER">C Driver</project>
                    <description>&lt;p&gt;I understand that the C driver has broad compatibility as a specific goal, but easy platform-specific optimizations can be very useful.&lt;/p&gt;

&lt;p&gt;Functions like mongo_insert() currently include a call to mongo_message_create() which then calls bson_malloc().  This supports the requirement to transmit the existing bson data prefixed by the collection name in a single send() call on the socket.&lt;/p&gt;

&lt;p&gt;Linux and Windows both support the required network semantics without the additional bson_malloc() by using vector-oriented send() equivalents.&lt;/p&gt;

&lt;p&gt;Here is a simplified example :&lt;/p&gt;


&lt;p&gt;int mongo_insert_bson( mongo * pMongo, const char * pCollection, bson * pBSON )&lt;br/&gt;
{&lt;br/&gt;
#if defined( linux ) || defined( _WIN32 )&lt;br/&gt;
	mongo_header header ;&lt;/p&gt;

&lt;p&gt;	int nBSON = *( ( int32_t * ) pBSON-&amp;gt;data ) ;&lt;br/&gt;
	int nCollection = 1 + strlen( pCollection ) ;&lt;/p&gt;

&lt;p&gt;	header.len = sizeof( header ) + sizeof( ZERO ) + nCollection + nBSON ;&lt;br/&gt;
	header.op = MONGO_OP_INSERT ;&lt;br/&gt;
	header.id = rand() ;&lt;br/&gt;
	header.responseTo = 0 ;&lt;/p&gt;

&lt;p&gt;#if defined( _WIN32 )&lt;br/&gt;
{&lt;br/&gt;
	WSABUF pSend[ 3 ] ;&lt;br/&gt;
	int nSent ;&lt;/p&gt;

&lt;p&gt;	pSend[ 0 ].len = sizeof( header ) ;&lt;br/&gt;
	pSend[ 0 ].buf = ( char * ) &amp;amp;( header ) ;&lt;/p&gt;

&lt;p&gt;	if( 0 != WSASend( pMongo-&amp;gt;sock, pSend, 1, &amp;amp;( nSent ), 0, 0, 0 ) )&lt;/p&gt;
	{
		pMongo-&amp;gt;err = MONGO_IO_ERROR ;
		return MONGO_ERROR ;
	}&lt;br/&gt;
	&lt;br/&gt;
	pSend[ 0 ].len = sizeof( ZERO ) ;&lt;br/&gt;
	pSend[ 0 ].buf = ( char * ) &amp;amp;( ZERO ) ;&lt;br/&gt;
&lt;br/&gt;
	pSend[ 1 ].len = nCollection ;&lt;br/&gt;
	pSend[ 1 ].buf = ( char * ) pCollection ;&lt;br/&gt;
&lt;br/&gt;
	pSend[ 2 ].len = nBSON ;&lt;br/&gt;
	pSend[ 2 ].buf = ( char * ) pBSON-&amp;gt;data ;&lt;br/&gt;
&lt;br/&gt;
	if( 0 != WSASend( pMongo-&amp;gt;sock, pSend, 3, &amp;amp;( nSent ), 0, 0, 0 ) )&lt;br/&gt;
	{		pMongo-&amp;gt;err = MONGO_IO_ERROR ;		return MONGO_ERROR ;	}

&lt;p&gt;	return MONGO_OK ;&lt;br/&gt;
}&lt;br/&gt;
#endif // defined( _WIN32 )&lt;/p&gt;

&lt;p&gt;#if defined( linux )&lt;br/&gt;
{&lt;br/&gt;
	struct iovec pSend[ 3 ] ;&lt;/p&gt;

&lt;p&gt;	ssize_t nSent ;&lt;/p&gt;

&lt;p&gt;	pSend[ 0 ].iov_len = sizeof( header ) ;&lt;br/&gt;
	pSend[ 0 ].iov_base = &amp;amp;( header ) ;&lt;/p&gt;

&lt;p&gt;	if( &lt;del&gt;1 == ( nSent = writev( pMongo&lt;/del&gt;&amp;gt;sock, pSend, 1 ) ) )&lt;/p&gt;
	{
		pMongo-&amp;gt;err = MONGO_IO_ERROR ;

		return MONGO_ERROR ;
	}&lt;br/&gt;
&lt;br/&gt;
	pSend[ 0 ].iov_len = sizeof( ZERO ) ;&lt;br/&gt;
	pSend[ 0 ].iov_base = &amp;amp;( ZERO ) ;&lt;br/&gt;
&lt;br/&gt;
	pSend[ 1 ].iov_len = nCollection ;&lt;br/&gt;
	pSend[ 1 ].iov_base = pCollection ;&lt;br/&gt;
&lt;br/&gt;
	pSend[ 2 ].iov_len = nBSON ;&lt;br/&gt;
	pSend[ 2 ].iov_base = pBSON-&amp;gt;data ;&lt;br/&gt;
&lt;br/&gt;
	if( &lt;del&gt;1 == ( nSent = writev( pMongo&lt;/del&gt;&amp;gt;sock, pSend, 3 ) ) )&lt;br/&gt;
	{		pMongo-&amp;gt;err = MONGO_IO_ERROR ;
		return MONGO_ERROR ;	}

&lt;p&gt;	return MONGO_OK ;&lt;br/&gt;
}&lt;br/&gt;
#endif // defined( _WIN32 )&lt;/p&gt;

&lt;p&gt;#else&lt;br/&gt;
	return mongo_insert( pMongo, pCollection, pBSON ) ;&lt;/p&gt;

&lt;p&gt;#endif // defined( linux ) || defined( _WIN32 )&lt;/p&gt;

&lt;p&gt;} // mongo_insert()&lt;/p&gt;


&lt;p&gt;Incorporating this kind of optimization generically in the mongo C driver probably requires a fair amount of well-considered refactoring, so I am not just sending in a hasty patch.  I am, however, more than happy to collaborate on this effort.&lt;/p&gt;</description>
                <environment>Linux, Windows</environment>
        <key id="28837">CDRIVER-110</key>
            <summary>support sending mongo messages on network without additional malloc where available</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</type>
                                            <priority id="4" iconUrl="https://jira.mongodb.org/images/icons/priorities/minor.svg">Minor - P4</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="gjmurakami">Gary Murakami</assignee>
                                    <reporter username="gifford">Gifford Hesketh</reporter>
                        <labels>
                            <label>performance</label>
                    </labels>
                <created>Mon, 23 Jan 2012 06:47:03 +0000</created>
                <updated>Mon, 11 Nov 2013 21:01:47 +0000</updated>
                            <resolved>Mon, 11 Nov 2013 21:01:47 +0000</resolved>
                                    <version>0.4</version>
                                    <fixVersion>0.90.0</fixVersion>
                                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="454630" author="christian.hergert@10gen.com" created="Mon, 11 Nov 2013 21:01:16 +0000"  >&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;The new C driver&lt;span class=&quot;error&quot;&gt;&amp;#91;1&amp;#93;&lt;/span&gt; uses scatter/gather I/O (with sendmsg()/recvmsg()) for communication with the MongoDB server. In many cases it will not malloc during the send phase of the message. Additionally, the recv phase of an operation opportunistically buffers to try to reduce the number of syscalls.&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;1&amp;#93;&lt;/span&gt; &lt;a href=&quot;https://github.com/chergert/libmongoc/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/chergert/libmongoc/&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="81653" author="kbanker" created="Mon, 23 Jan 2012 16:07:19 +0000"  >&lt;p&gt;Gifford,&lt;/p&gt;

&lt;p&gt;Thanks for the idea. I think it&apos;d be worthwhile to set up a simple benchmark to see exactly how much performance is improved. A non-trivial increase would obviously make the refactoring worthwhile.&lt;/p&gt;

&lt;p&gt;Kyle&lt;/p&gt;</comment>
                            <comment id="81572" author="gifford" created="Mon, 23 Jan 2012 06:48:43 +0000"  >&lt;p&gt;Sorry the sample code looks so ugly.  The formatting got lost in translation ...&lt;/p&gt;</comment>
                    </comments>
                    <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|hrmmhb:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>45720</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                    <customfield id="customfield_10557" key="com.pyxis.greenhopper.jira:gh-sprint">
                        <customfieldname>Sprint</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue id="60">Sprint 1</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>