Replicated MongoDB server slower than simple shards

Posted by displayName on Server Fault See other posts from Server Fault or by displayName
Published on 2014-08-18T21:41:27Z Indexed on 2014/08/18 22:22 UTC
Read the original article Hit count: 341

Filed under:
|
|

I tried to compare the performance of a sharded configuration against a sharded and replicated configuration.

The sharded configuration consists of 8 shards each running on three different machines thereby constituting a total of 24 shards. All 8 of these shards run in the same partition on each machine.

The sharded and replicated version is 8 shards again just like plain sharding, and all 8 mongods run on the same partition in each machine. But apart from this, each of these three machine now run additional 16 threads on another partition which serve as the secondary for the 8 mongods running on other machines. This is the way I prepared a sharded and replicated configuration with data chunks having replication factor of 3.

Important point to note is that once the data has been loaded, it is not modified. So after primary and secondaries have synchronized then it doesn't matter which one i read from.

To run the queries, I use an entirely different machine (let's call it config) which runs mongos and this machine's only purpose is to receive queries and run them on the cluster.

Contrary to my expectations, plain sharding of 8 threads on each machine (total = 3 * 8 = 24) is performing better for queries than the sharded + replicated configuration.

I have a script written to perform the query. So in order to time the scripts, I use time ./testScript and see the result. I tried changing the reading preference for replicated cluster by logging to mongo of config and run db.getMongo().setReadPref('secondary') and then exit the shell and run the queries like time ./testScript.

The questions are:

  1. Where am i going wrong in the replication? Why is it slower than its plain sharding version?
  2. Does the db.getMongo().ReadPref('secondary') persist when i leave the shell and try to perform the query?

All the four machines are running Linux and i have already increased the ulimit -n to 2048 from initial value of 1024 to allow more connections. The collections are properly distributed and all the mongods have equal number of chunks. Goes without saying that indices in both configurations are the same.

© Server Fault or respective owner

Related posts about replication

Related posts about mongodb