database 主主与主从数据库架构?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3736969/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Master-master vs master-slave database architecture?
提问by never_had_a_name
I've heard about two kind of database architectures.
我听说过两种数据库架构。
master-master
master-slave
主-主
主从
Isn't the master-master more suitable for today's web cause it's like Git, every unit has the whole set of data and if one goes down, it doesn't quite matter.
master-master 是不是更适合今天的web,因为它就像Git,每个单元都有一整套数据,一个宕机也无所谓。
Master-slave reminds me of SVN (which I don't like) where you have one central unit that handles thing.
主从让我想起 SVN(我不喜欢),在那里你有一个处理事情的中央单元。
Questions:
问题:
What are the pros and cons of each?
If you want to have a local database in your mobile phone like iPhone, which one is more appropriate?
Is the choice of one of these a critical factor to consider thoroughly?
各自的优缺点是什么?
如果你想在你的手机中像 iPhone 一样拥有一个本地数据库,哪一个更合适?
选择其中一个是否是需要彻底考虑的关键因素?
采纳答案by djna
We're trading off availability, consistency and complexity. To address the last question first: Does this matter? Yes very much! The choices concerning how your data is to be managed is absolutely fundamental, and there's no "Best Practice" dodging the decisions. You need to understand your particular requirements.
我们正在权衡可用性、一致性和复杂性。先解决最后一个问题:这有关系吗?是的非常!关于如何管理您的数据的选择绝对是基本的,并且没有“最佳实践”可以回避这些决定。您需要了解您的特定要求。
There's a fundamental tension:
有一个基本的张力:
One copy: consistency is easy, but if it happens to be down everybody is out of the water, and if people are remote then may pay horrid communication costs. Bring portable devices, which may need to operate disconnected, into the picture and one copy won't cut it.
一个副本:一致性很容易,但如果它碰巧失败,每个人都无法承受,如果人们远离,那么可能会付出可怕的沟通成本。将可能需要断开连接的便携式设备带入图片中,一份副本不会剪切它。
Master Slave: consistency is not too difficult because each piece of data has exactly one owning master. But then what do you do if you can't see that master, some kind of postponed work is needed.
Master Slave:一致性不是太难,因为每条数据只有一个拥有主人。可那要是见不到那位师父怎么办呢,还得做些延期的工作。
Master-Master: well if you can make it work then it seems to offer everything, no single point of failure, everyone can work all the time. The trouble with this is that it is veryhard to preserve absolute consistency. See the wikipedia articlefor more.
Master-Master:嗯,如果你能做到,那么它似乎提供了一切,没有单点故障,每个人都可以一直工作。这个麻烦的是,这是非常难以保持绝对一致。有关更多信息,请参阅维基百科文章。
Wikipedia seems to have a nice summary of the advantages and disadvantages
维基百科似乎对优点和缺点有一个很好的总结
Advantages
If one master fails, other masters will continue to update the database.
Masters can be located in several physical sites i.e. distributed across the network.
Disadvantages
Most multi-master replication systems are only loosely consistent, i.e. lazy and asynchronous, violating ACID properties.
Eager replication systems are complex and introduce some communication latency.
Issues such as conflict resolution can become intractable as the number of nodes involved rises and the required latency decreases.
好处
如果一个 master 失败,其他 master 将继续更新数据库。
主站可以位于多个物理站点,即分布在整个网络中。
缺点
大多数多主复制系统只是松散一致的,即懒惰和异步,违反了 ACID 属性。
Eager 复制系统很复杂,并且会引入一些通信延迟。
随着所涉及节点数量的增加和所需的延迟减少,诸如冲突解决之类的问题可能变得棘手。
回答by Skillachie
While researching the various database architectures as well. I have compiled a good bit of information that might be relevant to someone else researching in the future. I came across
同时研究各种数据库架构。我已经汇编了很多信息,这些信息可能与其他人将来的研究有关。我碰到
- Master-Slave Replication
- Master-Master Replication
- MySQL Cluster
- 主从复制
- 主-主复制
- MySQL 集群
I have decided to settle for using MySQL Cluster for my use case. However please see below for the various pros and cons that I have compiled
我决定在我的用例中使用 MySQL Cluster。但是,请参阅下面的各种利弊
1. Master-Slave Replication
1.主从复制
Pros
优点
- Analytic applications can read from the slave(s) without impacting the master
- Backups of the entire database of relatively no impact on the master
- Slaves can be taken offline and sync back to the master without any downtime
- 分析应用程序可以在不影响主站的情况下从从站读取
- 整个数据库的备份对master比较没有影响
- 从站可以离线并同步回主站,无需任何停机时间
Cons
缺点
- In the instance of a failure, a slave has to be promoted to master to take over its place. No automatic failover
- Downtime and possibly loss of data when a master fails
- All writes also have to be made to the master in a master-slave design
- Each additional slave add some load to the master since the binary log have to be read and data copied to each slave
- Application might have to be restarted
- 在发生故障的情况下,必须将一个从站提升为主站来接替它的位置。没有自动故障转移
- 主机故障时停机并可能丢失数据
- 所有的写操作也必须在主从设计中进行
- 每个额外的从站都会给主站增加一些负载,因为必须读取二进制日志并将数据复制到每个从站
- 应用程序可能需要重新启动
2. Master-Master Replication
2. 主主复制
Pros
优点
- Applications can read from both masters
- Distributes write load across both master nodes
- Simple, automatic and quick failover
- 应用程序可以从两个主机读取
- 在两个主节点之间分配写入负载
- 简单、自动和快速的故障转移
Cons
缺点
- Loosely consistent
- Not as simple as master-slave to configure and deploy
- 松散一致
- 不像主从配置和部署那么简单
3. MySQL Cluster
3. MySQL 集群
The new kid in town based on MySQL cluster design. MySQL cluster was developed with high availability and scalability in mind and is the ideal solution to be used for environments that require no downtime, high avalability and horizontal scalability.
基于 MySQL 集群设计的新人。MySQL 集群的开发考虑到了高可用性和可扩展性,是用于不需要停机、高可用性和水平可扩展性的环境的理想解决方案。
See MySQL Cluster 101for more information
有关更多信息,请参阅MySQL Cluster 101
Pros
优点
- (High Avalability) No single point of failure
- Very high throughput
- 99.99% uptime
- Auto-Sharding
- Real-Time Responsiveness
- On-Line Operations (Schema changes etc)
- Distributed writes
- (高可用性)无单点故障
- 非常高的吞吐量
- 99.99% 的正常运行时间
- 自动分片
- 实时响应
- 在线操作(架构更改等)
- 分布式写入
Cons
缺点
- 查看已知限制
You can visit for my Blogfull breakdown including architecture diagrams that goes into further details about the 3 mentioned architectures.
您可以访问我的博客的完整细分,包括架构图,其中详细介绍了上述 3 种架构。