Bifrost Document

Version 1.6.x

Bifrost ---- 面向生产环境的 MySQL 同步到 Redis,MongoDB,ClickHouse 等服务的异构中间件

Bifrost同步到ClickHouse性能测试过程_1

在此感谢 @yocoo 提供 腾讯云云主机 进行性能测试

机器A: 用于跑 Bifrost + 随机生成数据写到入 MySQL 的程序

配置:4核 内存:8G

机器C: MySQL

配置:4核 内存:8G 磁盘:1000G

机器C: ClickHouse

配置:4核 内存:8G 磁盘:1000G

软件版本:

Bifrost Version:v1.6.2-release

MySQL Version: 5.7.30-log

ClickHouse Version : 20.8.3.18

insertDataTest Version : 1.6.2

1. 准备工作

1).下载 Bifrost 源码,并且 编译 insertDataTest

git clone -b https://github.com/brokercap/Bifrost.git ./BifrostV1.6.x

cd BifrostV1.6.x/test

go build ./insertDataTest.go

2).安装MySQL 和 ClickHouse 并创建 bifrost_test 库及相对应的表名

MySQL 表结构 (建5个MySQL 表)

CREATE TABLE `binlog_field_test_5` (   `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,   `testtinyint` TINYINT(4) NOT NULL DEFAULT '-1',   `testsmallint` SMALLINT(6) NOT NULL DEFAULT '-2',   `testmediumint` MEDIUMINT(8) NOT NULL DEFAULT '-3',   `testint` INT(11)) NOT NULL DEFAULT '-4',   `testbigint` BIGINT(20) NOT NULL DEFAULT '-5',   `testvarchar` VARCHAR(400) NOT NULL,   `testchar` CHAR(2) NOT NULL,   `testenum` ENUM('en1','en2','en3') NOT NULL DEFAULT 'en1',   `testset` SET('set1','set2','set3') NOT NULL DEFAULT 'set1',`testtime` TIME NOT NULL DEFAULT '00:00:01',   `testdate` DATE NOT NULL DEFAULT '1970-01-01',   `testyear` YEAR(4) NOT NULL DEFAULT '1989',   `testtimestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,   `testdatetime` DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00',
  `testfloat` FLOAT(9,2) NOT NULL DEFAULT '0.00',   `testdouble` DOUBLE(9,2) NOT NULL DEFAULT '0.00',   `testdecimal` DECIMAL(9,2) NOT NULL DEFAULT '0.00',   `testtext` TEXT NOT NULL,   `testblob` BLOB NOT NULL,   `testbit` BIT(64) NOT NULL DEFAULT b'0',   `testbool` TINNYINT(1) NOT NULL DEFAULT '0',   `testmediumblob` MEDIUMBLOB NOT NULL,   `testlongblob` LONGBLOB NOT NULL,   `testtinyblob` TINYBLOB NOT NULL,   `test_unsinged_tinyint` TINYINT(4) UNSIGNED NOT NULL DEFAULT '1',   `test_unsinged_smallint` SMALLINT(6) UNSIGNED NOT NULL DEFFAULT '2',   `test_unsinged_mediumint` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '3',   `test_unsinged_int` INT(11) UNSIGNED NOT NULL DEFAULT '4',   `test_unsinged_bigint` BIGINT(20) UNSIGNED NOT NULL DEFAULT '5',   PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=40000000000 DEFAULT CHARSET=utf8;

ClickHouse 表结构 (建5个 ClikcHouse 表)

CREATE TABLE binlog_field_test_5 ( `id` UInt64, `testtinyint` Int8, `testsmallint` Int16, `testmediumint` Int32, `testint` Int32, `testbigint` Int64, `testvarchar` String, `testchar` String, `testenum` String, `testset` String, `testtime` String, `testdate` Date, `testyear` Int16, `testtimestamp` DateTime, `testdatetime` DateTime, `testfloat` Float64, `testdouble` Float64, `testdecimal` String, `testtext` String, `testblob` String, `testbit` Int64, `testbool` Int8, `testmediumblob` String, `testlongblob` String, `testtinyblob` String, `test_unsinged_tinyint` UInt8, `test_unsinged_smallint` UInt16, `test_unsinged_mediumint` UInt32, `test_unsinged_int` UInt32, `test_unsinged_bigint` UInt64, `binlog_event_type` String, `bifrost_data_version` Int64 ) ENGINE = MergeTree() ORDER BY id

2. 第一次测试

2.1 开始测试

MySQL 创建的 是 binlog_field_test 5个表,并且是Innodb 引擎

同步到ClickHouse 同步配置采用每个表一个同步配置,字段强绑定关系,并且采用的是日志追加模式同步

image

刷数据到MySQL (机器A上执行,与Bifrost 同一台机器)

nohup ./insertDataTest -host 10.0.3.31 -user xxtest -pwd xxtest -schema bifrost_test -table binlog_field_test_1 -count 1000000000 -batchsize 1000 -time_interval 100 >> ./1.log

nohup ./insertDataTest -host 10.0.3.31 -user xxtest -pwd xxtest -schema bifrost_test -table binlog_field_test_2 -count 1000000000 -batchsize 1000 -time_interval 100 >> ./2.log

nohup ./insertDataTest -host 10.0.3.31 -user xxtest -pwd xxtest -schema bifrost_test -table binlog_field_test_3 -count 1000000000 -batchsize 1000 -time_interval 100 >> ./3.log

nohup ./insertDataTest -host 10.0.3.31 -user xxtest -pwd xxtest -schema bifrost_test -table binlog_field_test_4 -count 1000000000 -batchsize 1000 -time_interval 100 >> ./4.log

nohup ./insertDataTest -host 10.0.3.31 -user xxtest -pwd xxtest -schema bifrost_test -table binlog_field_test_5 -count 1000000000 -batchsize 2000 -time_interval 50 >> ./5.log

2.2 第一测试结果

以上配置在执行同步的时候,Bifrost 同步位点是追得上 MySQL写入速度的,平均每分钟是在260万条数据解析,360Mb 数据处理速度

但在运行了 17 个小时后, MySQL 磁盘满了,写不进数据,同步就暂停状态,共计写入29亿多数据,约30亿条数据,由于没有保存记录,Bifrost 进程cpu使用率大约在 160%-210% 左右浮动,内存实际使用约220Mb - 700Mb之前浮动。

在MySQL 没有数据写入之后,Bifrost 内存下降到了220Mb ,并且没有进程退出,说明只要有数据进来可以继续稳定运行。

3. 第二次测试

3.1 开始测试

采用 MyISAM 引擎表结构 实际同步3个表,每次刷到数据到表里的速度变更

nohup ./insertDataTest -host 10.0.3.31 -user xxtest -pwd xxtest -schema bifrost_test -table binlog_field_test_1 -count 1000000000 -batchsize 2000 -time_interval 50 >> ./1.log

nohup ./insertDataTest -host 10.0.3.31 -user xxtest -pwd xxtest -schema bifrost_test -table binlog_field_test_2 -count 1000000000 -batchsize 2000 -time_interval 50 >> ./2.log

nohup ./insertDataTest -host 10.0.3.31 -user xxtest -pwd xxtest -schema bifrost_test -table binlog_field_test_3 -count 1000000000 -batchsize 2000 -time_interval 50 >> ./3.log

3.2 第二测试结果

实际执行下来 Bifrost binlog 解析跟不上 MySQL写入速度,Bifrost 每分钟同步量在270-280万条左右

4. 三次测试

4.1 开始测试

采用 MyISAM 引擎表结构,实际同步3个表,每个表每100ms 刷 1000条数据

nohup ./insertDataTest -host 10.0.3.31 -user xxtest -pwd xxtest -schema bifrost_test -table binlog_field_test_1 -count 1000000000 -batchsize 1000 -time_interval 100 >> ./1.log

nohup ./insertDataTest -host 10.0.3.31 -user xxtest -pwd xxtest -schema bifrost_test -table binlog_field_test_2 -count 1000000000 -batchsize 1000 -time_interval 100 >> ./2.log

nohup ./insertDataTest -host 10.0.3.31 -user xxtest -pwd xxtest -schema bifrost_test -table binlog_field_test_3 -count 1000000000 -batchsize 1000 -time_interval 100 >> ./3.log

实测试下来,Binlog解析基本上可以追上,略有延迟,由此可以证明在单线程刷单表数据的时候,MyISAm 比 Innodb 快。

每分钟解析速度约270万,380Mb大小(看来在当前硬件配置情况下,当前ClickHouse每1000条刷一次数据的情况下,这个速度可能是极限了)

image

硬件使用情况

image

Bifrost 大约使用550Mb内存左右, 感觉略高于 Innodb引擎的时候,至于为啥,未知

CPU 大约也是在160% - 210% 之间浮动

在同步了 6.2 亿的数据,尝试给第四个表,写1000万数据,看位点能否跟上,结果 位点开始拉大,差距差不多相差2亿,并慢慢拉大,每分钟处理的数据数量和大小并没有提升,说明当前 270万/分钟, 380Mb/每分钟是当前硬件配置上的上限了。在位点相差100s 左右的时候,把第四个表的刷数据进程暂停了

4.2 第三次测试结果

image

显示4:40 没有同步数据了,实际是查看日志是在4:29分写完的,因为这个流量统计这里时间只能参数,会有聚合时间,这咋就按流量显示的时间来计算。

大约花费 17.5 个小时同步完30亿数据,平均约速率约为 295万条/分钟,389M/分钟

硬件使用情况

image

同步完成,Bifrost 实际使用使用降回到240M

5. 第四次测试(全量测试)

5.1 开始测试

由于全量配置支持拉数据和同步数据的线程数,为了方便,这里我们将 binlog_field_test_1,binlog_field_test_2,binlog_field_test_3 三个表的数据同步到 ClickHouse 中的 binlog_field_test_all 一个表里

image

全量任务拉数据的线程 3 个,同步数据的线程 6个

image

同步中截图

image

image

image

同步过程中 机器负载可以打满,内存使用也比较低

5.2 第四次测试结果

image

image

全量 3069529000 条数据 ,共耗时 12小时33分钟

image

全量同步完后,CPU和内存又降回到正常状态

6. 本轮测试小结

4核8G 的机器上运行 Bifrost 同步数据

表字段30个,增量同步的时候,同步性能差不多是每分钟280万条 ,380MB大小左右 ,约40亿条/天。并且CPU使用率在2核,内存在700MB 以下,如果表的数据更多,单表数据量更小,有可能性能会更好,可以更充分CPU

全量因为可以配置拉数据和同步数据的线程数,数据本身是可以无序的同步概念。可以根据CPU核数情况进行动态配置,测试下来,配置合理是可以将CPU打满的,内存使用也不高

综合上来看, Bifrost 内存需求不高,选择配置的时候,可以考滤计算型的机器!

Last updated on 27 Dec 2020
Edit on GitHub