MongoDB 1000W級資料 Insert和Query和Delete效能測試

來源:互聯網
上載者:User

MongoDB 1000W級資料 Insert和Query和Delete效能測試(分別測試 不加索引 和 加索引)

先看下測試機效能(64bit):

  1. ^_^[root@:~]#grep "model name" /proc/cpuinfo | cut -f2 -d:  
  2.  Intel(R) Xeon(R) CPU           E5606  @ 2.13GHz  
  3.  Intel(R) Xeon(R) CPU           E5606  @ 2.13GHz  
  4.  Intel(R) Xeon(R) CPU           E5606  @ 2.13GHz  
  5.  Intel(R) Xeon(R) CPU           E5606  @ 2.13GHz  
  6.  Intel(R) Xeon(R) CPU           E5606  @ 2.13GHz  
  7.  Intel(R) Xeon(R) CPU           E5606  @ 2.13GHz  
  8.  Intel(R) Xeon(R) CPU           E5606  @ 2.13GHz  
  9.  Intel(R) Xeon(R) CPU           E5606  @ 2.13GHz  
  10. ^_^[root@:~]#grep MemTotal /proc/meminfo  
  11. MemTotal:      4040580 kB  
  12. ^_^[root@:~]# free -m  
  13.              total       used       free     shared    buffers     cached  
  14. Mem:          3945       3715        230          0         40       2626  
  15. -/+ buffers/cache:       1048       2897  
  16. Swap:         4094          2       4092  
  17. ^_^[root@:~]#getconf LONG_BIT  
  18. 64  
  19. ^_^[root@:~]#more /etc/RedHat-release  
  20. Red Hat Enterprise Linux Server release 5.5 (Tikanga)  
  21. ^_^[root@:~]#uname -r  
  22. 2.6.18-194.el5  

測試程式:

  1. #include <iostream>   
  2. #include <mongo/client/dbclient.h>   
  3. using namespace std;  
  4. using namespace mongo;  
  5.   
  6. #define INIT_TIME \   
  7.         struct timeval time1,time2; \  
  8.   
  9. #define START_TIME \   
  10.         gettimeofday(&time1,NULL); \  
  11.   
  12. #define STOP_TIME \   
  13.         gettimeofday(&time2,NULL); \  
  14.   
  15. #define PRINT_TIME \   
  16.         cout<<"Time:"<<time2.tv_sec-time1.tv_sec<<":"<<time2.tv_usec-time1.tv_usec<<endl;  
  17.   
  18. int main() {  
  19.         srand(time(NULL));  
  20.         char ar[26+1];  
  21.         DBClientConnection conn;  
  22.         conn.connect("localhost");  
  23.         cout<<"MongoDB Connected OK!"<<endl;  
  24.         int count=10000000;  
  25.         INIT_TIME;  
  26.         START_TIME;  
  27. //insert   
  28. #if 1   
  29.         while (count--) {  
  30.                 for (int i=0; i<26; i++) {  
  31.                         ar[i] = rand()%26+97;  
  32.                 }  
  33.                 ar[26]='\0';  
  34.                 BSONObj p = BSON("NewsId"<<ar);  
  35.                 conn.insert("test.users",p);  
  36.         }  
  37. #endif   
  38.   
  39.         STOP_TIME;  
  40.         PRINT_TIME;  
  41.         return 0;  
  42. }  

不加索引測試:

......................# MongoDB 不加索引 插入1000W條測試 #...................

  1. ^_^[root@:~/svn/nugget/MongoDB/utest]#./insertData                
  2. MongoDB Connected OK!  
  3. Time:207s:194125μs  

......................# MongoDB 不加索引 1000W條遍曆測試 #...................

我們讓MongoDB全部遍曆一遍:

讓測試資料倒序,取倒序後第一條資料:

  1. > db.users.find().sort({'_id':-1})  
  2. { "_id" : ObjectId("4e2cbdf4a1ca039d82214e33"), "NewsId" : "dgvshdhevmjgunvbepgdkzirqk" }  

第一條資料的NewsId為  dgvshdhevmjgunvbepgdkzirqk

測試程式:

  1. ^_^[root@:/usr/local/mongodb/bin]#./mongo<bat.js   
  2. MongoDB shell version: 1.8.2  
  3. connecting to: test  
  4. > var startTime = new Date();  
  5. >   
  6. > db.users.find({NewsId:"dgvshdhevmjgunvbepgdkzirqk"});  
  7. { "_id" : ObjectId("4e2ccfd2a1ca039d82527b34"), "NewsId" : "dgvshdhevmjgunvbepgdkzirqk" }  
  8. >   
  9. > (new Date().getTime()-startTime.getTime())/1000  
  10. 5.846s  
  11. > bye  

......................# MongoDB 不加索引 1000W條刪除測試 #...................

  1. ^_^[root@:/usr/local/mongodb/bin]#./mongo 10.7.3.228 < bat.js  
  2. MongoDB shell version: 1.8.2  
  3. connecting to: 10.7.3.228/test  
  4. > var startTime = new Date();    
  5. > //db.users.find({NewsId:"csgsqdglbyfuwdjfkkrxgzyacc"});     
  6. > db.users.remove()  
  7. > (new Date().getTime()-startTime.getTime())/1000   
  8. 103.924  
  9. > bye  

......................# MongoDB 不加索引 1000W條刪除最後一條測試 #...................

  1. ^_^[root@:/usr/local/mongodb/bin]#./mongo 10.7.3.228 < bat.js  
  2. MongoDB shell version: 1.8.2  
  3. connecting to: 10.7.3.228/test  
  4. > var startTime = new Date();    
  5. > //db.users.find({NewsId:"csgsqdglbyfuwdjfkkrxgzyacc"});     
  6. > db.users.remove({"NewsId":"nmffcewwjvbhjfyagfxlifgiud"})  
  7. > (new Date().getTime()-startTime.getTime())/1000   
  8. 3.991  
  9. > bye  
  • 1
  • 2
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.