MongoDB性能テストコード


100万件のレコードを書き込み、インデックスを作成し、インデックスを使用して10万回連続してクエリーします.
   
   
   
   
  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 = [truefalse][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クラスタを構成する』参照 ,本人のノートパソコン(4 Gメモリ)の性能テストの結果は以下の通りです.
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
およそ1秒あたり400件以上の書き込みがあり、インデックスの作成速度が非常に速く、インデックスを使用して1秒あたり3500件以上のクエリがあります.書くのが遅いのは不思議ではありませんが、普通のノートパソコンにクラスタが付いていますね.