MongoDB-level data Insert, Query, and Delete performance tests (without or without indexing)
Let's take a look at the testing machine performance (64bit ):
- Performance_^ [root @: ~] # Grep"Model name"/Proc/cpuinfo | cut-f2-d:
- Intel (R) Xeon (R) CPU E5606 @ 2.13 GHz
- Intel (R) Xeon (R) CPU E5606 @ 2.13 GHz
- Intel (R) Xeon (R) CPU E5606 @ 2.13 GHz
- Intel (R) Xeon (R) CPU E5606 @ 2.13 GHz
- Intel (R) Xeon (R) CPU E5606 @ 2.13 GHz
- Intel (R) Xeon (R) CPU E5606 @ 2.13 GHz
- Intel (R) Xeon (R) CPU E5606 @ 2.13 GHz
- Intel (R) Xeon (R) CPU E5606 @ 2.13 GHz
- Performance_^ [root @: ~] # Grep MemTotal/proc/meminfo
- MemTotal: 4040580 kB
- Performance_^ [root @: ~] # Free-m
- Total used free shared buffers cached
- Mem: 3945 3715 230 0 40 2626
- -/+ Buffers/cache: 1048 2897
- Swap: 4094 2 4092
- Performance_^ [root @: ~] # Getconf LONG_BIT
- 64
- Performance_^ [root @: ~] # More/etc/RedHat-release
- Red Hat Enterprise Linux Server release 5.5 (Tikanga)
- Performance_^ [root @: ~] # Uname-r
- 2.6.18-194. el5
Test procedure:
- # Include <iostream>
- # Include <mongo/client/dbclient. h>
- Using NamespaceStd;
- Using NamespaceMongo;
-
- # Define INIT_TIME \
- StructTimeval 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;
-
- IntMain (){
- Srand (time (NULL ));
- CharAr [26 + 1];
- DBClientConnection conn;
- Conn. connect ("Localhost");
- Cout <"MongoDB Connected OK! "<Endl;
- IntCount = 10000000;
- INIT_TIME;
- START_TIME;
- // Insert
- # If 1
- While(Count --){
- For(IntI = 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;
- Return0;
- }
Test without adding an index:
...................... # MongoDB inserts data records without indexing #...................
- Pai_^ [root @:~ /Svn/nugget/MongoDB/utest] #./insertData
- MongoDB Connected OK!
- Time: 207 s: 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 entry isDgvshdhevmjgunvbepgdkzirqk
Test procedure:
- Pai_^ [root @:/usr/local/mongodb/bin] #./mongo <bat. js
- MongoDB shell version: 1.8.2
- Connecting to: test
- > Var startTime =NewDate ();
- >
- > Db. users. find ({NewsId:"Dgvshdhevmjgunvbepgdkzirqk"});
- {"_ Id": ObjectId ("4e2ccfd2a1ca039d82527b34"),"NewsId":"Dgvshdhevmjgunvbepgdkzirqk"}
- >
- > (NewDate (). getTime ()-startTime. getTime ()/1000
- 5.846 s
- > Bye
...................... # MongoDB deletion test without indexing entries #...................
- Pai_^ [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 =NewDate ();
- >// Db. users. find ({NewsId: "csgsqdglbyfuwdjfkkrxgzyacc "});
- > Db. users. remove ()
- > (NewDate (). getTime ()-startTime. getTime ()/1000
- 103.924
- > Bye
...................... # Delete the last test without adding indexes to MongoDB #...................
- Pai_^ [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 =NewDate ();
- >// Db. users. find ({NewsId: "csgsqdglbyfuwdjfkkrxgzyacc "});
- > Db. users. remove ({"NewsId":"Nmffcewwjvbhjfyagfxlifgiud"})
- > (NewDate (). getTime ()-startTime. getTime ()/1000
- 3.991
- > Bye