Raj Saraogi
Raj Saraogi

Reputation: 1938

How to decide when to use replicate sets for mongodb in production

We are currently hosting the MongoDB using its official docker image in ec2, for our production environment, its 32gb memory server dedicated to just this service.

How can using replica sets help us in the improvement of the performance of our MongoDB, we are currently facing that the response for queries is getting slower day by day.

Are there any measures through which we can determine that investing in the replica set will provide worthy benefits as well and will not be premature optimization.

Upvotes: 4

Views: 2130

Answers (2)

genericUser
genericUser

Reputation: 7158

It is recommended to use replica-set in production due to HA functionality.

As a result of source limits on one hand and the need of HA in production on the other hand, I would suggest you to create a minimal replica-set which will consist of Primary, Secondary and an Arbiter (an arbiter does not contain any data and is very low memory consumer).

Also, Writes typically effect your memory performance much more than reads. In order to achieve better write performance I would advice you to create more shards (the more masters you have, the more writes you can handle at the same time).

However, I'm not sure what case your mongo's performance to slow so fast. I think you should:

  1. Check what is most effect your production's performance (complicated queries or hard writes).
  2. Change your read preference to "nearest".
  3. Consider to disable Read Concern "majority" (remember that by default there is a write "majority" concern. Members should be up to date).
  4. Check for a better index.
  5. And of curse create a replica-set!

Good Luck! :P

Upvotes: 0

prasad_
prasad_

Reputation: 14287

MongoDB replication is a high availability solution (see note at the end of the post for more details on Replication). Replication is not a performance improvement solution.

MongoDB query performance depends upon various factors: size of collection, size of document, database design, query definition and indexes. Inadequate hardware (memory, hard drive, cpu and network) can affect the query performance. The number of operations at a given time can also affect the performance.

For faster query performance the main consideration is using indexes. Indexes affect directly the query filter and sort operations. To find if your query is performing optimally and using the proper indexes generate a query plan using the explainwith "executionStats" mode; study the plan. Explain can be run on MongoDB find, update, delete and aggregation queries. All these queries can benefit from indexes. See Query Optimization.

Adding capabilities to the existing hardware is known as vertical scaling; and replication is not vertical scaling.


Replication:

This is configured as a replica-set - a primary node and multiple secondary nodes. The primary is the main point of contact for application - all writes happen on the primary, (and reads, by default). The data written to the primary is replicated to the secondaries. This way data redundancy is accomplished. When the primary goes down one of the secondaries takes over as primary and keep the system running via a failover process. Data durability, high availability, redundancy and failover are the man concepts with replication. In MongoDB a replica-set cluster can have up to fifty nodes.

Upvotes: 1

Related Questions