Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于全量数据同步时的优化建议 #116

Open
wulimax opened this issue Jun 14, 2022 · 15 comments
Open

关于全量数据同步时的优化建议 #116

wulimax opened this issue Jun 14, 2022 · 15 comments

Comments

@wulimax
Copy link

wulimax commented Jun 14, 2022

调研使用go-mysql-transfer时,发现千万级别的大表数据同步时,对于mysql的压力很大,
优化建议:
将 select b.* from (select %s from %s order by %s limit %d,%d) a left join %s b on a.%s=b.%s
通过EXPLAIN 虚拟表并未用到索引
期望优化成 : SELECT * FROM table where id > 0 order by id limit 100
通过迭代主键id 的方式替换掉 使用虚拟表的方式

@chengcxy
Copy link

赞同 可以试下 先取 min(id) max(id) 然后设定batch =1000(3000/5000等)
where id>0 and id<= 1000
where id>1000 and id<= 2000
where id>2000 and id<=3000

开启20个worker 并发执行上面的子任务效率更快

调研使用go-mysql-transfer时,发现千万级别的大表数据同步时,对于mysql的压力很大, 优化建议: 将 select b.* from (select %s from %s order by %s limit %d,%d) a left join %s b on a.%s=b.%s 通过EXPLAIN 虚拟表并未用到索引 期望优化成 : SELECT * FROM table where id > 0 order by id limit 100 通过迭代主键id 的方式替换掉 使用虚拟表的方式

@wulimax
Copy link
Author

wulimax commented Dec 16, 2022 via email

@chengcxy
Copy link

可以加一下您的联系方式吗 学习一下go-mysql-transfer ------------------ 原始邮件 ------------------ 发件人: "wj596/go-mysql-transfer" @.>; 发送时间: 2022年10月21日(星期五) 上午7:48 @.>; 抄送: "a『♀※♂@@.@.>; 主题: Re: [wj596/go-mysql-transfer] 关于全量数据同步时的优化建议 (Issue #116) 赞同 可以试下 先取 min(id) max(id) 然后设定batch =1000(3000/5000等) where id>0 and id<= 1000 where id>1000 and id<= 2000 where id>2000 and id<=3000 开启20个worker 并发执行上面的子任务效率更快 调研使用go-mysql-transfer时,发现千万级别的大表数据同步时,对于mysql的压力很大, 优化建议: 将 select b.* from (select %s from %s order by %s limit %d,%d) a left join %s b on a.%s=b.%s 通过EXPLAIN 虚拟表并未用到索引 期望优化成 : SELECT * FROM table where id > 0 order by id limit 100 通过迭代主键id 的方式替换掉 使用虚拟表的方式 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

v信:chengcxy86

@chengcxy
Copy link

chengcxy commented Dec 24, 2022

调研使用go-mysql-transfer时,发现千万级别的大表数据同步时,对于mysql的压力很大, 优化建议: 将 select b.* from (select %s from %s order by %s limit %d,%d) a left join %s b on a.%s=b.%s 通过EXPLAIN 虚拟表并未用到索引 期望优化成 : SELECT * FROM table where id > 0 order by id limit 100 通过迭代主键id 的方式替换掉 使用虚拟表的方式

下午先改了一版 https://github.com/chengcxy/go-mysql-transfer
提交了合并请求等作者merge

@Sharkzeng
Copy link

兄弟 你的版本 是否支持MYSQL 同步到MYSQL呢? 另外是否支持配置方式 同步到过个目标,多个表呢?

@wulimax
Copy link
Author

wulimax commented Mar 29, 2023 via email

@chengcxy
Copy link

自己写一个脚本 批量生成datax的json配置文件 或者自己造轮子 没什么复杂的 读取到schema,切分读取,拼接insert intosql语句 能自动读取到配置即可

@Sharkzeng
Copy link

如果是mysql同步到mysql 可以使用其他工具 ,比如 mysql自带的数据同步功能,otter,yugong, canal ,DataX,dbsyncer,

------------------ 原始邮件 ------------------ 发件人: "wj596/go-mysql-transfer" @.>; 发送时间: 2023年3月29日(星期三) 下午2:24 @.>; 抄送: "a『♀※♂@@.@.>; 主题: Re: [wj596/go-mysql-transfer] 关于全量数据同步时的优化建议 (Issue #116) 兄弟 你的版本 是否支持MYSQL 同步到MYSQL呢? 另外是否支持配置方式 同步到过个目标,多个表呢? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

canal 是要自己开发客户端啊

@wulimax
Copy link
Author

wulimax commented Mar 30, 2023 via email

@wulimax
Copy link
Author

wulimax commented Mar 30, 2023 via email

@Sharkzeng
Copy link

其他工具 只有dbsyncer 稍微符合下要, 不过它不支持REDIS
其实想要个 免费 易配置,出错友好定位的 MYSQL TO MYSQL ; MYSQL TO REDIS; MYSQL TO CLICKHOUSE; MYSQL TO ES

@Sharkzeng
Copy link

go-mysql-transfer 这工具 配置挺易的 就单表,单目标 不太实用, 要自己写LUA脚本

@wulimax
Copy link
Author

wulimax commented Mar 30, 2023 via email

@tianyuso
Copy link

tianyuso commented Sep 8, 2023

赞同 可以试下 先取 min(id) max(id) 然后设定batch =1000(3000/5000等) where id>0 and id<= 1000 where id>1000 and id<= 2000 where id>2000 and id<=3000

开启20个worker 并发执行上面的子任务效率更快

调研使用go-mysql-transfer时,发现千万级别的大表数据同步时,对于mysql的压力很大, 优化建议: 将 select b.* from (select %s from %s order by %s limit %d,%d) a left join %s b on a.%s=b.%s 通过EXPLAIN 虚拟表并未用到索引 期望优化成 : SELECT * FROM table where id > 0 order by id limit 100 通过迭代主键id 的方式替换掉 使用虚拟表的方式

int类型的主键可以,uuid的主键这种方式不行

@chengcxy
Copy link

chengcxy commented Sep 9, 2023

是的,我们主键自增id 创建时间 更新时间是建表时候的必带字段,如果业务上有uuid作为唯一键的要求,我们做法是主键自增id,uuid列添加唯一索引

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants