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

optimize redis cluster readonly mode #187

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

alexezio
Copy link

@alexezio alexezio commented Mar 15, 2021

Description

optimize cluster readonly mode by avoid MovedError in write-bound command.

How to reproduce

redis environment:

  • version: 5.0.6
  • master-slave: 5:5

aredis connection pool settings:

  • readonly=True
  • reinitialize_steps=None

fuction optimzed:

  • pool.py/get_node_by_slot

debugging application with vscode, when app invoke write command, fuction get_node_by_slot will return random nodes in that slot when readonly is true. this will cause MovedError exception(in write command like set, expire, setnx etc..) and cause cluster reinitialize, consume cpu usage.

中文说明

aredis 集群模式在readonly设置为true的情况下,未对命令做读写区分,导致了在redis从节点上执行了写操作,触发MovedError异常,最后耗费大量cpu时间在reinitialize流程上, 在多主多从(5主5从及以上)的配置下,非常消耗cpu资源。
对readonly逻辑进行优化,读相关指令,可直接从slot对应主从中选择执行, 写相关指令,则直接返回主节点。

Lian Benchi and others added 2 commits March 15, 2021 22:14
set command default to None to compatible other part
alisaifee added a commit to alisaifee/coredis that referenced this pull request Jan 17, 2022
alisaifee added a commit to alisaifee/coredis that referenced this pull request Jan 17, 2022
alisaifee added a commit to alisaifee/coredis that referenced this pull request Jan 17, 2022
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

Successfully merging this pull request may close these issues.

1 participant