RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
MongoDB性能测试代码

写入100万条记录,建立索引,使用索引连续查询 10万次。

十载的北海街道网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都全网营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整北海街道建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联从事“北海街道网站设计”,“北海街道网站推广”以来,每个客户项目都认真落实执行。

  1. use admin;//连接资料库 
  2. db.auth("mongoAdmin","123456");//登录 
  3. use test;//连接测试库 
  4. db.test_collection.dropIndexes();  
  5. db.test_collection.drop();  
  6. print("insert begin: "+Date());//写入开始时间 
  7. people = ["Marc", "Bill", "George", "Eliot", "Matt", "Trey", "Tracy", "Greg", "Steve", "Kristina", "Katie", "Jeff"];  
  8. for(var i=10; i<1000000; i++){  
  9.     name = people[Math.floor(Math.random()*people.length)];  
  10.     user_id = i;  
  11.     boolean = [true, false][Math.floor(Math.random()*2)];  
  12.     added_at = new Date();  
  13.     number = Math.floor(Math.random()*10001);  
  14.     db.test_collection1.save({"name":name, "user_id":user_id, "boolean": boolean, "added_at":added_at, "number":number });  
  15. };  
  16. print("insert End: "+Date());//写入结束时间 
  17. db.test_collection.ensureIndex({user_id:1});  
  18. print("find begin: "+Date());//查询开始时间 
  19. var i=0;  
  20. var tempResult=null;  
  21. while(i<100000){  
  22.     i=i+1;  
  23.     tempResult=db.test_collection.findOne({"user_id":Math.floor(Math.random()*1000000)});  
  24. };  
  25. print("find end: " + Date());//查询结束时间 
  26. 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多条。写性能慢不觉得奇怪,毕竟是一台普通的笔记本电脑上配了一个集群呢。


标题名称:MongoDB性能测试代码
本文地址:http://sczitong.cn/article/pejioo.html