SpringBoot的redis连接池lettuce参数配置优化建议Redis客户端配置优化建议
配置项默认
值
描述中⽂描述
available refresh triggers should be used.
redis集拓扑⾃动刷新
allocated by the pool at a given time. Use a negative
value for no limit.
连接池可以分配的最⼤连接数。使
⽤负值表⽰⽆限制。
Use a negative value to indicate an unlimited
number of idle connections.
连接池可以分配的最⼤连接数。使
⽤负值表⽰⽆限制。
should block before throwing an exception when the
pool is exhausted. Use a negative value to block
indefinitely.
连接池资源耗尽时,连接尝试分配
阻塞时间,超时即抛出异常。使⽤
负值⽆限期阻塞。
to maintain in the pool. This setting only has an
effect if both it and time between eviction runs are
positive.
连接池最⼩空闲连接数.仅在它和
time-between-eviction-runs都为正
时有效
When positive, the idle object evictor thread starts,
otherwise no idle object eviction is performed.
空闲对象逐出器线程的运⾏间隔时
间。当为正值时,空闲对象逐出器
线程启动,否则不执⾏空闲对象逐
出。
配置详解
配置数量过少,往往在开发环境时配置会⽐较低,在压测时会导致竞争激烈,多数线程被阻塞,导致TPS上不去.
可以通过打印redis查询接⼝耗时发现,接⼝耗时不稳定.有些快的在1ms完成,慢的在40ms以上,甚⾄超时.[建议查询耗时在1-3ms之间]
配置数量过⼤,配置数量过⼤不仅浪费资源,甚⾄可能抢占不到与redis的连接,这与redis服务器可连接的最⼤数有关.处理redis连接数过多
解决⽅法: 加⼤配置值.
建议默认值: CPU*2
连接池最⼤的空闲数.过少会导致频繁释放\建⽴链接,⼗分耗时(建⽴连接是耗时操作).过多会浪费资源.
配置数量过少,导致并发⾼时,需要新建与redis的连接.
通过监控查看redis每秒新建连接数与当前连接数,逐步提⾼配置数量,以致达到预期.
连接尝试分配阻塞时间.过短会频繁抛出异常,在有旁路设计的系统中,压⼒就会宣泄到数据库中.过长
或者⽆限制会导致接⼝响应时间过长. dis.lettuce.pool.min-idlespringboot中文
连接池最⼩空闲连接数.
空闲对象逐出器线程的运⾏间隔时间.空闲连接线程释放周期时间
.
配置推荐
开发环境
⽣产环境
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论