Let's take a look at the testing machine performance (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/meminfoMemTotal: 4040580 kB^_^[root@:~]# free -m total used free shared buffers cachedMem: 3945 3715 230 0 40 2626-/+ buffers/cache: 1048 2897Swap: 4094 2 4092^_^[root@:~]#getconf LONG_BIT64^_^[root@:~]#more /etc/redhat-releaseRed Hat Enterprise Linux Server release 5.5 (Tikanga)^_^[root@:~]#uname -r2.6.18-194.el5
Test procedure:
#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;}
Test without adding an index:
...................... # MongoDB inserts data records without indexing #...................
^_^[root@:~/svn/nugget/MongoDB/utest]#./insertData MongoDB Connected OK!Time:207s:194125μs
...................... # MongoDB does not add an index of million traversal tests #...................
Let's traverse MongoDB all over again:
Put the test data in reverse order, and take the first data after reverse order:
> db.users.find().sort({'_id':-1}){ "_id" : ObjectId("4e2cbdf4a1ca039d82214e33"), "NewsId" : "dgvshdhevmjgunvbepgdkzirqk" }
The newsid of the first data is dgvshdhevmjgunvbepgdkzirqk.
Test procedure:
^_^[root@:/usr/local/mongodb/bin]#./mongo<bat.js MongoDB shell version: 1.8.2connecting to: test> var startTime = new Date();> > db.users.find({NewsId:"dgvshdhevmjgunvbepgdkzirqk"});{ "_id" : ObjectId("4e2ccfd2a1ca039d82527b34"), "NewsId" : "dgvshdhevmjgunvbepgdkzirqk" }> > (new Date().getTime()-startTime.getTime())/10005.846s> bye
...................... # MongoDB deletion test without indexing entries #...................
^_^[root@:/usr/local/mongodb/bin]#./mongo 10.7.3.228 < bat.jsMongoDB shell version: 1.8.2connecting 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
...................... # Delete the last test without adding indexes to MongoDB #...................
^_^[root@:/usr/local/mongodb/bin]#./mongo 10.7.3.228 < bat.jsMongoDB shell version: 1.8.2connecting 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
Index addition test:
> db.users.getIndexes()[ { "name" : "_id_", "ns" : "test.users", "key" : { "_id" : 1 }, "v" : 0 }]> db.users.ensureIndex({NewsId:1})> db.users.getIndexes() [ { "name" : "_id_", "ns" : "test.users", "key" : { "_id" : 1 }, "v" : 0 }, { "_id" : ObjectId("4e2cc408572ff09d98851cb7"), "ns" : "test.users", "key" : { "NewsId" : 1 }, "name" : "NewsId_1", "v" : 0 }]
...................... # MongoDB index insertion tests #...................
^_^[root@:~/svn/nugget/MongoDB/utest]#./insertData MongoDB Connected OK!Time:2019s:19419μs
...................... # MongoDB index tests #...................
Take the last piece of data, and then check the performance:
^_^[root@:/usr/local/mongodb/bin]#./mongo <bat.js MongoDB shell version: 1.8.2connecting to: test> var startTime = new Date();> > db.users.find({NewsId:"nxuvdqtjrrptoyildolesbkqmd"});{ "_id" : ObjectId("4e2ccc2ea1ca039d82b9e4b3"), "NewsId" : "nxuvdqtjrrptoyildolesbkqmd" }> > (new Date().getTime()-startTime.getTime())/10000.022s> bye
...................... # MongoDB index deletion tests #...................
^_^[root@:/usr/local/mongodb/bin]#./mongo 10.7.3.228 < bat.jsMongoDB shell version: 1.8.2connecting to: 10.7.3.228/test> var startTime = new Date(); > //db.users.find({NewsId:"csgsqdglbyfuwdjfkkrxgzyacc"}); > db.users.remove()> (new Date().getTime()-startTime.getTime())/1000 570.782> bye
...................... # Delete a test from MongoDB index #...................
^_^[root@:/usr/local/mongodb/bin]#./mongo 10.7.3.228 < bat.jsMongoDB shell version: 1.8.2connecting to: 10.7.3.228/test> var startTime = new Date(); > //db.users.find({NewsId:"csgsqdglbyfuwdjfkkrxgzyacc"}); > db.users.remove({"NewsId":"cikjwikamhtixoykrrfjnepkwu"})> (new Date().getTime()-startTime.getTime())/1000 0.025> bye
Summarize the test data:
No Index
Add 10 million records at time: 207 S: 194125 μs
Query 5.846 s
Delete all 103.94 s
Delete last 3.991 s
Indexed
Add 10 million records at time: 2019 S: 19419 μs
Query 0.022 s
Delete all 570.782 s
Delete last 0.025 s
Test MongoDB 1.6