先看下测试机性能(64bit):
通渭ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为成都创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18982081108(备注:SSL证书合作)期待与您的合作!
- ^_^[root@:~]#grep "model name" /proc/cpuinfo | cut -f2 -d:
- Intel(R) Xeon(R) CPU E5606 @ 2.13GHz
- Intel(R) Xeon(R) CPU E5606 @ 2.13GHz
- Intel(R) Xeon(R) CPU E5606 @ 2.13GHz
- Intel(R) Xeon(R) CPU E5606 @ 2.13GHz
- Intel(R) Xeon(R) CPU E5606 @ 2.13GHz
- Intel(R) Xeon(R) CPU E5606 @ 2.13GHz
- Intel(R) Xeon(R) CPU E5606 @ 2.13GHz
- Intel(R) Xeon(R) CPU E5606 @ 2.13GHz
- ^_^[root@:~]#grep MemTotal /proc/meminfo
- MemTotal: 4040580 kB
- ^_^[root@:~]# free -m
- total used free shared buffers cached
- Mem: 3945 3715 230 0 40 2626
- -/+ buffers/cache: 1048 2897
- Swap: 4094 2 4092
- ^_^[root@:~]#getconf LONG_BIT
- 64
- ^_^[root@:~]#more /etc/redhat-release
- Red Hat Enterprise Linux Server release 5.5 (Tikanga)
- ^_^[root@:~]#uname -r
- 2.6.18-194.el5
测试程序:
- #include
- #include
- using namespace std;
- using namespace mongo;
- #define INIT_TIME \
- struct timeval time1,time2; \
- #define START_TIME \
- gettimeofday(&time1,NULL); \
- #define STOP_TIME \
- gettimeofday(&time2,NULL); \
- #define PRINT_TIME \
- cout<<"Time:"<
- int main() {
- srand(time(NULL));
- char ar[26+1];
- DBClientConnection conn;
- conn.connect("localhost");
- cout<<"MongoDB Connected OK!"<
- int count=10000000;
- INIT_TIME;
- START_TIME;
- //insert
- #if 1
- while (count--) {
- for (int i=0; i<26; i++) {
- ar[i] = rand()%26+97;
- }
- ar[26]='\0';
- BSONObj p = BSON("NewsId"<
- conn.insert("test.users",p);
- }
- #endif
- STOP_TIME;
- PRINT_TIME;
- return 0;
- }
不加索引测试:
......................# MongoDB 不加索引 插入1000W条测试 #...................
- ^_^[root@:~/svn/nugget/MongoDB/utest]#./insertData
- MongoDB Connected OK!
- Time:207s:194125μs
......................# MongoDB 不加索引 1000W条遍历测试 #...................
我们让MongoDB全部遍历一遍:
让测试数据倒序,取倒序后第一条数据:
- > db.users.find().sort({'_id':-1})
- { "_id" : ObjectId("4e2cbdf4a1ca039d82214e33"), "NewsId" : "dgvshdhevmjgunvbepgdkzirqk" }
第一条数据的NewsId为 dgvshdhevmjgunvbepgdkzirqk
测试程序:
- ^_^[root@:/usr/local/mongodb/bin]#./mongo
- MongoDB shell version: 1.8.2
- connecting to: test
- > var startTime = new Date();
- >
- > db.users.find({NewsId:"dgvshdhevmjgunvbepgdkzirqk"});
- { "_id" : ObjectId("4e2ccfd2a1ca039d82527b34"), "NewsId" : "dgvshdhevmjgunvbepgdkzirqk" }
- >
- > (new Date().getTime()-startTime.getTime())/1000
- 5.846s
- > bye
#p#
加索引测试:
- > 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
- 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
总结下测试数据吧:
没索引
添加 1 千万 记录 Time:207s:194125μs
查询 5.846s
有索引
添加 1 千万 记录 Time:2019s:19419μs
查询 0.022s
原文链接:http://blog.csdn.net/crazyjixiang/article/details/6630624
【编辑推荐】
本文名称:MongoDB1000W级数据Insert和Query性能测试
分享URL:http://www.shufengxianlan.com/qtweb/news41/214241.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联