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

优先选择从节点执行任务 #724

Closed
jjz921024 opened this issue Dec 13, 2023 · 6 comments
Closed

优先选择从节点执行任务 #724

jjz921024 opened this issue Dec 13, 2023 · 6 comments
Assignees
Labels
type: feature request New feature or request

Comments

@jjz921024
Copy link
Contributor

当前scan_reader和sync_reader都是选择主节点进行连接,
为了避免主节点负载太高,在有从节点的情况下,优先选择从节点进行同步和迁移工作

  1. 在scan_reader和sync_reader下增加 perfer_replica 属性,表示优先选择从节点
  2. 修改 cluster_nodes.go 中的 GetRedisClusterNodes() 函数,根据配置选择主从节点,若某个主节点没有从节点,则还是连接主节点
@suxb201
Copy link
Member

suxb201 commented Dec 21, 2023

感觉配置文件直接写从节点就可以,RedisShake 不做决策,可以尽量保持简单。

@jjz921024
Copy link
Contributor Author

目前的实现中,即使配置文件中指定了从节点, GetRedisClusterNodes() 通过cluster node命令拿到集群的拓扑信息后,还是会连到主节点上

if !strings.Contains(words[2], "master") {

@suxb201
Copy link
Member

suxb201 commented Dec 21, 2023

明白了,Cluster 模式下确实有这样的问题。

@Zheaoli
Copy link
Collaborator

Zheaoli commented Dec 21, 2023

这里的设计我有点纠结,我自己测试下来后,我倾向于 scan 可以连接到从节点,sync 还是链接到主节点比较好?

@suxb201
Copy link
Member

suxb201 commented Dec 22, 2023

@Zheaoli sync 也是会增加主节点负载的。Redis 是单线程架构,处理用户命令和给 salve 节点发送数据交替进行。

@jjz921024
Copy link
Contributor Author

@suxb201 @Zheaoli hi,这个功能感觉还是有挺多需求的,生产环境上都不想加重主节点的负载,这种同步的功能都可以移到从节点做。能麻烦看看 #725 这个pr的实现是否有问题吗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants