Why Is MongoDB So Fast

2020-02-16 08:00发布

I was showing my co-worker performance benchmarks of MongoDB vs SQL 2008 and while he believes MongoDB is faster, he doesn't understand how its possible. His logic, was that SQL has been around for decades, and has some of the smartest people working on it, and how can MongoDB; a relatively new kid on the block be so superior in performance? I wasn't able to really provide a solid and technical answer, and I was hoping you guys could assist.

标签: mongodb
9条回答
【Aperson】
2楼-- · 2020-02-16 08:26

MongoDB isn't like a traditional relational database. It's noSQL or document based, it provides weak consistency guarantees, and it doesn't have to guarantee consistency like SQL.

查看更多
祖国的老花朵
3楼-- · 2020-02-16 08:30

As it has been mentioned MongoDB isn't created and shouldn't be used the same as a SQL database. SQL (and other relational databased) store relational data, that is that data in table X can be set up to have direct relations to information in table Y. MongoDB doesn't have this ability, and can therefore drop a lot of overhead. Hence why MongoDB is usually used to store lists, not relations.

Add in the fact that it isn't not quite ACID compliant yet (though it has taken large strides since it was first introduced) and that's the bulk of the speed differences.

Here are the differences outlined on the actual site between a full transactional model and their model.

In practice, the non-transactional model of MongoDB has the following implications:

  • No rollbacks. Your code must function without rollbacks. Check all programmatic conditions before performing the first database write operation. Order your write operations such that the most important operation occurs last.
  • Explicit locking. Your code may explicitly lock objects when performing operations. Thus, the application programmer has the capability to ensure "serializability" when required. Locking functionality will be available in late alpha / early beta release of MongoDB.
  • Database check on startup. Should the database abnormal terminate (rare), a database check procedure will automatically run on startup (similar to fschk).
查看更多
霸刀☆藐视天下
4楼-- · 2020-02-16 08:34

SQL has to do quite a lot, Mongo just has to drop bits onto disk (almost)

查看更多
登录 后发表回答