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

JedisCluster Pipeline 的支持? #865

Closed
Roiocam opened this issue Mar 21, 2024 · 13 comments
Closed

JedisCluster Pipeline 的支持? #865

Roiocam opened this issue Mar 21, 2024 · 13 comments

Comments

@Roiocam
Copy link
Contributor

Roiocam commented Mar 21, 2024

Motivation

目前的 JedisCluster 模式下,PUT_ALL 是单线程遍历执行的,考虑到 Jedis 已经在 4.0 支持上了 ClusterPipeline,JetCache 有考虑支持吗?

Jedis 相关 ISSUE、PR:

升级到 5.x 版本,API 会流畅一点,但是 4.4.0 也够用,我提个 PR 看看?

@areyouok
Copy link
Collaborator

这个issue非常专业,在我细看之前,我需要先提出一个问题。

jedis版本一般是不单独改的。spring、spring-boot、lettuce、jedis的版本我会保持一致,它们要改就一起改。spring需要哪个版本的jedis/lettuce可以看org.springframework.data:spring-data-redis的pom定义,虽然我不能决定用户使用哪个版本的spring,但如果使用jetcache的根pom中定义的版本,一定是问题最少的。此外,我还需要尽量适应广泛的spring版本,同一个版本的jetcache可以在多个spring版本下使用,具体可以查看docs目录下的兼容性文档。

所以jedis一定要升级版本吗?升级的话:

  1. spring、spring-boot、lettuce、jedis需要同步升级
  2. 升级以后是否有潜在的兼容性问题,是否还可以配合旧版本的spring和jedis工作?
  3. 如果较大的兼容性问题,我会升级jetcache的次版本号,也就是说要升级到2.8版本,同时也要在兼容性文档中做出说明

mvn运行的时候会根据jdk的版本决定用哪个版本的spring进行测试(也可以手工修改),有一些测试比如RedisSpringDataCacheTest也会探测运行时环境决定是否运行。

@Roiocam
Copy link
Contributor Author

Roiocam commented Mar 21, 2024

@areyouok 感谢您的耐心回复,我看了下,最新的 Spring Data Redis 也是不支持 JedisCluster 的 Pipeline 的

https://github.com/spring-projects/spring-data-redis/blob/59481726f4c5f7451c19d639ec5edbba2f373649/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java#L675-L682

并且 Jedis 的版本变化是:

spring data redis jedis commit
3.0.0-M5 4.2.3 spring-projects/spring-data-redis@862decf
3.0.0 4.3.1 spring-projects/spring-data-redis@ac89fa7
3.2.0-M1 4.4.3 spring-projects/spring-data-redis@ce3c439
3.2.0-M3 4.4.4 spring-projects/spring-data-redis@307ca5e
3.2.0-RC1 5.0.1(中间有个4.4.5) spring-projects/spring-data-redis@2075633
3.2.0~至今 3.2.4 5.0.2 spring-projects/spring-data-redis@f97bd87

由于 3.2.0 正式版直接就到 5.0.x 了,因此维护一个和 Spring 不对齐的 4.4.0 版本可能会导致问题,那这样我们只能留在 4.3.2,并在 JetCache 下一个大版本迭代(需要同步更新 Spring、 Lettuce)的时候,才升级到 5.0.x 比较合适。

不过 4.3.2 也并不是没有支持 ClusterPipeline 的方案,我们只需要加一个 Wrapper 就可以, 我在 PR 里增加一个 Commit 来体现

@Roiocam
Copy link
Contributor Author

Roiocam commented Mar 21, 2024

补充一下背景,之所以提这个是因为我们业务组的同时反馈从 Lettuce 迁移到 Jedis 之后,缓存同步的性能慢了快一个小时,排查后发现这边有个性能优化点,这是我们升级前后的耗时:

当然,我们的场景比较特殊,一次性同步 250w 的缓存

升级前

362675b5516a11c3f0cee3cdc57c54b1_副本

升级后

031c4a1c78c56ec08219fc870e5e9cfe_副本

@areyouok
Copy link
Collaborator

最新版本我一般是这样确定的,先找一个最新的spring-boot稳定版本,然后看它的pom需要spring-framework的什么版本,以及它一来的spring data(不一定是最新的)对jedis/lettuce的版本要求。

这些都是可以升级的,只是升级以后需要的检查项比较多。

@Roiocam
Copy link
Contributor Author

Roiocam commented Mar 22, 2024

假如 JetCache 的 2.8.0 以下一个正式版本的 Spring(3.2.0 开始), spring data redis 的版本是同步于 spring-boot 的:

jetcache/pom.xml

Lines 203 to 207 in 94c5a19

<spring.framework.version>6.0.11</spring.framework.version>
<spring.boot.version>3.1.3</spring.boot.version>
<lettuce.version>6.2.6.RELEASE</lettuce.version>
<jedis.version>4.3.2</jedis.version>

需要变动的大概是上面这几个依赖那么有两种可选方案, 来自于:

 <spring.framework.version>6.1.0</spring.framework.version> 
 <spring.boot.version>3.2.0</spring.boot.version> 
 <lettuce.version>6.3.0.RELEASE</lettuce.version> 
  
 <jedis.version>5.0.2</jedis.version> 

或者最新的:

 <spring.framework.version>6.1.5</spring.framework.version> 
 <spring.boot.version>3.2.4</spring.boot.version> 
 <lettuce.version>6.3.2.RELEASE</lettuce.version> 
  
 <jedis.version>5.0.2</jedis.version> 

我认为可以先让 2.8.0 同步到 3.2.0,在修订号迭代中再考虑升级 3.2.x 的小版本

我在尝试升级的时候发现当前版本的 redisson 引入了一个低版本的 Spring: https://github.com/redisson/redisson/blob/redisson-3.18.0/redisson-spring-boot-starter/pom.xml

那么要同步所有版本都到 3.2.0,将 redisson 也升级到 3.25.0 才行:https://github.com/redisson/redisson/blob/redisson-3.25.0/redisson-spring-boot-starter/pom.xml

@Roiocam
Copy link
Contributor Author

Roiocam commented Mar 22, 2024

@areyouok 我发起了两个 PR,一个是为 2.7.x,另一个则是为 2.8.x 提供的 JedisCluster Pipeline 支持,你可以看下吗?

2.8.x 那版更新了很多依赖,但是单测看起来只有 Redisson 有不兼容 Kryo 序列化问题,我用配置重写降级了默认的 KryoCodec,其余的兼容性我还没验证,如果单测能够 cover 住,那应该没问题。

2.7.x 的那版考虑近期发一个版本吗?谢谢

@areyouok
Copy link
Collaborator

我很长时间没有改过这个项目了。很多东西包括jedis新旧版本的差异我也不记得了,我需要一些时间来评估。也许不需要改那么多。

@areyouok
Copy link
Collaborator

我看了一下4.3.2的代码,ClusterPipeline是个重量级对象,每次new一个应该是不行的,应该取UnifiedJedis类的provider字段,对于JedisCluster实例来说,就是ClusterConnectionProvider,做个类型转换就好了。

provider字段是protected,也没有getter,我认为最简单的修改方式是在构造RedisCache类的时候,通过反射拿出来。这样只需要改一个类。没有特别的需要,也不用升级jedis/spring的版本了,jetcache2.7搭配高版本spring/jedis应该也可以运行的。

通过wrapper的方式继承,就还有更多的地方要改,因为Cache可以通过API来构造(构造的时候需要传入JedisClusterWrapper),RedisAutoConfiguration不是唯一入口。

@Roiocam
Copy link
Contributor Author

Roiocam commented Mar 27, 2024

closed by #866

@Roiocam Roiocam closed this as completed Mar 27, 2024
@areyouok
Copy link
Collaborator

GET_ALL还需要优化吗?

@Roiocam
Copy link
Contributor Author

Roiocam commented Mar 28, 2024

GET_ALL还需要优化吗?

可以,不过 GET_ALL 只能优化集群那边的处理逻辑,非集群下反而 mget 和 del(keys) 性能好点,我尝试提个 PR 看看

@areyouok
Copy link
Collaborator

我的意思就是cluster情况下的GET_ALL

@Roiocam
Copy link
Contributor Author

Roiocam commented Mar 28, 2024

我的意思就是cluster情况下的GET_ALL

#873 把 GET_ALL 和 REMOVE_ALL 都改了

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 a pull request may close this issue.

2 participants