MongoDB-level data Insert, Query, and Delete performance tests

Source: Internet
Author: User

MongoDB-level data Insert, Query, and Delete performance tests (without or without indexing)

Let's take a look at the testing machine performance (64bit ):

  1. Performance_^ [root @: ~] # Grep"Model name"/Proc/cpuinfo | cut-f2-d:
  2. Intel (R) Xeon (R) CPU E5606 @ 2.13 GHz
  3. Intel (R) Xeon (R) CPU E5606 @ 2.13 GHz
  4. Intel (R) Xeon (R) CPU E5606 @ 2.13 GHz
  5. Intel (R) Xeon (R) CPU E5606 @ 2.13 GHz
  6. Intel (R) Xeon (R) CPU E5606 @ 2.13 GHz
  7. Intel (R) Xeon (R) CPU E5606 @ 2.13 GHz
  8. Intel (R) Xeon (R) CPU E5606 @ 2.13 GHz
  9. Intel (R) Xeon (R) CPU E5606 @ 2.13 GHz
  10. Performance_^ [root @: ~] # Grep MemTotal/proc/meminfo
  11. MemTotal: 4040580 kB
  12. Performance_^ [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. Performance_^ [root @: ~] # Getconf LONG_BIT
  18. 64
  19. Performance_^ [root @: ~] # More/etc/RedHat-release
  20. Red Hat Enterprise Linux Server release 5.5 (Tikanga)
  21. Performance_^ [root @: ~] # Uname-r
  22. 2.6.18-194. el5

Test procedure:

  1. # Include <iostream>
  2. # Include <mongo/client/dbclient. h>
  3. Using NamespaceStd;
  4. Using NamespaceMongo;
  5. # Define INIT_TIME \
  6. StructTimeval time1, time2 ;\
  7. # Define START_TIME \
  8. Gettimeofday (& time1, NULL );\
  9. # Define STOP_TIME \
  10. Gettimeofday (& time2, NULL );\
  11. # Define PRINT_TIME \
  12. Cout <"Time :"<Time2. TV _ sec-time1. TV _sec <":"<Time2. TV _ usec-time1. TV _usec <endl;
  13. IntMain (){
  14. Srand (time (NULL ));
  15. CharAr [26 + 1];
  16. DBClientConnection conn;
  17. Conn. connect ("Localhost");
  18. Cout <"MongoDB Connected OK! "<Endl;
  19. IntCount = 10000000;
  20. INIT_TIME;
  21. START_TIME;
  22. // Insert
  23. # If 1
  24. While(Count --){
  25. For(IntI = 0; I <26; I ++ ){
  26. Ar [I] = rand () % 26 + 97;
  27. }
  28. Ar [26] ='\ 0';
  29. BSONObj p = BSON ("NewsId"<Ar );
  30. Conn. insert ("Test. users", P );
  31. }
  32. # Endif
  33. STOP_TIME;
  34. PRINT_TIME;
  35. Return0;
  36. }

Test without adding an index:

...................... # MongoDB inserts data records without indexing #...................

  1. Pai_^ [root @:~ /Svn/nugget/MongoDB/utest] #./insertData
  2. MongoDB Connected OK!
  3. 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:

  1. > Db. users. find (). sort ({'_ Id':-1 })
  2. {"_ Id": ObjectId ("4e2cbdf4a1ca039d82214e33"),"NewsId":"Dgvshdhevmjgunvbepgdkzirqk"}

The NewsId of the first data entry isDgvshdhevmjgunvbepgdkzirqk

Test procedure:

  1. Pai_^ [root @:/usr/local/mongodb/bin] #./mongo <bat. js
  2. MongoDB shell version: 1.8.2
  3. Connecting to: test
  4. > Var startTime =NewDate ();
  5. >
  6. > Db. users. find ({NewsId:"Dgvshdhevmjgunvbepgdkzirqk"});
  7. {"_ Id": ObjectId ("4e2ccfd2a1ca039d82527b34"),"NewsId":"Dgvshdhevmjgunvbepgdkzirqk"}
  8. >
  9. > (NewDate (). getTime ()-startTime. getTime ()/1000
  10. 5.846 s
  11. > Bye

...................... # MongoDB deletion test without indexing entries #...................

  1. Pai_^ [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 =NewDate ();
  5. >// Db. users. find ({NewsId: "csgsqdglbyfuwdjfkkrxgzyacc "});
  6. > Db. users. remove ()
  7. > (NewDate (). getTime ()-startTime. getTime ()/1000
  8. 103.924
  9. > Bye

...................... # Delete the last test without adding indexes to MongoDB #...................

  1. Pai_^ [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 =NewDate ();
  5. >// Db. users. find ({NewsId: "csgsqdglbyfuwdjfkkrxgzyacc "});
  6. > Db. users. remove ({"NewsId":"Nmffcewwjvbhjfyagfxlifgiud"})
  7. > (NewDate (). getTime ()-startTime. getTime ()/1000
  8. 3.991
  9. > Bye
  • 1
  • 2
  • Next Page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.