Skip to content

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