tduccuong

tduccuong

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? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews