Friday 15 July 2011

mongodb - Sharding on single machine -



mongodb - Sharding on single machine -

i want run shard on local server. please help me step step. want create multi instance of mongod on cpu(16 core). way, i'm collection consist of 7 1000000 documents, whether went missing when run shard?

i utilize script creating 3 shard on 1 replicaset:

# clean echo "killing mongod , mongos" killall mongod killall mongos echo "removing info files" rm -rf /media/mongo/data/config rm -rf /media/mongo/data/shard* rm -rf /data/config rm -rf /data/shard* # mac create sure rlimits high plenty open necessary connections ulimit -n 2048 # start replica set , tell it shard0 mkdir -p /media/mongo/data/shard0/rs0 mongod --replset s0 --logpath "/var/log/mongodb/s0-r0.log" --dbpath /media/mongo/data/shard0/rs0 --port 37017 --fork --shardsvr --smallfiles sleep 5 # connect 1 server , initiate set mongo --port 37017 << 'eof' config = { _id: "s0", members:[ { _id : 0, host : "localhost:37017" }, ]}; rs.initiate(config) eof # start replicate set , tell it shard1 mkdir -p /media/mongo/data/shard1/rs0 mongod --replset s1 --logpath "/var/log/mongodb/s1-r0.log" --dbpath /media/mongo/data/shard1/rs0 --port 47017 --fork --shardsvr --smallfiles sleep 5 mongo --port 47017 << 'eof' config = { _id: "s1", members:[ { _id : 0, host : "localhost:47017" }, ]}; rs.initiate(config) eof # start replicate set , tell it shard2 mkdir -p /media/mongo/data/shard2/rs0 mongod --replset s2 --logpath "/var/log/mongodb/s2-r0.log" --dbpath /media/mongo/data/shard2/rs0 --port 57017 --fork --shardsvr --smallfiles sleep 5 mongo --port 57017 << 'eof' config = { _id: "s2", members:[ { _id : 0, host : "localhost:57017" }, ]}; rs.initiate(config) eof # start 3 config servers rm cfg-a.log cfg-b.log cfg-c.log mkdir -p /media/mongo/data/config/config-a /media/mongo/data/config/config-b /media/mongo/data/config/config-c mongod --logpath "/var/log/mongodb/cfg-a.log" --dbpath /media/mongo/data/config/config-a --port 57040 --fork --configsvr --smallfiles mongod --logpath "/var/log/mongodb/cfg-b.log" --dbpath /media/mongo/data/config/config-b --port 57041 --fork --configsvr --smallfiles mongod --logpath "/var/log/mongodb/cfg-c.log" --dbpath /media/mongo/data/config/config-c --port 57042 --fork --configsvr --smallfiles # start mongos on port 27018 rm mongos-1.log sleep 5 mongos --port 27018 --logpath "/var/log/mongodb/mongos-1.log" --configdb localhost:57040,localhost:57041,localhost:57042 --fork echo "waiting 60 seconds replica sets come online" sleep 60 echo "connnecting mongos , enabling sharding" # add together shards , enable sharding on test db mongo --port 27018 << 'eof' db.admincommand( { addshard : "s0/"+"localhost:37017" } ); db.admincommand( { addshard : "s1/"+"localhost:47017" } ); db.admincommand( { addshard : "s2/"+"localhost:57017" } ); db.admincommand({enablesharding: "ibsng"}); eof sleep 5 echo "done setting sharded environment on localhost"

but don't know how add together shard key on collection. speed write/read(i/o) important.

sharding not help improve query performance if done on single machine has huge number of documents(7 1000000 not small).

reason : mongodb uses memory mapped files means re-create of info , indexes stored in ram , whenever there query fetches ram itself. in current scenario queries slower because info + indexes size big not fit in ram , hence there lot of i/o activity info disk bottleneck.

what else can done improve query performance (incase sharding not option):

increase ram on machine use indexes redesign schema

note - if implement above points, there limit how much query performance can improved, sharding linear scaling of read/write throughput can expected.

mongodb query-optimization sharding

No comments:

Post a Comment