Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDb - Utilizing multi CPU server for a write heavy application

I am currently evaluating MongoDb for our write heavy application...

Currently MongoDb uses single thread for write operation and also uses global lock whenever it is doing the write... Is it possible to exploit multiple CPU on a multi-CPU server to get better write performance? What are your workaround for global write lock?

like image 386
StackUnderflow Avatar asked Dec 10 '10 09:12

StackUnderflow


People also ask

Is MongoDB CPU intensive?

In short, often bad database queries and wrong MongoDB server settings result in MongoDB high CPU usage on the server.

Is MongoDB multithreaded?

The MongoDB server currently uses a thread per connection plus a number of internal threads. You can list all threads (including idle and system) using db. currentOp(true) in the mongo shell. If you have 8 incoming requests, each of those will be handled by a separate connection thread.


2 Answers

No, it is still recommended to use sharding to utilize multiple CPU cores. As stated in the FAQ

Sharding improves concurrency by distributing collections over multiple mongod instances, allowing shard servers (i.e. mongos processes) to perform any number of operations concurrently to the various downstream mongod instances.

Each mongod instance is independent of the others in the shard cluster and uses the MongoDB readers-writer lock). The operations on one mongod instance do not block the operations on any others.

Sharding on a single box has its issues, as one user stated in the mongodb-user mailing list

After some significant experimentation, I've found a single MongoDB shard daemon CANNOT use more than one CPU. On a 24 CPU box, performance scales up until we hit about 8 shards, then another limit kicks in.

like image 149
fitheflow Avatar answered Oct 07 '22 16:10

fitheflow


So right now, the easy solution is to shard.

Yes, normally sharding is done across servers. However, it is completely possible to shard on a single box. You simply fire up the shards on different ports and provide them with different folders. Here's a sample configuration of 2 shards on one box.

The MongoDB team recognizes that this is kind of sub-par, and I know from talking to them that they're looking at better ways to do this.

Obviously once you get multiple shards on one box and increase your write threads, you will have to be wary of disk IO. In my experience, I've been able to saturate disks with a single write thread. If your inserts/updates are relatively simple, you may find that extra write threads don't do anything. (Map-Reduces are the exception here, sharding definitely helps there)

like image 32
Gates VP Avatar answered Oct 07 '22 17:10

Gates VP