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条回答
The star\"
2楼-- · 2020-02-16 08:14

While the other answers are interesting I would add that one of the reasons MongoDB is "so fast", at least in benchmarks, is the write concern.

You can read more about the different write concerns here but basically you can define the level of "security" you want when writing data.

The default level used to be unacknowledged, which means the write operation is just triggered but the driver does not check if it performed successfully. It is faster, but way less reliable.

They changed it about one year ago to acknowledged. But I guess most of the benchmarks out there still use the 'unacknowledged` mode for better results.

If you want to see the difference in term of performance, you can check this article (a bit old but it still gives an idea).

查看更多
做个烂人
3楼-- · 2020-02-16 08:17

MongoDB is fast because:

  1. Not ACID and availability is given preference over consistency.
  2. Asynchronous insert and update: What it means is MongoDB doesn't insert data to DB as soon as insert query is processed. Same is true for updates.
  3. No Joins overhead: When they say MongoDB is a document database, what they mean is a database that contains data that is self sufficient and all the information is embedded like a real document.
查看更多
Emotional °昔
4楼-- · 2020-02-16 08:19

MongoDB is fast because its web scale!

Its a fun video and well worth everyone watching, but it does answer your question - that most of the noSQL engines like MongoDB are not robust and not resilient to crashes and other outages. This security is what they sacrifice to gain speed.

查看更多
SAY GOODBYE
5楼-- · 2020-02-16 08:20

MongoDb is faster because: 1. No transactions; 2. No relations between tables;

If you will try to do exact the same logic on SQL server, for example : 1. Do not use Select with locks ; 2. No relations between tables; It will not be so big gap in speed between SQL Server and MongoDB. Only one place definitely will be faster , write and update records, because SQL doing insert and update table in the queue and in a transaction, on MondoDB it happens asynchronously. In my projections I could not gain any big differences in speed between SQL SERVER and MongoDB, because business logic was very similar between 2 projects. Real speed gain on MongoDb you can get on Analytical projects with bid data, or on big content management engines, like news papers, online stores and etc. Again no optimization on MongoDB and good optimization on SQL server can make these databases almost equal.

查看更多
混吃等死
6楼-- · 2020-02-16 08:22

I will also add that another difference is less about speed and more about conceptualization (although I believe that it might help with speed because there is less room for joining issues) is the document-based storage is very similar to object oriented mindset.

The document-based might not be perfectly ACID, but I believe MongoDB is easier to get what you want by just getting the whole document rather than messing with all the joins of a SQL DB, risking some bad joins as well.

Apologies to any SQL die-hard fans.

查看更多
够拽才男人
7楼-- · 2020-02-16 08:24

Mongo's not ACID compliant, so it doesn't have to deal with nearly as much "cruft" to make sure that what you try to put into the DB can come back out again later.

If you don't mind losing some functionality and possibly losing data in exchange for speed, then Mongo's good. If you absolutely need to guarantee data integrity and/or have complex join requirements, then avoid Mongo-type systems like the plague.

查看更多
登录 后发表回答