multithreading - Redis 连接数与单线程

标签 multithreading spring-boot redis

我读到 Redis 是单线程的。

使用 jedis 客户端(java)我们可以配置连接池,比如:

spring.redis.jedis.pool.max-active=8 # Maximum number of connections that can be allocated by the pool at a given time. Use a negative value for no limit.
spring.redis.jedis.pool.max-idle=8 # Maximum number of "idle" connections in the pool. Use a negative value to indicate an unlimited number of idle connections.
spring.redis.jedis.pool.max-wait=-1ms # Maximum amount of time a connection allocation should block before throwing an exception when the pool is exhausted. Use a negative value to block indefinitely.
spring.redis.jedis.pool.min-idle=0 # Target for the minimum number of idle connections to maintain in the pool. This setting only has an effect if it is positive.

我知道池连接对于获得已打开的连接很重要,因此不会再花时间重新连接。

假设 8 个“客户端请求”使用所有可用池,因此将使用 8 个连接,这些客户端在 Redis 中执行“GET”命令。

Redis 每次处理一个线程?由于 Redis 是单线程,每个线程都需要等待其他线程完成吗?在这种情况下,当 1 个“GET”正在处理时,其他 7 个在 Redis 队列中?

如果 Redis 是单线程,max-active 如何影响 Redis 性能?

最佳答案

只有Redis的主循环是单线程的。它使用 client buffers在单独的线程中以加快处理速度。你花在从 Redis 获取数据上的大部分时间是网络时间。他们为此提供帮助。这意味着除非您存储非常大的对象,否则您将获得几乎线性的吞吐量增长。

在这里,我测量了 Lettuce(另一个客户端)的不同设置。我希望“合并”设置与您使用 Jedis 获得的设置非常相似:Redis is single thread. Then why should I use lettuce?

关于multithreading - Redis 连接数与单线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51352671/

相关文章:

java - Spring 默认 bean 候选者

php - Laravel 4.2 中用于缓存和 session 的不同 redis 数据库

java - 如何检测虚假唤醒

java - 如何确定高延迟网络请求的最佳线程数?

java - 使用 wro4j-maven-plugin 的 Spring Boot AngularJs 应用程序 : angular-bootstrap. css 生成失败

Redis:迭代/扫描按值排序的所有键

ruby-on-rails - Rails 在我的 redis 缓存中添加额外的行

C++ 随机种子、全局对象和 SDL_Threads

java - 无法从其他类(线程)的 Vector 获取元素

spring-boot - 如何验证来自 OAuth 服务器的 token ?