MongoDB 1000W級資料 Insert和Query和Delete效能測試(分別測試 不加索引 和 加索引)
先看下測試機效能(64bit):
- ^_^[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 <iostream>
- #include <mongo/client/dbclient.h>
- 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:"<<time2.tv_sec-time1.tv_sec<<":"<<time2.tv_usec-time1.tv_usec<<endl;
-
- int main() {
- srand(time(NULL));
- char ar[26+1];
- DBClientConnection conn;
- conn.connect("localhost");
- cout<<"MongoDB Connected OK!"<<endl;
- 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"<<ar);
- 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<bat.js
- 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
......................# MongoDB 不加索引 1000W條刪除測試 #...................
- ^_^[root@:/usr/local/mongodb/bin]#./mongo 10.7.3.228 < bat.js
- MongoDB shell version: 1.8.2
- connecting to: 10.7.3.228/test
- > var startTime = new Date();
- > //db.users.find({NewsId:"csgsqdglbyfuwdjfkkrxgzyacc"});
- > db.users.remove()
- > (new Date().getTime()-startTime.getTime())/1000
- 103.924
- > bye
......................# MongoDB 不加索引 1000W條刪除最後一條測試 #...................
- ^_^[root@:/usr/local/mongodb/bin]#./mongo 10.7.3.228 < bat.js
- MongoDB shell version: 1.8.2
- connecting to: 10.7.3.228/test
- > var startTime = new Date();
- > //db.users.find({NewsId:"csgsqdglbyfuwdjfkkrxgzyacc"});
- > db.users.remove({"NewsId":"nmffcewwjvbhjfyagfxlifgiud"})
- > (new Date().getTime()-startTime.getTime())/1000
- 3.991
- > bye