写入100万条记录,建立索引,使用索引连续查询 10万次。
use admin;//连接资料库 db.auth("mongoAdmin","123456");//登录 use test;//连接测试库 db.test_collection.dropIndexes(); db.test_collection.drop(); print("insert begin: "+Date());//写入开始时间 people = ["Marc", "Bill", "George", "Eliot", "Matt", "Trey", "Tracy", "Greg", "Steve", "Kristina", "Katie", "Jeff"]; for(var i=10; i<1000000; i++){ name = people[Math.floor(Math.random()*people.length)]; user_id = i; boolean = [true, false][Math.floor(Math.random()*2)]; added_at = new Date(); number = Math.floor(Math.random()*10001); db.test_collection1.save({"name":name, "user_id":user_id, "boolean": boolean, "added_at":added_at, "number":number }); }; print("insert End: "+Date());//写入结束时间 db.test_collection.ensureIndex({user_id:1}); print("find begin: "+Date());//查询开始时间 var i=0; var tempResult=null; while(i<100000){ i=i+1; tempResult=db.test_collection.findOne({"user_id":Math.floor(Math.random()*1000000)}); }; print("find end: " + Date());//查询结束时间 print("game over");//最后一行,保证上一行执行
参照《10分钟配置MongoDB集群》 ,本人笔记本电脑(4G内存)上性能测试结果如下:
insert begin: Mon Dec 24 2012 15:06:26 GMT+0800
insert End: Mon Dec 24 2012 15:10:14 GMT+0800
find begin: Mon Dec 24 2012 15:10:14 GMT+0800
find end: Mon Dec 24 2012 15:10:37 GMT+0800
大概就是平均一秒钟写入400多条,创建索引速度极快,使用索引平均每秒查询3500多条。写性能慢不觉得奇怪,毕竟是一台普通的笔记本电脑上配了一个集群呢。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。