-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 7.0.8
-
Component/s: None
-
None
-
Environment:Ubuntu 18, Phusion Passenger, Ruby 2.5.8 Mongo Atlas with Global Write Enabled
-
(copied to CRM)
-
When Mongoid reloads models it will use the shard key declared for the model, if one exists, in addition to the id field in the find query.
Given a Global Write enabled Mongo Atlas cluster with the following compound shard keys:
{ location: 1, token: 1 }
The reload mechanism for my document takes around 200 ms. This severely affects the performance of my application since all of the invocations of delete_all/destroy_all seems to utilize the reload mechanism on the document.
It also appears that the "identity" of the document is not compatible with Global Write clusters, since it only utilizes the document's ID
Here's some code to demonstrate the performance issues:
mc = nil Benchmark.bm(100) do |bm| bm.report("Initialize Mongo connection and get Mongo Cart") do mc = MongoCart.where(location: "CA", token: "4d8e7b38d7ac73ba68cf6401299b918f").first end bm.report("Re-fetch Mongo Cart") do mc = MongoCart.where(location: "CA", token: "4d8e7b38d7ac73ba68cf6401299b918f").first end bm.report("Reload Mongo Cart") do mc.reload end bm.report("Get Mongo Cart by Token") do mc = MongoCart.find_by(token: "4d8e7b38d7ac73ba68cf6401299b918f") end bm.report("Get Mongo Cart by ID") do mc = MongoCart.find(mc._id) end bm.report("Get Mongo Cart by Location + ID") do mc = MongoCart.where(location: "CA", _id: mc._id).first end end
And the resulting benchmarks are attached.
Can there be a way to have the reload mechanism include shard key fields to improve its performance?
- is related to
-
MONGOID-4759 Change updates to prefer target by the query
- Backlog
- links to