Redis(StackExchange.Redis)发布性能差?

3

我正在尝试使用Redis pub/sub在应用程序之间传输数据,速度很快(每秒25000条消息)。

我已经进行了以下测试:

拓扑结构

1个发布者、1个订阅者和Redis服务器。所有这些都托管在同一台计算机上。

计算机硬件

CPU: Intel(R) Core(TM) I7-4578U CPU@3.00GHz Memory: 16.0GB

代码

Stopwatch sw = new Stopwatch();
sw.Start();
while (_started)
{
    //db.PublishAsync(RawMessagesCapturedMsg.TopicGroupName, redisValue);
    db.Publish(RawMessagesCapturedMsg.TopicGroupName, redisValue);
    totalRedisMsg++;
    if (totalRedisMsg % 10000 == 0)
    {
        Console.WriteLine("totalRedisMsg: {0} @ {1}, time used(ms): {2}",
            totalRedisMsg, DateTime.Now, sw.ElapsedMilliseconds);
    }
}
sw.Stop();
结果: enter image description here

根据结果显示,发布10k条消息需要约6秒时间。

我想确认一下,这是Redis(或StackExchange.Redis)的实际表现吗?还是我的测试有问题?

更新:

根据被采纳的答案,我发现原因是我的消息大小太大(300kB)。

1个回答

3

需要检查的事项:

  1. CPU负载是多少?是否已满?如果没有,那么可能卡在带宽或延迟上。
  2. 消息大小是多少?将其乘以您看到的传输速率,与您(期望)拥有的带宽相比如何?
  3. Redis实例的ping值是多少?也许往返时间太长了。在这种情况下,您可以使用多个线程和多个连接来增加吞吐量。

我手头有一个基准测试,用于回答另一个问题。在Java(lettuce客户端库)中,我对1个线程、本地CPU i5-6400、远程CPU E5-2603 v4、0.180ms的远程ping和消息为“hello”的结果如下。

Benchmark              (address)   Mode  Cnt      Score      Error  Units
LettuceThreads.pooled     socket  thrpt    5  35699.267 ±  706.946  ops/s
LettuceThreads.pooled  localhost  thrpt    5  28130.801 ± 9476.584  ops/s
LettuceThreads.pooled     remote  thrpt    5   3080.115 ±  422.390  ops/s
LettuceThreads.shared     socket  thrpt    5  41717.332 ± 3559.226  ops/s
LettuceThreads.shared  localhost  thrpt    5  31092.925 ± 9894.748  ops/s
LettuceThreads.shared     remote  thrpt    5   3920.260 ±  178.637  ops/s

将其与您拥有的硬件进行比较,也许可以帮助您评估库性能。请注意,即使知道 CPU 速度慢了 2 倍,远程性能下降了 10 倍,这是很多的。

以下内容适用于 16 个线程。因此,正如您所看到的,更多的线程数量可能会帮助至少获得吞吐量,尽管存在延迟。

Benchmark              (address)   Mode  Cnt       Score       Error  Units
LettuceThreads.pooled     socket  thrpt    5  123846.426 ±  2926.807  ops/s
LettuceThreads.pooled  localhost  thrpt    5   83997.678 ± 31410.595  ops/s
LettuceThreads.pooled     remote  thrpt    5   31045.111 ±  2198.065  ops/s
LettuceThreads.shared     socket  thrpt    5  218331.662 ± 17459.352  ops/s
LettuceThreads.shared  localhost  thrpt    5  182296.689 ± 52163.154  ops/s
LettuceThreads.shared     remote  thrpt    5   30803.575 ±  2128.306  ops/s

根据你的回答,我发现我的消息大小非常大(300KB)。在阅读了你的帖子之前,我没有注意到这一点。你救了我的一天,非常感谢! - ricky
很高兴能帮到你!您可以在您的问题中添加“性能”标签吗? - Imaskar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接