Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any benefits/pitfalls for running multiple MongoDB shards within a single server?

Tags:

mongodb

I am currently running a traditional MySQL Master/Slave set up with about 90GB of data. The traffic on our application is increasing rapidly, and already this set up is showing signs of slowing down. I would very much love to try out MongoDB and I am especially excited with the auto-sharding feature.

However, I currently have only 2 (dedicated) DB servers at my disposal, and definitely one of them has to be used for replication. So here is my question:

If I run multiple instances of MongoDB as shards within the same server, will I actually reap the benefits of having smaller sharded data sets? Or will this instead cause the performance to tank due to increased load / memory requirements?

like image 493
Wenxiang Wu Avatar asked Nov 11 '10 14:11

Wenxiang Wu


People also ask

How does sharding improve performance in MongoDB?

Sharding is MongoDB's way of supporting horizontal scaling. When you shard a MongoDB collection, the data is split across multiple server instances. This way, the same node is not queried in succession. The data is split on a particular field in the collection you've selected.

What is the use of shards in MongoDB?

A shard is a single MongoDB instance that holds a subset of the sharded data. Shards can be deployed as replica sets to increase availability and provide redundancy. The combination of multiple shards creates a complete data set.

When should I shard MongoDB?

MongoDB uses sharding to support deployments with very large data sets and high throughput operations. Database systems with large data sets or high throughput applications can challenge the capacity of a single server. For example, high query rates can exhaust the CPU capacity of the server.

Which one is good sharding or replication justify?

Replication may help with horizontal scaling of reads if you are OK to read data that potentially isn't the latest. sharding allows for horizontal scaling of data writes by partitioning data across multiple servers using a shard key. It's important to choose a good shard key.


2 Answers

Kristina Chodorow of MongoDB has a series of blog posts about sharding and replica sets in MongoDB. She mentions that you almost never want sharding, at least not until you've tried replica sets. Read her series on replica sets too: part 1, part 2, part 3

like image 61
Theo Avatar answered Oct 06 '22 00:10

Theo


Why not run shard across the two servers, and have a second mond instance on each server that replicates the other shard? That would give you sharding and redundancy. If one server went down, the other server would have the replica.

Sharding might be useful if each mongod instances data folder was on a different disk, or if the entire data set fit into memory and you have multiple cores.

like image 26
Justin Dearing Avatar answered Oct 05 '22 23:10

Justin Dearing