tduccuong

tduccuong

Mongodb driver query replica set very slow

hi,

I use this driver https://github.com/zookzook/elixir-mongodb-driver
to connect to my replica set including 3 nodes across the Internet. The connection string is

mongodb://<auth-info>@localhost:27017/<db>?authSource=<db>&w=1

As you see the connection is only to localhost. But the query is very slow:

Mongo.find(:mongo_conn_pool, <collection-name>, %{_id: <doc-string-id>})

took on average 170ms to complete! The collection contains only few hundred of small documents.

To test, I connect the data set using mongo client with same connection string above, and here is the query explain:

<dataset-name>:SECONDARY> db.<collection>.find({_id: <doc-string-id>}).explain("executionStats")
{
	"queryPlanner" : {
		"plannerVersion" : 1,
		"namespace" : "<db>.<collection>",
		"indexFilterSet" : false,
		"parsedQuery" : {
			"_id" : {
				"$eq" : <doc-string-id>
			}
		},
		"winningPlan" : {
			"stage" : "IDHACK"
		},
		"rejectedPlans" : [ ]
	},
	"executionStats" : {
		"executionSuccess" : true,
		"nReturned" : 1,
		"executionTimeMillis" : 0,
		"totalKeysExamined" : 1,
		"totalDocsExamined" : 1,
		"executionStages" : {
			"stage" : "IDHACK",
			"nReturned" : 1,
			"executionTimeMillisEstimate" : 0,
			"works" : 2,
			"advanced" : 1,
			"needTime" : 0,
			"needYield" : 0,
			"saveState" : 0,
			"restoreState" : 0,
			"isEOF" : 1,
			"keysExamined" : 1,
			"docsExamined" : 1
		}
	},
	"serverInfo" : {
		"host" : <host-name>,
		"port" : 27017,
		"version" : "4.4.1",
	},
	"ok" : 1,
	"$clusterTime" : {
		"clusterTime" : Timestamp(1607619155, 1),
		"signature" : {
			"hash" : BinData(0,"/FCwtvQs6sJq6q/3pwRZU3oBv04="),
			"keyId" : NumberLong("6886352401205297154")
		}
	},
	"operationTime" : Timestamp(1607619155, 1)
}

which is much much faster than via the mongodb driver.

To test further, I connected my app to the replica set, using the same above connection string, but this time on the primary node. The same query (via mongodb-driver), to my surprise, took only ~2ms.

My guess is, somehow the driver does not force query on the current local node? That is, when I make a query not on a primary node, the driver still contact the primary (which is about 170ms ping round trip away) to perform the query?

Where Next?

Popular in Questions Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

Other popular topics Top

peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New

We're in Beta

About us Mission Statement