Why mongodb arbiter needs dbpath? - mongodb

An mongodb arbiter roles are as follows:
An arbiter does not have a copy of data set and cannot become a primary. However, an arbiter participates in elections for primary. An arbiter has exactly 1 election vote.
Arbiters are mongod instances that are part of a replica set but do not hold data. Then, why arbiter needs dbpath?

The arbiter stores various housekeeping data, which you can inspect by looking at the local database:
MongoDB Enterprise ruby-driver-rs:ARBITER> db.getMongo().setSlaveOk()
MongoDB Enterprise ruby-driver-rs:ARBITER> use local
switched to db local
MongoDB Enterprise ruby-driver-rs:ARBITER> db.runCommand({listCollections:1})
{
"cursor" : {
"id" : NumberLong(0),
"ns" : "local.$cmd.listCollections",
"firstBatch" : [
{
"name" : "system.replset",
"type" : "collection",
"options" : {
},
"info" : {
"readOnly" : false,
"uuid" : UUID("108fbabe-4139-4d3d-8326-fc8e169b811d")
},
"idIndex" : {
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_"
}
},
{
"name" : "startup_log",
"type" : "collection",
"options" : {
"capped" : true,
"size" : 10485760
},
"info" : {
"readOnly" : false,
"uuid" : UUID("1c3ed741-a7f8-4fad-89f9-36f979cbfa22")
},
"idIndex" : {
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_"
}
},
{
"name" : "replset.oplogTruncateAfterPoint",
"type" : "collection",
"options" : {
},
"info" : {
"readOnly" : false,
"uuid" : UUID("37c4d64b-8fcc-4aa5-b1e0-2ac6b71e893a")
},
"idIndex" : {
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_"
}
},
{
"name" : "replset.election",
"type" : "collection",
"options" : {
},
"info" : {
"readOnly" : false,
"uuid" : UUID("53fc68a9-19c9-4262-b152-fafa99ea55f5")
},
"idIndex" : {
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_"
}
},
{
"name" : "replset.minvalid",
"type" : "collection",
"options" : {
},
"info" : {
"readOnly" : false,
"uuid" : UUID("5564332b-3c3f-4103-acbd-c53c7a71581c")
},
"idIndex" : {
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_"
}
},
{
"name" : "system.rollback.id",
"type" : "collection",
"options" : {
},
"info" : {
"readOnly" : false,
"uuid" : UUID("fa26f83a-8843-4b6d-8d4d-4cde192976bd")
},
"idIndex" : {
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_"
}
}
]
},
"ok" : 1
}

Related

MongoDB performing slow read-queries under load

I'm running a MongoDB on my VPS. Two instances of the same python bot are constantly reading and writing documents. Essentially, they continously repeat the following steps infinitely:
Get a document using find_and_modify() (no i cannot use find() here)
process data fetched in step 1 (takes 10-60 seconds)
update document using find_and_modify() (no i cannot use update() here)
This worked flawlessly until I deployed a REST API web server to view the results in the browser etc. Now whenever the bot instances and the web server are running at the same time, the bots slow down by minutes and a request to my web server takes 2 minutes. When either the bots or the web server are/is running, they both query the database within milliseconds.
Before I think about upgrading my VPS' RAM and CPU, I would like to understand what exactly causes this. I assume the problem lies in the database being overwhelmed with the amount of requests from the 3 clients (2 bot instances, 1 web server).
I found the command currentOp(), but I'm having issues understanding its return.
> db.currentOp({"secs_running": {"$gte": 5}})
{
"inprog" : [
{
"type" : "op",
"host" : "localhost:27017",
"desc" : "conn1555",
"connectionId" : 1555,
"client" : "127.0.0.1:37750",
"clientMetadata" : {
"driver" : {
"name" : "PyMongo",
"version" : "3.11.3"
},
"os" : {
"type" : "Linux",
"name" : "Linux",
"architecture" : "x86_64",
"version" : "5.4.0-71-generic"
},
"platform" : "CPython 3.8.5.final.0"
},
"active" : true,
"currentOpTime" : "2021-04-27T13:37:56.261+00:00",
"opid" : 3151480,
"lsid" : {
"id" : UUID("71d36512-c5a3-4fe9-b3f9-31fd23e86413"),
"uid" : BinData(0,"47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=")
},
"secs_running" : NumberLong(123),
"microsecs_running" : NumberLong(123430156),
"op" : "command",
"ns" : "nxmain.websites",
"command" : {
"aggregate" : "websites",
"pipeline" : [
{
"$match" : {
}
},
{
"$group" : {
"_id" : 1,
"n" : {
"$sum" : 1
}
}
}
],
"cursor" : {
},
"lsid" : {
"id" : UUID("71d36512-c5a3-4fe9-b3f9-31fd23e86413")
},
"$db" : "nxmain",
"$readPreference" : {
"mode" : "primaryPreferred"
}
},
"planSummary" : "COLLSCAN",
"numYields" : 934,
"locks" : {
"ReplicationStateTransition" : "w",
"Global" : "r",
"Database" : "r",
"Collection" : "r"
},
"waitingForLock" : false,
"lockStats" : {
"ReplicationStateTransition" : {
"acquireCount" : {
"w" : NumberLong(936)
}
},
"Global" : {
"acquireCount" : {
"r" : NumberLong(936)
}
},
"Database" : {
"acquireCount" : {
"r" : NumberLong(936)
}
},
"Collection" : {
"acquireCount" : {
"r" : NumberLong(936)
}
},
"Mutex" : {
"acquireCount" : {
"r" : NumberLong(2)
}
}
},
"waitingForFlowControl" : false,
"flowControlStats" : {
}
},
{
"type" : "op",
"host" : "localhost:27017",
"desc" : "conn1535",
"connectionId" : 1535,
"client" : "127.0.0.1:36886",
"clientMetadata" : {
"driver" : {
"name" : "PyMongo",
"version" : "3.11.3"
},
"os" : {
"type" : "Linux",
"name" : "Linux",
"architecture" : "x86_64",
"version" : "5.4.0-71-generic"
},
"platform" : "CPython 3.8.5.final.0"
},
"active" : true,
"currentOpTime" : "2021-04-27T13:37:56.261+00:00",
"opid" : 3152992,
"secs_running" : NumberLong(7),
"microsecs_running" : NumberLong(7503765),
"op" : "command",
"ns" : "admin.$cmd",
"command" : {
"ismaster" : 1,
"topologyVersion" : {
"processId" : ObjectId("60845741af792cc59a636f20"),
"counter" : NumberLong(0)
},
"maxAwaitTimeMS" : 10000,
"$db" : "admin",
"$readPreference" : {
"mode" : "primary"
}
},
"numYields" : 0,
"waitingForLatch" : {
"timestamp" : ISODate("2021-04-27T13:37:48.858Z"),
"captureName" : "AnonymousLatch"
},
"locks" : {
},
"waitingForLock" : false,
"lockStats" : {
},
"waitingForFlowControl" : false,
"flowControlStats" : {
}
}
],
"ok" : 1
}
As you can see there are two operations in the pipeline. The one with secs_running: 123 is the web server, the other one is one of the bot instances, which takes about 10-20 seconds when the web server is running in parallel.
What could be the cause for my problem and how can I solve it? Thank you in advance.

How does a Pageable request works?

I have a Pageable request which query for about 1.6 millions documents and each request limit the response to 1000 documents. The query use an index... Well at least it should... I'm using db.currentOp() to look for the request that takes a while to process. When I launched the query (yesterday at 01:00PM) it used the index for each portion of 1000. But it seems that at some point he decided not to use it anymore... And I can't figure out why...
I also have a command operation for the same query and it is using the index.
{
"desc" : "conn7758",
"threadId" : "1012",
"connectionId" : 7758,
"client" : "10.10.10.3:64670",
"clientMetadata" : {
"driver" : {
"name" : "mongo-java-driver",
"version" : "unknown"
},
"os" : {
"type" : "Windows",
"name" : "Windows Server 2008 R2",
"architecture" : "x86",
"version" : "6.1"
},
"platform" : "Java/Oracle Corporation/1.8.0_73-b02"
},
"active" : true,
"opid" : 119588895,
"secs_running" : 1299,
"microsecs_running" : NumberLong(1299666014),
"op" : "command",
"ns" : "thingsplay.data",
"query" : {
"count" : "data",
"query" : {
"device" : "S000110",
"topic" : "INPUTS/COIL1000",
"date" : {
"$gt" : ISODate("2015-08-08T06:00:00Z"),
"$lt" : ISODate("2018-06-14T11:28:08.369Z")
}
}
},
"planSummary" : "IXSCAN { device: 1, topic: 1, vhost: 1}",
"numYields" : 81449,
"locks" : {
"Global" : "r",
"Database" : "r",
"Collection" : "r"
},
"waitingForLock" : false,
"lockStats" : {
"Global" : {
"acquireCount" : {
"r" : NumberLong(162900)
}
},
"Database" : {
"acquireCount" : {
"r" : NumberLong(81450)
}
},
"Collection" : {
"acquireCount" : {
"r" : NumberLong(81450)
}
}
}
}
The request is still running... and I think it will be for a couple of hours.
Here is the last operations that is running :
{
"desc" : "conn7758",
"threadId" : "1012",
"connectionId" : 7758,
"client" : "10.10.10.3:64670",
"clientMetadata" : {
"driver" : {
"name" : "mongo-java-driver",
"version" : "unknown"
},
"os" : {
"type" : "Windows",
"name" : "Windows Server 2008 R2",
"architecture" : "x86",
"version" : "6.1"
},
"platform" : "Java/Oracle Corporation/1.8.0_73-b02"
},
"active" : true,
"opid" : 120813021,
"secs_running" : 134,
"microsecs_running" : NumberLong(134586683),
"op" : "query",
"ns" : "thingsplay.data",
"query" : {
"find" : "data",
"filter" : {
"device" : "S000110",
"topic" : "INPUTS/COIL1000",
"date" : {
"$gt" : ISODate("2015-08-08T06:00:00Z"),
"$lt" : ISODate("2018-06-14T11:28:08.369Z")
}
},
"projection" : {
},
"skip" : 1124000,
"limit" : 1000
},
"numYields" : 8445,
"locks" : {
"Global" : "r",
"Database" : "r",
"Collection" : "r"
},
"waitingForLock" : false,
"lockStats" : {
"Global" : {
"acquireCount" : {
"r" : NumberLong(16892)
}
},
"Database" : {
"acquireCount" : {
"r" : NumberLong(8446)
}
},
"Collection" : {
"acquireCount" : {
"r" : NumberLong(8446)
}
}
}
}
Unfortunately I don't have the operation of the first operations that went well but you can see here that it doesn't use the index.
[
{
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "thingsplay.data"
},
{
"v" : 2,
"key" : {
"device" : 1,
"topic" : 1,
"date" : 1
},
"name" : "device_1_topic_1_date_1",
"ns" : "thingsplay.data",
"background" : true
},
{
"v" : 2,
"key" : {
"device" : 1,
"topic" : 1,
"vhost" : 1
},
"name" : "device_1_topic_1_vhost_1",
"ns" : "thingsplay.data",
"background" : true
}
]

Why mongo doesn't use the right index?

I'm using MongoDB to store data with the following structure :
{ "_id" : ObjectId("5a497a1f451bf00880331913"), "device" : "deviceId", "topic" : "topicId", "vhost" : "vhostId", "date" : ISODate("2018-01-01T00:00:31.220Z"), "value" : 452 }
with the following indexes :
[
{
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "thingsplay.data"
},
{
"v" : 2,
"key" : {
"device" : 1,
"topic" : 1,
"date" : 1
},
"name" : "device_1_topic_1_date_1",
"ns" : "thingsplay.data",
"background" : true
},
{
"v" : 2,
"key" : {
"device" : 1,
"topic" : 1,
"vhost" : 1
},
"name" : "device_1_topic_1_vhost_1",
"ns" : "thingsplay.data",
"background" : true
}
]
But when I'm making a query with device, topic and date fields it uses device_1_topic_1_vhost_1 index...
For another request with the explain option I just had the right winning plan (device_1_topic_1_date_1) but when I execute it... I'm still waiting for it to complete and with db.currentOp() I don't see it using any index...
{
"desc" : "conn2172",
"threadId" : "2836",
"connectionId" : 2172,
"client" : "x.x.x.x:50177",
"appName" : "MongoDB Shell",
"clientMetadata" : {
"application" : {
"name" : "MongoDB Shell"
},
"driver" : {
"name" : "MongoDB Internal Client",
"version" : "3.6.2"
},
"os" : {
"type" : "Windows",
"name" : "Microsoft Windows Server 2008 R2",
"architecture" : "x86_64",
"version" : "6.1 SP1 (build 7601)"
}
},
"active" : true,
"opid" : 22137990,
"secs_running" : 322,
"microsecs_running" : NumberLong(322246758),
"op" : "command",
"ns" : "company.data",
"query" : {
"explain" : {
"find" : "data",
"filter" : {
"device" : "deviceId",
"topic" : "topicId",
"date" : {
"$gt" : ISODate("2018-01-01T00:00:00Z"),
"$lt" : ISODate("2018-06-12T16:18:00Z")
}
}
},
"verbosity" : "executionStats"
},
"numYields" : 19245,
"locks" : {
"Global" : "r",
"Database" : "r",
"Collection" : "r"
},
"waitingForLock" : false,
"lockStats" : {
"Global" : {
"acquireCount" : {
"r" : NumberLong(38492)
}
},
"Database" : {
"acquireCount" : {
"r" : NumberLong(19246)
}
},
"Collection" : {
"acquireCount" : {
"r" : NumberLong(19246)
}
}
}
}
I don't understand why the index is not being used...

Issue When I set shard key

I have a collection and I set shard it.
I have errors while I add a shard key!!!
mongos> sh.shardCollection('IBSng.connection_log', {login_time:1})
But I was shown this error:
Even I set compound shard with logout_time field with login_time, But the result shown to me this error.
{
"proposedKey" : {
"login_time" : 1
},
"curIndexes" : [
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "IBSng.connection_log"
},
{
"v" : 1,
"key" : {
"user_id" : 1
},
"name" : "user_id_1",
"ns" : "IBSng.connection_log"
},
{
"v" : 1,
"key" : {
"ras_id" : 1
},
"name" : "ras_id_1",
"ns" : "IBSng.connection_log"
},
{
"v" : 1,
"key" : {
"retry_count" : 1
},
"name" : "retry_count_1",
"ns" : "IBSng.connection_log"
},
{
"v" : 1,
"key" : {
"credit_used" : 1
},
"name" : "credit_used_1",
"ns" : "IBSng.connection_log"
},
{
"v" : 1,
"key" : {
"details.mac" : 1
},
"name" : "details.mac_1",
"ns" : "IBSng.connection_log"
},
{
"v" : 1,
"key" : {
"username" : 1
},
"name" : "username_1",
"ns" : "IBSng.connection_log"
},
{
"v" : 1,
"key" : {
"type_details.in_bytes" : 1,
"type_details.out_bytes" : 1
},
"name" : "type_details.in_bytes_1_type_details.out_bytes_1",
"ns" : "IBSng.connection_log"
},
{
"v" : 1,
"key" : {
"details.kill_reason" : 1
},
"name" : "details.kill_reason_1",
"ns" : "IBSng.connection_log"
},
{
"v" : 1,
"key" : {
"details.terminate_cause" : 1
},
"name" : "details.terminate_cause_1",
"ns" : "IBSng.connection_log"
},
{
"v" : 1,
"key" : {
"login_time" : -1,
"logout_time" : -1
},
"name" : "login_time_-1_logout_time_-1",
"ns" : "IBSng.connection_log",
"sparse" : false
}
],
"ok" : 0,
"errmsg" : "please create an index that starts with the shard key before sharding."
}
I Waiting for your answers.
Add an index for {login_time:1}, this is different to that compound one you have done.

Aggregation framework performance on a 10M collection

I have a collection of 10M documents, that is a pre-aggregation of daily events.
A simple $group took more than 8s, is this performance normal ?
Some date from the profiler :
{
"op" : "command",
"ns" : "analytics.$cmd",
"command" : {
"aggregate" : "aggregation",
"pipeline" : [
{
"$group" : {
"_id" : "",
"hits" : {
"$sum" : "$hits"
}
}
}
]
},
"ntoreturn" : 1,
"keyUpdates" : 0,
"numYield" : 15,
"lockStats" : {
"timeLockedMicros" : {
"r" : NumberLong(17169805),
"w" : NumberLong(0)
},
"timeAcquiringMicros" : {
"r" : NumberLong(8582619),
"w" : NumberLong(294)
}
},
"responseLength" : 78,
"millis" : 8594,
"ts" : ISODate("2013-12-04T15:57:38.217Z"),
"client" : "127.0.0.1",
"allUsers" : [ ],
"user" : ""
}
Here is one single document
{
"_id" : ObjectId("529e21ee67e807418500daeb"),
"date" : ISODate("2012-09-19T00:00:00Z"),
"hits" : 1,
"infos" : {
"sourceValue" : NumberLong(1),
"eventType" : "createUser",
"sourceType" : "user",
"instance" : "xxx",
"targetType" : "user",
"targetValue" : NumberLong(15)
}
}