实现目标

  1. 验证PolarDB能够做透明的读写分离
  2. 验证读写分离的负载均衡能力

实验准备

  1. 完成实验一《使用sysbench验证POLARDB的OLTP性能》
  2. 创建读写分离连接地址
    https://help.aliyun.com/document_detail/85143.html?spm=a2c4g.11186623.6.582.6c1112f9C1CqA2

一:透明读写分离

  1. 压测集群连接地址
sysbench --test=oltp \

 --mysql-host=XXX \

 --oltp-tables-count=128 \

 --mysql-user=XXX \

 --mysql-password=XXX \

 --mysql-port=XXX \

 --db-driver=mysql \

 --oltp-table-size=100000 \

 --mysql-db=sbtest \

 --max-requests=0 \

 --oltp-read-only=on \

 --oltp-skip-trx=on \

 --max-time=60 \

 --mysql-ignore-errors=1062 \

 --report-interval=1 \

 --num-threads=32 run

这个case包含了点查询,range查询和简单的查询

  1. 压测读写分离连接地址
    测试方法同上,地址换成读写分离地址
  2. 对比两者性能差异
    预期观察到走读写分离地址获得更好的性能(因为同时使用了RW和RO节点的能力)

二:负载均衡

  1. 开一个窗口按照以下测试做点查询
sysbench --test=oltp \

 --mysql-host=lab.maxscale.rds.aliyuncs.com \

 --oltp-tables-count=128 \

 --mysql-user=mytest \

 --mysql-password=test123 \

 --mysql-port=3306 \

 --db-driver=mysql \

 --oltp-table-size=100000 \

 --mysql-db=sbtest \

 --max-requests=0 \

 --max-time=300 \

 --oltp_simple_ranges=0 \

 --oltp-distinct-ranges=0 \

 --oltp-sum-ranges=0 \

 --oltp-order-ranges=0 \

 --oltp-read-only=on \

 --oltp-skip-trx=on \

 --num-threads=32 \

 --report-interval=1 run

 

  1. 在开一个窗口执行另外一个慢查询case,打开事务,使得慢查询请求都打到主库
sysbench --test=oltp \

 --mysql-host=xxx \

 --oltp-tables-count=128 \

 --mysql-user=xxx \

 --mysql-password=xxx \

 --mysql-port=3306 \

 --db-driver=mysql \

 --oltp-table-size=100000 \

 --mysql-db=sbtest \

 --max-requests=0 \

 --max-time=300 \

 --oltp-point-selects=0 \

 --oltp_simple_ranges=0 \

 --oltp-distinct-ranges=1000 \

 --oltp-sum-ranges=0 \

 --oltp-order-ranges=0 \

 --oltp-read-only=on \

 --oltp-skip-trx=off \
 --report-interval=5 \

 --num-threads=16 run

oltp-distinct-ranges查询相对于点查询会消耗更多的资源,因为oltp-skip-trx=off会打开事务,所以这个case的请求会全发到主库,造成主库压力高

  1. 通过监控观察到更多的流量发送到了只读库