为什么 MongoDB 比 SQL DB 快得多的任何详细和具体原因? [英] Any detailed and specific reasons for Why MongoDB is much faster than SQL DBs?

查看:12
本文介绍了为什么 MongoDB 比 SQL DB 快得多的任何详细和具体原因?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,关于为什么MongoDB这么快

我很欣赏这些答案,但是,它们很笼统.是的,我知道:

I appreciate those answers, however, they are quite general. Yes, I know:

  • MongoDB 是基于文档的,那么为什么基于文档会导致更高的速度?
  • MongoDB 是 noSQL,但为什么 noSQL 意味着更高的性能?
  • SQL 在一致性、ACID 等方面比 MongoDB 做得更多,但我相信 MongoDB 也在做类似的事情来保证数据安全、维护索引等,对吧?

好的,我写这个问题只是为了找出答案

Ok, I write this question just in order to find out

  1. 详细和具体的原因是什么 MongoDB 的高性能?
  2. 究竟SQL做了什么,而MongoDB却没有,所以它获得了非常高的性能?
  3. 如果面试官(MongoDB 和 SQL 专家)问你为什么 MongoDB 这么快",你会怎么回答?显然只是回答:因为 MongoDB is noSQL" 是不够的.
  1. what are the detailed and specific reasons for MongoDB's high performance?
  2. What exactly SQL does, but MongoDB does not do, so it gains very high performance?
  3. If an interviewer (a MongoDB and SQL expert) asks you "Why MongoDB is so fast", how would you answer? Obviously just answering: "because MongoDB is noSQL" is not enough.

谢谢

推荐答案

首先我们来比较一下苹果和苹果: MongoDB的读写就像一张表的主键单次读写,没有非集群RDBMS 中的索引.

First, let's compare apples with apples: Reads and writes with MongoDB are like single reads and writes by primary key on a table with no non-clustered indexes in an RDBMS.

所以让我们准确地进行基准测试:http://mysqlha.blogspot.de/2010/09/mysql-versus-mongodb-yet-another-silly.html

So lets benchmark exactly that: http://mysqlha.blogspot.de/2010/09/mysql-versus-mongodb-yet-another-silly.html

事实证明,完全相同的原始操作的公平比较中的速度差异并不大.事实上,MySQL 稍微快一点.我会说,它们是等价的.

And it turns out, the speed difference in a fair comparison of exactly the same primitive operation is not big. In fact, MySQL is slightly faster. I'd say, they are equivalent.

为什么?因为实际上,两个系统在这个特定的基准测试中都在做类似的事情.返回单行,按主键搜索,实际上并没有那么多工作.这是一个非常快速的操作.我怀疑跨进程通信开销是其中很大一部分.

Why? Because actually, both systems are doing similar things in this particular benchmark. Returning a single row, searched by primary key, is actually not that much work. It is a very fast operation. I suspect that cross-process communication overheads are a big part of it.

我的猜测是,MySQL 中更优化的代码比 MongoDB 的系统开销略少(没有逻辑锁,可能还有其他一些小东西).

My guess is, that the more tuned code in MySQL outweighs the slightly less systematic overheads of MongoDB (no logical locks and probably some other small things).

由此得出一个有趣的结论:您可以像使用文档数据库一样使用 MySQL,并从中获得出色的性能.

This leads to an interesting conclusion: You can use MySQL like a document database and get excellent performance out of it.

如果面试官说:我们不关心文档或样式,我们只需要一个更快的数据库,你认为我们应该使用 MySQL 还是 MongoDB?",我会怎么回答?

If the interviewer said: "We don't care about documents or styles, we just need a much faster database, do you think we should use MySQL or MongoDB?", what would I answer?

我建议暂时忽略性能,看看这两个系统的相对强度.对于 MongoDB,我想到了诸如扩展(向上)和复制之类的事情.对于 MySQL,还有更多功能,例如丰富的查询、并发模型、更好的工具和成熟度等等.

I'd recommend to disregard performance for a moment and look at the relative strength of the two systems. Things like scaling (way up) and replication come to mind for MongoDB. For MySQL, there are a lot more features like rich queries, concurrency models, better tooling and maturity and lots more.

基本上,您可以用功能换取性能.愿意这样做吗?这是一般人无法做出的选择.如果您不惜一切代价选择性能,请考虑在添加其他技术之前先调整 MySQL.

Basically, you can trade features for performance. Are willing to do that? That is a choice that cannot be made generally. If you opt for performance at any cost, consider tuning MySQL first before adding another technology.

当客户端通过主键检索单个行/文档时会发生以下情况.我将注释两个系统之间的差异:

Here is what happens when a client retrieves a single row/document by primary key. I'll annotate the differences between both systems:

  1. 客户端构建二进制命令(同)
  2. 客户端通过 TCP 发送(相同)
  3. 服务器解析命令(同)
  4. 服务器从缓存中访问查询计划(仅限 SQL,不是 MongoDB,不是 HandlerSocket)
  5. 服务器要求 B-Tree 组件访问该行(相同)
  6. 服务器在通向行的 B-Tree 路径上采用物理只读锁(相同)
  7. 服务器对行进行逻辑锁定(仅限 SQL,不是 MongoDB,不是 HandlerSocket)
  8. 服务器序列化该行并通过 TCP 发送(相同)
  9. 客户端反序列化(相同)

对于典型的基于 SQL 的 RDBMS,只有两个额外的步骤.这就是为什么没有真正的区别.

There are only two additional steps for typical SQL-bases RDBMS'es. That's why there isn't really a difference.

这篇关于为什么 MongoDB 比 SQL DB 快得多的任何详细和具体原因?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆