| Testing MongoDB vs. MySQL with python scripting under Linux |
|
|
|
| Written by Martino Vedana | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Tuesday, 11 January 2011 00:00 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Today I'm pygoing to test two DBMS to understand which is the faster and how much in some specific cases. The focus is on simple read, write and delete of a different amount of data. This is useful to evaluate if in a project which DBMS to use or if is better to use different DBMS's to cover different areas. I'm going to test Oracle's MySQL and mongoDB. Why these Databases? Because the first one is the most used in small/medium web environments (and also is used in large installations like Facebook) and today can be defined the “base comparsion” to evaluate other DBMS. The second one is the most attractive DBMS in terms of popularity (the community is growing), performances (seems to be much more faster than other Relational DBMS) and features (like GridFS). Let's take a look to what Wikipedia says about our two comers: MongoDB (from "humongous") is an open source, scalable, high-performance, schema-free, document-oriented database written in the C++ programming language. MongoDB combines the functionality of key-value stores - which are fast and highly scalable - and traditional RDBMS systems - which provide rich queries and deep functionality. It is designed for problems that are difficult to be solved by traditional RDBMs, for example databases spanning many servers. The database is document-oriented so it manages collections of JSON-like documents. Many applications can, thus, model data in a more natural way, as data can be nested in complex hierarchies and still be query-able and indexable. Development of MongoDB began in October 2007 by 10gen. The first public release was in February 2009. MySQL is a relational database management system (RDBMS) that runs as a server providing multi-user access to a number of databases. MySQL is officially pronounced /maɪˌɛskjuːˈɛl/ ("My S-Q-L"), but is often also pronounced /maɪˈsiːkwəl/ ("My Sequel"). It is named after developer Michael Widenius' daughter, My. The SQL phrase stands for Structured Query Language. The MySQL development project has made its source code available under the terms of the GNU General Public License, as well as under a variety of proprietary agreements. MySQL was owned and sponsored by a single for-profit firm, the Swedish company MySQL AB, now owned by Oracle Corporation. Members of the MySQL community have created several forks (variations) such as Drizzle, OurDelta, Percona Server, and MariaDB. All of these forks were in progress before the Oracle acquisition; Drizzle was announced eight months before the Sun acquisition. Free-software projects that require a full-featured database management system often use MySQL. Where the project may lead to something in commercial use, the license terms need careful study. Some free software project examples: WordPress, phpBB, Drupal and other software built on the LAMP software stack. MySQL is also used in many high-profile, large-scale World Wide Web products, including Wikipedia, Google and Facebook. Let's Start!- What I'm testingWhat I want to test is the speed of mySQL DBMS vs, mongoDB during INSERT, DELETE or SEARCH statement of small values such as decimal numbers or strings (identified by numeric keys). The range of rows is 100 ~ 1.000.000 so that means the probably all the rows are store in ram. Anyway in the future I'll test larger tables (more than 1.000.000 values). Other target is to test the two DBMS using python (there's already a huge number of php/java tests done) I tried to have the same conditions when working with MySQL and mongoDB so I wrote two python scripts, one for MySQL and one for mongoDB with the same structure. Testing environment:Software:Python Python 2.6.6 PyMongo 01.07.00 MySQLdb 01.02.02 MySQL 5.1.49-1ubuntu8.1 MongoDB 1:1.4.4-2ubuntu2 Operating System: Ubuntu Linux kernel v.2.6.35-24 (32 bit) Hardware: Type : Intel® Core™2 Duo Processor T6600 Speed : 2.20GHz FSB : 800MHz Cache : 2MB L2 cache RAM: 4GB (2 x 2GB) DDR3 1066 SDRAM The testing scriptsThe test core script insert, search and then delete 1000, 10.000, 100.000 and 1.000.000 values.Note that the search part is a sequence of 5 search on a random key and the final value is an average between the five results. The connections libraies are: PyMongo v. 01.07.00 for MongoDB and MySQLdb v. 01.02.02 for MySQL Tables structureMysql structure:CREATE TABLE IF NOT EXISTS `test` ( `k` varchar(25) NOT NULL, `v` varchar(25) NOT NULL, PRIMARY KEY (`k`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; Mysql core scriptdef DeleteAll(self): Download the complete script clicking below mongoDB core script# generic insert functionDownload the complete script clicking below ResultsLet's start with MySQL results: As you can see this table shows you the sec. needed to perform insertion, deleting or search on 100,1.000,10.000, 100.000 and 1.000.000 rows
And now the results of mongoDB test:
As you can easily see in the results mongoDB is always much more faster than mySQL. In only one case mySQL is more or less equal to mongoDB: deleting of 100 rows. In all other cases mongodb is from 1,5 to 6000 times faster!!! Lets see a comparsion table (how many times MongoDB was faster than MySQL):
This means that for example inserting 100.000 rows in mongoDB is 1,30 times faster than in MySQL. The more shocking result is that searching 1 key in a table containing 1.000.000 rows (indexed) is 6.677 times faster with mongoDB than mySQL in this environment. I executed the same test on other testing machine and this value has changed a bit from 4000 to 7000 times faster. In my opinion is not a matter of 7.000 or 1.000; the key point is that we have a result with three zeros: thousands times faster! Let's see graphically the three cases: ![]() ![]() ![]() What can I say? Fast, fast and again: fast; mongoDB is in all cases faster than MySQL. Non relational DBMS were born to be faster than relational DBMSs and this goal was reached by mongoDB! If you have notes, points to improve you can leave a note to continue the discussion about this test Thanks to Flavio and Angel for supporting me during testing activities! ¡Gracias Amigos! |





Today I'm pygoing to test two DBMS to understand which is the faster and how much in some specific cases. The focus is on simple read, write and delete of a different amount of data. 

