【转载】MongoDB 1000W级数据 Insert和Query和Delete性能测试
加索引测试:
- > db.users.getIndexes()
- [
- {
- "name" : "_id_",
- "ns" : "test.users",
- "key" : {
- "_id" : 1
- },
- "v" : 0
- }
- ]
- > db.users.ensureIndex({NewsId:1})
- > db.users.getIndexes()
- [
- {
- "name" : "_id_",
- "ns" : "test.users",
- "key" : {
- "_id" : 1
- },
- "v" : 0
- },
- {
- "_id" : ObjectId("4e2cc408572ff09d98851cb7"),
- "ns" : "test.users",
- "key" : {
- "NewsId" : 1
- },
- "name" : "NewsId_1",
- "v" : 0
- }
- ]
......................# MongoDB 加索引 插入1000W条测试 #...................
- ^_^[root@:~/svn/nugget/MongoDB/utest]#./insertData
- MongoDB Connected OK!
- Time:2019s:19419μs
......................# MongoDB 加索引 1000W条测试遍历测试 #...................
还是一样取最后一条数据,然后看下性能:
- ^_^[root@:/usr/local/mongodb/bin]#./mongo <bat.js
- MongoDB shell version: 1.8.2
- connecting to: test
- > var startTime = new Date();
- >
- > db.users.find({NewsId:"nxuvdqtjrrptoyildolesbkqmd"});
- { "_id" : ObjectId("4e2ccc2ea1ca039d82b9e4b3"), "NewsId" : "nxuvdqtjrrptoyildolesbkqmd" }
- >
- > (new Date().getTime()-startTime.getTime())/1000
- 0.022s
- > bye
......................# MongoDB 加索引 删除1000W条测试 #...................
- ^_^[root@:/usr/local/mongodb/bin]#./mongo 10.7.3.228 < bat.js
- MongoDB shell version: 1.8.2
- connecting to: 10.7.3.228/test
- > var startTime = new Date();
- > //db.users.find({NewsId:"csgsqdglbyfuwdjfkkrxgzyacc"});
- > db.users.remove()
- > (new Date().getTime()-startTime.getTime())/1000
- 570.782
- > bye
......................# MongoDB 加索引 1000W中删除一条测试 #...................
- ^_^[root@:/usr/local/mongodb/bin]#./mongo 10.7.3.228 < bat.js
- MongoDB shell version: 1.8.2
- connecting to: 10.7.3.228/test
- > var startTime = new Date();
- > //db.users.find({NewsId:"csgsqdglbyfuwdjfkkrxgzyacc"});
- > db.users.remove({"NewsId":"cikjwikamhtixoykrrfjnepkwu"})
- > (new Date().getTime()-startTime.getTime())/1000
- 0.025
- > bye
总结下测试数据吧:
没索引
添加 1 千万 记录 Time:207s:194125μs
查询 5.846s
删除全部 103.94s
删除最后一条 3.991s
有索引
添加 1 千万 记录 Time:2019s:19419μs
查询 0.022s
删除全部 570.782s
删除最后一条 0.025s