爱可生 DBA 团队成员,卖力公司 DMP 产品的运维和客户 MySQL 问题的处理。善于数据库故障处理。对数据库技能和 python 有着浓厚的兴趣。
本文来源:原创投稿
爱可生开源社区出品,原创内容未经授权不得随意利用,转载请联系
# 主库 & 从库set global slave_compressed_protocol = ON ;stop slave io_thread;start slave io_thread;# 开启or关闭 slave_compressed_protocol参数,需重启复制,让该参数生效。
binlog压缩的压缩效果
压缩到底有没有效果呢?不废话直接压测当作果。

创建压缩表注意灌输数据
socket='/data/mysql/data/7777/mysqld.sock'user='root'password='123'db='lubao7hao'table_num='10'table_size='500000'thread_num='128'sysbench /usr/share/sysbench/tests/include/oltp_legacy/oltp.lua --mysql-socket=${socket} --mysql-user=${user} --mysql-password=${password} --mysql-db=${db} --oltp-tables-count=${table_num} --oltp-table-size=${table_size} --report-interval=10 --rand-init=on --max-requests=0 --oltp-test-mode=nontrx --oltp-nontrx-mode=select --oltp-read-only=off --max-time=360000 --num-threads=${thread_num} prepare
关闭状态主库监控
从库监控
开启状态 主库监控
从库监控
结论主库 cpu 从库 cpu 主库 send 主库 recv 从库 send 从库 recv 未压缩 4.24% 2.7% 14.50MB/s 7.31MB 35KB/s 14.60MB/s 压缩 8.50% 3.18% 6.68MB/s 7.27MB/s 35KB/s 6.610MB/s
1、开启 slave_compressed_protocol 参数,压缩效果明显,网络数据传输量约为未开启一半,压缩率 50%。
2、开启 slave_compressed_protocol 参数,在一定程度上是会花费 CPU 资源;如果 CPU 负载已经很高就不太建议再开压缩了。
把稳事变在MySQL 在 5.7.21 以下,或者 8.0.4 以下的版本在 slave_compressed_protocol=ON 与半同步复制一起利用时,会触发 Bug 导致主库写入卡住。这里就不多说了,以免偏离主题太多,见地址:https://bugs.mysql.com/bug.php?id=86230