tduccuong

tduccuong

Mongodb driver query replica set very slow

hi,

I use this driver GitHub - zookzook/elixir-mongodb-driver: MongoDB driver for Elixir · GitHub
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

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
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
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New

Other popular topics Top

New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
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
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement