Redis是单线程的.那我为什么要用生菜呢? [英] Redis is single thread. Then why should I use lettuce?
问题描述
Redis 4.0之后,Redis可以执行多线程某些功能(1.删除后台对象等),但是Redis通常仍使用单线程. 常见问题-Redis
After Redis 4.0, Redis can execute multi thread some functions (1. deleting objects in backgrounds, etc.), but Redis still usually uses single thread. FAQ - Redis
所以我想生菜没用. Lettuce是Redis客户端,可以在1个连接中使用多个线程,但是Redis在1个连接中只能使用单个线程.
So I guess lettuce is useless. Lettuce is redis client that can use multiple threads in 1 connections, but Redis can use only single thread in 1 connection.
您可以建议对Redis客户端使用生菜吗?为什么?
Can you recommend to use lettuce for Redis client? Why?
推荐答案
因为您不仅要花时间在Redis执行命令的过程中,而且还要花时间传输数据(发送命令,接收结果).在传输时,在单线程模式下,Redis不起作用.当Redis工作时,不会发生任何转移.此处有多个连接或一个管道连接,可帮助您饱和带宽和CPU周期.
Because you spend time not only while Redis executes commands, but also transferring data (sending commands, recieving results). In single thread mode while you transfer, Redis doesn't work. While Redis works, no transfer occures. Multiple connections or one pipelined connection are here to help you saturate both bandwidth and CPU cycles.
luttece不仅与速度有关.它还可以帮助您使用异步和响应式API更好地组织代码.
And luttece is not only about speed. It also helps you organize your code better with asynchronous and reactive API.
回到性能主题,此处是一个简单的基准,可用来大致了解线程和集中影响.请注意,虽然池化速度较慢(您花了一些时间进行池操作),但它允许您隔离操作(因此错误不会影响其他线程)并使用MULTI
和阻止命令.
Back to performance topic, here is a simple benchmark to get general understanding of threading and pooling impact. Note, that while pooling is a bit slower (you spend some time on pool operations), it allows you to isolate actions (so an error doesn't affect other threads) and use MULTI
and blocking commands.
这是我的结果(本地系统具有4个内核,远程系统CPU慢大约2倍):
Here are my results (local system has 4 cores, remote system CPU is about 2 times slower):
Benchmark (address) Mode Cnt Score Error Units
LettuceThreads.pooled socket thrpt 25 35389.995 ± 1325.198 ops/s
LettuceThreads.pooled localhost thrpt 25 32075.870 ± 416.220 ops/s
LettuceThreads.pooled remote thrpt 25 3883.193 ± 67.622 ops/s
LettuceThreads.shared socket thrpt 25 39419.772 ± 1966.023 ops/s
LettuceThreads.shared localhost thrpt 25 34293.245 ± 1737.349 ops/s
LettuceThreads.shared remote thrpt 25 3919.251 ± 49.897 ops/s
Threads = 2
Benchmark (address) Mode Cnt Score Error Units
LettuceThreads.pooled socket thrpt 25 56938.187 ± 2727.772 ops/s
LettuceThreads.pooled localhost thrpt 25 49420.748 ± 2091.631 ops/s
LettuceThreads.pooled remote thrpt 25 7791.706 ± 133.507 ops/s
LettuceThreads.shared socket thrpt 25 81195.900 ± 1593.424 ops/s
LettuceThreads.shared localhost thrpt 25 78404.688 ± 3878.044 ops/s
LettuceThreads.shared remote thrpt 25 3992.023 ± 39.092 ops/s
Threads = 4
Benchmark (address) Mode Cnt Score Error Units
LettuceThreads.pooled socket thrpt 25 87345.126 ± 8149.009 ops/s
LettuceThreads.pooled localhost thrpt 25 75003.031 ± 4481.289 ops/s
LettuceThreads.pooled remote thrpt 25 15807.410 ± 225.376 ops/s
LettuceThreads.shared socket thrpt 25 169112.489 ± 3749.897 ops/s
LettuceThreads.shared localhost thrpt 25 115464.778 ± 5099.728 ops/s
LettuceThreads.shared remote thrpt 25 7952.492 ± 133.521 ops/s
您可以在这里看到性能随线程数的增长而很好地扩展,因此生菜不是没有用的.
You can see here that performance scales very well with the number of threads, so lettuce is not useless.
这篇关于Redis是单线程的.那我为什么要用生菜呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!