[摘要]tokumx完全兼容mongodb,不过在性能上比原生的mongodb有20倍的提升。详细见tokumx官网的介绍:TokuMX – High-Performance MongoDB Distribution 从tokutek官网下载的Mongodb版本是已经编译过的,解压后直接可以使用。需要注意的是Linux内核要禁止transparent huge pages的使用。
mongodb配置:
cat /etc/mongodb.conf bind_ip = 192.168.100.101 port = 27017 fork = true pidfilepath = /var/run/mongodb/mongodb.pid logpath = /var/log/mongodb/mongodb.log dbpath = /data/mongodb/ journal = true replSet = sudops_set nohttpinterface = true
初始化replset
config = { _id : "sudops_set", members : [ {_id:0,host:"192.168.100.101:27017"}, {_id:1,host:"192.168.100.102:27017"}, {_id:2,host:"192.168.100.103:27017"}, ] } rs.initiate(cfg)
初始化之后查询replic状态:
sudops_set:PRIMARY> rs.conf() { "_id" : "sudops_set", "version" : 3, "protocolVersion" : 65, "members" : [ { "_id" : 0, "host" : "192.168.100.101:27017" }, { "_id" : 1, "host" : "192.168.100.102:27017" }, { "_id" : 2, "host" : "192.168.100.103:27017" } ] }
插入/查询数据测试:
use fisher siteinfo = {"sitename":"www.sudops.com", "content":"site about cloud service", "date":new Date() } db.fisher.insert(siteinfo) db.fisher.find().limit(1) sudops_set:PRIMARY> db.fishertestdb.find().limit(1) { "_id" : ObjectId("5328166733c35a42f94bb530"), "sitename" : "www.sudops.com", "content" : "site about cloud service", "date" : ISODate("2014-03-18T09:48:17.355Z") }
在slave上进行插入数据有如下报错:
error: { "$err" : "not master and slaveOk=false", "code" : 13435 }
需要在shell下执行下面的命令即可
rs.slaveOk() “shorthand for db.getMongo().setSlaveOk()”
最后贴出tokumx有意思的报错时的启动画面:
Tue Mar 18 17:01:45.997 [initandlisten] [tokumx] startup Tue Mar 18 17:01:45.998 [initandlisten] ERROR: Tue Mar 18 17:01:45.998 [initandlisten] Tue Mar 18 17:01:45.998 [initandlisten] ************************************************************ Tue Mar 18 17:01:45.998 [initandlisten] Tue Mar 18 17:01:45.998 [initandlisten] @@@@@@@@@@@ Tue Mar 18 17:01:45.998 [initandlisten] @@' '@@ Tue Mar 18 17:01:45.998 [initandlisten] @@ _ _ @@ Tue Mar 18 17:01:45.998 [initandlisten] | (.) (.) | Tue Mar 18 17:01:45.998 [initandlisten] | ` | Tue Mar 18 17:01:45.998 [initandlisten] | > ' | Tue Mar 18 17:01:45.998 [initandlisten] | .----. | Tue Mar 18 17:01:45.998 [initandlisten] .. |.----.| .. Tue Mar 18 17:01:45.998 [initandlisten] .. ' ' .. Tue Mar 18 17:01:45.998 [initandlisten] .._______,. Tue Mar 18 17:01:45.998 [initandlisten] Tue Mar 18 17:01:45.998 [initandlisten] TokuMX will not run with transparent huge pages enabled. Tue Mar 18 17:01:45.998 [initandlisten] Please disable them to continue. Tue Mar 18 17:01:45.998 [initandlisten] (echo never > /sys/kernel/mm/transparent_hugepage/enabled) Tue Mar 18 17:01:45.998 [initandlisten] Tue Mar 18 17:01:45.998 [initandlisten] The assertion failure you are about to see is intentional. Tue Mar 18 17:01:45.998 [initandlisten] ************************************************************ Tue Mar 18 17:01:45.998 [initandlisten] Tue Mar 18 17:01:45.998 [initandlisten] Assertion failure false /home/buildslave/buildslave-0/release_build-linux-e-opt/build/src/mongo/db/storage/env.cpp 1123 Tue Mar 18 17:01:46.002 [initandlisten] exception in initAndListen: 0 assertion /home/buildslave/buildslave-0/release_build-linux-e-opt/build/src/mongo/db/storage/env.cpp:1123, terminating Tue Mar 18 17:01:46.002 dbexit: Tue Mar 18 17:01:46.002 [initandlisten] shutdown: going to close listening sockets... Tue Mar 18 17:01:46.002 [initandlisten] shutdown: going to flush diaglog... Tue Mar 18 17:01:46.002 [initandlisten] shutdown: going to close sockets... Tue Mar 18 17:01:46.004 [initandlisten] shutdown: going to close databases... Tue Mar 18 17:01:46.004 [initandlisten] shutdown: going to unload all plugins... Tue Mar 18 17:01:46.004 [initandlisten] shutdown: going to shutdown TokuMX... Tue Mar 18 17:01:46.004 [initandlisten] [tokumx] shutdown Tue Mar 18 17:01:46.004 [initandlisten] shutdown: removing fs lock... Tue Mar 18 17:01:46.004 dbexit: really exiting now
tokumx具体的性能还没有进行测试,究竟是否像官网说的那样给力还需要事实来说明,不过单从Mongod服务的启动速度来看tokumx确实要比原生的mongodb快一些。