Reputation: 19
It is my first Stackoverflow question but I'm long time reader.
I'm working on some home project and I tried to compare the speed of MongoDB and MySQL. Suprisingly.. MongoDB is almost 5 times slower even with very basic table? I was reading that they are almost the same speed but it got me thinking.
Can someone explain to me why is this happening?
The MongoDB code:
app.get('/mongodb', function(req, res, next) {
var time = process.hrtime();
User.find(function(err, users) {
if (err) return next(err);
var diff = process.hrtime(time);
if(diff[0] == 0) {
res.send(diff[1].toString());
} else {
res.send(diff[0]+"."+diff[1]);
}
});
});
The MySQL code:
app.get('/mysql', function(req, res, next) {
var time = process.hrtime();
mysql.query("SELECT * FROM users", function(err, results) {
if (err) throw err;
var diff = process.hrtime(time);
if(diff[0] == 0) {
res.send(diff[1].toString());
} else {
res.send(diff[0]+"."+diff[1]);
}
});
});
MySQL returns: 1.52201348
MongoDB returns: 9.746405351
Schema is:
User {
id integer,
name string,
email string,
}
There are around 500000 of Users.
Index is on _id in MongoDB and id in MySQL.
MongoDB shell version: 2.4.6
MySQL version: 5.5.37
Any ideas? Any help or suggestions will be much appreciated.
Regards, Wnzl.
Upvotes: 1
Views: 94
Reputation: 31
I think the main problem here is that benchmarking should always be done with respect to a special use case. The assumption, that they perfom with same speed is pretty unspecific.
So the use case you examine here is defined by your example and means getting all entities of a schema. Even if the use case is pretty simple, the meaningfulness of your result won't be.
MongoDB and SQL are database systems designed for different use cases. This means that each system is optimized for different queries. This is where I think you should dig deeper to get the reason for different performances.
Also take into account, that based on hat, querying all entity's of one schema, perhaps could be realized with multiple but in total faster queries. Last think about bootstrap, caching and indexing mechanisms that may be total different due to optimizations to system specific use cases.
Upvotes: 1