Redis is single thread. Then why should I use lettuce?

后端 未结 1 1828
野性不改
野性不改 2021-01-15 19:16

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

So

相关标签:
1条回答
  • 2021-01-15 20:18

    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.

    And luttece is not only about speed. It also helps you organize your code better with asynchronous and reactive API.

    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.

    Here are my results (local system has 4 cores, remote system CPU is about 2 times slower):

    Threads=1

    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.

    0 讨论(0)
提交回复
热议问题