5

I recently changed my server setup to include a replica set. The secondary DBs are located in multiple regions around the world to decrease latency. The problem is that I think all of the reads are being done from the master and not from the secondary servers. I'm seeing 500ms+ latency in newrelic on servers far away from the master DB, but the staging server, which is in the same region as the master is ~20ms. How can I check if the secondary read or nearest is working, or do I have a setting missing / wrong? (I have tried both SECONDARY_PREFERRED, and NEAREST)

Url:

mongodb://1.1.1.1:27017,1.1.1.2:27017,1.1.1.3:27017,1.1.1.4:27017,1.1.1.5:27017/mydatabase

My options look like this:

"replSet": {
   "rs_name": "myRepSet"
   "readPreference": "ReadPreference.SECONDARY_PREFERRED",
   "read_preference": "ReadPreference.SECONDARY_PREFERRED",
   "slaveOk": true
}

Mongoose version: 3.8.x

codephobia
  • 1,580
  • 2
  • 17
  • 42

3 Answers3

3

As per the project issues on gitHub there was a issue where the Read preference does not seem to be working when upgrading to the newest version (mongoose@3.8.1 & mongodb@1.3.23) as all the reads are being done from the master and not from the secondary servers.

As per the comments this problem doesnot come when you roll back to older version(mongoose@3.6.4 & mongodb@1.2.14), reads will start going to the secondaries(collection level). This issue is meant to be fixed in version 3.8.7.

Please reference the following issues for the same:

https://github.com/Automattic/mongoose/issues/1833 https://github.com/Automattic/mongoose/issues/1895

sahil gupta
  • 2,339
  • 12
  • 14
  • We actually updated to Mongoose 4.x to half fix the issue, then made some modifications to the code ourselves which saw decreased latency to ~20-60ms. I'll give credit for this answer though since it is on track with what we did. – codephobia Jul 17 '15 at 19:11
1

How can I check if the secondary read or nearest is working,

If you have access to your machines, a simple way to check which ones are being queried is with mongostat. Just log into one of your servers and run

mongostat --discover

This will give you basic output on inserts/queries/updates/delete that are being run on each machine in your replica set. If you have a quiet system it will be easy to see where the queries are being redirected to so you can at least know whether your secondaries are being hit.

If they aren't, you will need to investigate your driver settings.

womp
  • 115,835
  • 26
  • 236
  • 269
  • It just seems to be showing the sync between nodes. With 40k hits to the website a day, there is just too much data showing there to make sense of anything. – codephobia Jul 15 '15 at 00:03
  • 1
    Too bad, but understandable. You could log into just one of your secondaries and run mongostat locally and see if anything shows up under the "queries" column. – womp Jul 15 '15 at 00:05
0

Instead of secondary can you check with nearest option. I guess that should work. Check this link. http://docs.mongodb.org/manual/reference/read-preference/#nearest

  • As I said in the question, I have tried both options with the same results. – codephobia Jul 14 '15 at 22:27
  • My bad. End of the day and my eyes are worse now. Anyway did you check this link. Looks to me worth give a try. http://emptysqua.re/blog/reading-from-mongodb-replica-sets-with-pymongo/ – malay biswal Jul 14 '15 at 22:36