面试连环炮系列(二十八):数据库读写分离的目的是什么?

1. 数据库读写分离的目的是什么?

通常,商业系统读得更多,写得更少。读写分离将读写操作分散到不同的节点,可以小幅提升写性能,大幅提升读性能。通常在数据库中采用一主多从的方式,主数据库可以读写,从库只能读。

[En]

Usually, the business system reads more and writes less. Read-write separation distributes the read and write operations to different nodes, which can slightly improve the write performance and greatly improve the read performance. Usually adopts the way of one master and multiple slaves in the database, the master database can read and write, and the slave library can only read.

2. 读写分离会带来什么问题?如何解决?

主库和从库的数据存在延迟。例如,写完主数据库后,将主库的数据同步到从库需要花费时间,这就导致了主库和从库之间的数据不一致。解决方案是在无法容忍延迟的情况下强制读取主库。

[En]

There is a delay in the data of the master and slave libraries. For example, after writing the master database, it takes time to synchronize the data of the master library to the slave database, which leads to the data inconsistency between the master database and the slave database. The solution is to force the main library to be read in scenarios where delays cannot be tolerated.

3. MySQL主从复制的原理清楚吗?

  • 主库将数据库中数据的变化写入到 binlog
    从库连接主库。
  • 从库会创建一个I/O线程向主库请求更新的 binlog。
  • 主库会创建一个 binlog dump 线程来发送 binlog ,从库中的 I/O 线程负责接收。
  • 从库的 I/O 线程将接收的 binlog 写入到 relay log 中。
  • 从库的 SQL 线程读取 relay log 同步数据本地(也就是再执行一遍 SQL )。

4. 读写分离具体怎么实施呢?

常用组件有下面2个:

  • Sharding-JDBC:定位为轻量级Java框架,在Java的JDBC层提供的额外服务。它使用客户端直连数据库,以jar包形式提供服务,无需额外部署和依赖,可理解为增强版的JDBC驱动,完全兼容JDBC和各种ORM框架。
  • MyCat:实现了MySQL协议的服务器,前端用户可以把它看作是一个数据库代理,用MySQL客户端工具和命令行访问,而其后端可以用MySQL原生协议与多个MySQL服务器通信,也可以用JDBC协议与大多数主流数据库服务器通信,其核心功能是分库分表,配合数据库的主从模式还可实现读写分离。

Original: https://www.cnblogs.com/xiaoyangjia/p/16070541.html
Author: 编码砖家
Title: 面试连环炮系列(二十八):数据库读写分离的目的是什么?

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/505518/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球