Any detailed and specific reasons for why MongoDB is much faster than SQL DB?

Ok, there are questions about why MongoDB is so fast

I appreciate these answers, however they are pretty general. Yes I know:

  • MongoDB is document-based, so why can document-based much faster speeds?
  • MongoDB is noSQL, but why does noSQL mean better performance?
  • SQL does a lot more than MongoDB for consistency, ACID, etc., but I believe MongoDB also does something similar to keep data safe, maintain indexing, etc., right?

Okay, I am writing this question just to find out

  • What are the detailed and specific reasons for MongoDB's high performance?
  • What exactly does SQL do, but MongoDB does not, so it gets very high performance?
  • If the interviewer (MongoDB and SQL expert) asks you "Why MongoDB is so fast" , how would you answer? Obviously, simply answering: "because MongoDB is noSQL" not enough.

thank

+30
performance sql mongodb nosql
Jun 28 '12 at 12:21
source share
3 answers

First, compare apples to apples: Reading and writing with MongoDB is like reading and writing by primary key once in a table without non-clustered indexes in an RDBMS.

So let's compare this: http://mysqlha.blogspot.de/2010/09/mysql-versus-mongodb-yet-another-silly.html

And it turns out that the difference in speed in a fair comparison of the exact same primitive operation is small. MySQL is actually a little faster. I would say that they are equivalent.

Why? Because in fact, both systems do similar things in this particular test. Returning a single row, searching by primary key, actually doesnโ€™t work that much. This is a very fast operation. I suspect that the overhead of interprocess communication is a significant part of it.

I assume that the more customizable code in MySQL outweighs the slightly less systematic overhead of MongoDB (without logical locks and possibly some other small things).

This leads to an interesting conclusion: You can use MySQL as a document database and get excellent performance.




If the interviewer said: โ€œWe donโ€™t need documents or styles, we just need a much faster database, do you think we should use MySQL or MongoDB?โ€, What would I answer?

I would recommend briefly ignoring performance and looking at the relative strength of the two systems. Things like scaling (way up) and replication are reminiscent of MongoDB. For MySQL, there are many more features, such as rich queries, concurrency models, advanced snap-in and maturity, and much more.

Basically, you can trade features for performance. Are you ready to do this? This is a choice that cannot be made at all. If you choose performance at all costs, consider tuning MySQL before adding another technology.




This is what happens when a client retrieves a single line / document using a primary key. I will comment on the differences between both systems:

  • Client creates a binary command (same)
  • The client sends it over TCP (same)
  • The server parses the command (same)
  • The server accesses the query plan from the cache (only SQL, not MongoDB, not HandlerSocket)
  • The server requests a B-Tree component to access the row (same)
  • Server accepts readonly physical lock on B-Tree path leading to row (same)
  • The server accepts a logical lock in the string (only SQL, not MongoDB, not HandlerSocket)
  • The server serializes the string and sends it over TCP (same)
  • Client deserializes it (same)

There are only two additional steps for typical RDBMS SQL databases. That is why there really is no difference.

+28
Jun 28 '12 at 12:29
source share

In general, MySQL and MongoDB are very similar to the "robust" write performance on the same machine. Simple searches for keys / values โ€‹โ€‹are almost the same ... if you want to use MySQL in this way. Obviously, document support is a big productivity and a big victory in productivity.

With an automatic window ... MongoDB is faster indescribable. Out of the box, with the right design, you can scale almost linearly without creating any logic in your code at all.

Read / write separation is also built into almost every driver ... which, most, is sponsored or developed by 10gen itself.

I already scaled the applications to and wrote down the read / write separation code, distributed the hashes for sharding, constantly restyling the tasks, and added gzip to the mysql โ€œdocumentโ€ repositories. pah.

It is faster because it is simple and focused. It is designed with all this in mind. The scale of commercial equipment is a priority. The priorities of the RDBMS are completely different.

+5
Mar 06 '13 at 9:18
source share

By default, mongo does not index; also no transactions. however, if you configure the mysql table without indexing and enable auto-messaging, you will not see a huge difference in speed. writing bits to disk takes some time.

however, mongo is designed to be easy to scale. using shards, you can scale your records horizontally and get much better performance without the replication complexity of a master. Using replica sets, you can scale your readings horizontally. therefore, I would say that there is a systematic performance improvement, but each request is not necessarily faster.

+4
Jun 28 '12 at 12:33
source share



All Articles