mongoc driver mongoc_socket_setsockopt

21 views
Skip to first unread message

Guglielmo Fanini

unread,
Jul 22, 2019, 12:56:07 PM7/22/19
to mongodb-user
can mongoc_socket_setsockopt in mongoc driver be used to set socket receive/transmit buffer size with SO_RCVBUF/SO_SNDBUF option in order to increase throughput

should this be done on server side as well, thank you for any clues


Jeremy Mikola

unread,
Dec 9, 2019, 8:12:38 PM12/9/19
to mongodb-user


On Monday, July 22, 2019 at 12:56:07 PM UTC-4, Guglielmo Fanini wrote:
can mongoc_socket_setsockopt in mongoc driver be used to set socket receive/transmit buffer size with SO_RCVBUF/SO_SNDBUF option in order to increase throughput

should this be done on server side as well, thank you for any clues


I can't speak for the server, but I believe libmongoc's mongoc_socket_setsockopt function is only part of the http://mongoc.org/libmongoc/current/mongoc_socket_t.html abstraction. AFAIK, libmongoc's public API does not actually expose the sockets used for its database connections. Rather, these functions are related to the stream abstraction (http://mongoc.org/libmongoc/current/mongoc_stream_t.html), which exists to allow wrapping drivers to provide their own IO mechanism for libmongoc. Older versions of the PHP driver used the streams API for that purpose.

That said, the source of mongoc_socket_setsockopt suggests that it's a very thin wrapper around setsockopt, so I presume it would work if you obtained a mongoc_socket_t* from libmongoc.
 

Guglielmo Fanini

unread,
Dec 9, 2019, 8:22:38 PM12/9/19
to mongodb-user
My suspicion is there is no buffer enlargement, at least on client side apparent, because in the case of frequent round trip write-read (from client initiated to db say) it is akin to inter process RPC, depending heavily on RTT, thus you'd gain very little, however in the case of consistent write only to the db with write concern 0 (don't care for return code in case of well known surely writeable insert/update) and for stream changes consistent read only from the db it should help.
Another question : change streams are literally that, i.e. they don't report if the same field value is overwritten in the db, is that so, thanks for informations.

Jeremy Mikola

unread,
Dec 9, 2019, 8:30:39 PM12/9/19
to mongod...@googlegroups.com
On Mon, Dec 9, 2019 at 8:22 PM Guglielmo Fanini <g.fa...@gmail.com> wrote:

Another question : change streams are literally that, i.e. they don't report if the same field value is overwritten in the db, is that so, thanks for informations.

Change streams leverage the replica set oplog, so you should not expect the change stream to report an event if the document is not actually changed. To test this, I spawned two mongo shells connected to the same replica set.

In the first, I inserted a new document and performed an update that did not modify the document.

rs0:PRIMARY> db.foo.insert({x:1})
WriteResult({ "nInserted" : 1 })
rs0:PRIMARY> db.foo.updateOne({x:1},{$set:{x:1}});
{ "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 0 }
 
In the second shell, I opened a change stream shortly before executing the insert/update operations and observed that only one event was reported:

rs0:PRIMARY> db.foo.watch()
{ "_id" : { "_data" : "825DEEF44E000000022B022C0100296E5A10048054A49ABDBD4530A95A9F02F3124A1746645F696400645DEEF44E406545D3AF8769CE0004" }, "operationType" : "insert", "clusterTime" : Timestamp(1575941198, 2), "fullDocument" : { "_id" : ObjectId("5deef44e406545d3af8769ce"), "x" : 1 }, "ns" : { "db" : "test", "coll" : "foo" }, "documentKey" : { "_id" : ObjectId("5deef44e406545d3af8769ce") } }

Reply all
Reply to author
Forward
0 new messages