YCSB测试MongoDB分片

 下面测试一下分片(我这里的分片参见我前面MongoDB分片搭建

启动

MongoDB中的启动顺序是,先启动配置服务器,在启动分片,最后启动mongos。(三台机器)

mongod -f /usr/local/mongodb/conf/config.conf
mongod -f /usr/local/mongodb/conf/shard1.conf
mongod -f /usr/local/mongodb/conf/shard2.conf
mongod -f /usr/local/mongodb/conf/shard3.conf
mongos -f /usr/local/mongodb/conf/mongos.conf

串联路由服务器

搭建了mongodb配置服务器、路由服务器,各个分片服务器,不过应用程序连接到mongos路由服务器并不能使用分片机制,还需要在程序里设置分片配置,让分片生效。

登陆任意一台mongos

mongo --port 20000

使用admin数据库

use  admin

串联路由服务器与分配副本集

sh.addShard("shard1/192.168.0.100:27001,192.168.0.101:27001,192.168.0.102:27001");
sh.addShard("shard2/192.168.0.100:27002,192.168.0.101:27002,192.168.0.102:27002");
sh.addShard("shard3/192.168.0.100:27003,192.168.0.101:27003,192.168.0.102:27003");

查看集群状态

sh.status()

登陆任意一台mongos

mongo --port 20000

使用管理数据库

use  admin

指定TESTDB(数据库)分片生效

db.runCommand( { enablesharding :"testdb"});

指定数据库里需要分片的集合和片键,哈希id分片

db.runCommand( { shardcollection : "testdb.table1",key : {"_id": "hashed"} } );

我们设置testdb的table1表需要分片,根据i_d自动分片到shard1,shard2,shard3上面去。要这样设置是因为不是所有mongodb的数据库和表都需要分片!

测试分片配置结果

连接MongoDB路由服务

mongo  127.0.0.1:20000

YCSB进行MongoDB分片压力测试

./bin/ycsb load mongodb -threads 100 -s -P workloads/mongotest_in_only -p mongodb.url=mongodb://127.0.0.1:20000/ycsb?w=0 > outputLoad_shard.txt

使用Mongostat辅助测试(我这里ycsb数据库没有指定用户及密码)

mongostat --host 127.0.0.1:20000 --authenticationDatabase ycsb

 

posted @ 2019-04-18 20:45  iDataSharing  阅读(676)  评论(0编辑  收藏  举报