Reputation: 918
How can I check if meteor is using the oplog of my mongo? I have a cluster of mongo and set two envs for my meteor.
MONGO_URL=mongodb://mongo/app?replicaSet=rs0
MONGO_OPLOG_URL=mongodb://mongo/local?authSource=app
How can I check if the opt log is actually in use. Meteor can fallback to query polling which is very inefficient but I would like to see if it's working properly with the oplog.
Any ideas?
Upvotes: 4
Views: 3181
Reputation: 866
This may be very late, but this is the only way that worked for me :
someCollection._driver.mongo._oplogHandle
if this is set to null then the oplog is not enabled, otherwise you can use this handle to check for more details.
Upvotes: 0
Reputation: 36930
To set up oplog tailing, you need to set up a user
on my_database
, and an oplog_user
on local
. Then, specify the following URIs to connect to your replica set named test-shard
(e.g. if there are 3 hosts named test-shard-[0-2]
):
MONGO_URL="mongodb://user:[email protected]:27017,test-shard-1.mongodb.net:27017,test-shard-2.mongodb.net:27017/my_database?ssl=true&replicaSet=test-shard&authSource=admin"
MONGO_OPLOG_URL="mongodb://oplog_user:[email protected]:27017,test-shard-1.mongodb.net:27017,test-shard-2.mongodb.net:27017/local?ssl=true&replicaSet=test-shard&authSource=admin"
On MongoDB Atlas they require ssl=true
, and also all users authenticate through the admin
database. On another deployment you might just authenticate through my_database
, in which case you'd remove the authsource=admin
for MONGO_URL
and write authsource=my_database
for MONGO_OPLOG_URL
. See this post for another example.
With MongoDB 3.6 and the Mongo node driver 3.0+, you may be able to use a succinct notation for DNS seedlist connections, e.g. on MongoDB Atlas, to specify the environment variables:
MONGO_URL="mongodb+srv://user:[email protected]/my_database"
MONGO_OPLOG_URL="mongodb+srv://oplog_user:[email protected]/local"
The link above explains how this notation fills in the ssl
, replicaSet
, and authSource
arguments. This is a lot nicer than the long strings above, and also means you can scale your replica set up and down without needing to reconfigure anything.
As hwillson mentioned, use the facts-ui
and facts-base
packages (formerly facts
) to see if there are any oplogObserveDriver
s running in your app. If they are all pollingObserveDriver
, than oplog is not set up correctly.
Upvotes: 3
Reputation: 6382
If you are using Kadira APM to monitor your app's performance, you can see if oplogs are working by navigating to the "Live Queries" section and having a look at the "Oplog notifications" chart.
You can see in my screenshot that oplogs are working, as values appear in the chart (bottom right). If oplogs weren't working then this chart would be empty.
Upvotes: 2
Reputation: 1399
Quoting the relevant bits from Meteor's OplogObserveDriver
docs:
How to tell if your queries are using OplogObserveDriver
For now, we only have a crude way to tell how many observeChanges calls are using OplogObserveDriver, and not which calls they are.
This uses the
facts
package, an internal Meteor package that exposes real-time metrics for the current Meteor server. In your app, runmeteor add facts
, and add the{{> serverFacts}}
template to your app. If you are using theautopublish
package, Meteor will automatically publish all metrics to all users. If you are not usingautopublish
, you will have to tell Meteor which users can see your metrics by callingFacts.setUserIdFilter
in server code; for example:
Facts.setUserIdFilter(function (userId) {
var user = Meteor.users.findOne(userId);
return user && user.admin;
});
(When running your app locally,
Facts.setUserIdFilter(function () { return true; });
may be good enough!)Now look at your app. The facts template will render a variety of metrics; the ones we're looking for are observe-drivers-oplog and observe-drivers-polling in the mongo-livedata section. If observe-drivers-polling is zero or not rendered at all, then all of your observeChanges calls are using OplogObserveDriver!
Upvotes: 4