Wednesday 15 June 2016

Scaling the Read Query Load On MongoDB server



Requirement Overview:We are capturing all activity on Jobs In mongoDB like view ,apply,view source,apply source etc.There is lots of read query fired on real times to get stats about jobs.
We need to scale our read load so that we can serve all read request without any delay.


Approach :There are 2 ways of reducing read load on Primary MongoDB server.
       
  1. Distributing the Data on Multiple Node (Sharding).
            
     2.  Use secondary mongodb node for read query.


By default, an application directs its read operations to the primary member in a replica set.        




Since Our data size is not large ,we have not implemented sharding .But read operation are very high on the same data Set.
Code Snippet:


var collection =dataLoggerDB.collection(currentCollection,{readPreference:'secondaryPreferred'});


Read Preference Options:


Read Preference Mode
Description
Default mode. All operations read from the current replica set primary.
In most situations, operations read from the primary but if it is unavailable, operations read from secondary members.
All operations read from the secondary members of the replica set.
In most situations, operations read from secondary members but if no secondary members are available, operations read from the primary.
Operations read from member of the replica set with the least network latency, irrespective of the member’s type.

No comments:

Post a Comment