redis (StackExchange.Redis) 发布性能差?
redis (StackExchange.Redis) publish performance is poor?
我正在尝试使用 Redis pub/sub 在应用程序之间高速传输数据(每秒 25000 条消息)。
我已经测试如下:
拓扑结构:
1 个发布者、1 个订阅者和 Redis 服务器。所有都托管在同一台电脑上。
电脑硬件:
CPU: Intel(R) Core(TM) I7-4578U CPU@3.00GHz
内存: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();
结果:
如结果所示,发布10k条消息大约需要6秒。
我想确认是redis(或StackExchange.Redis)的实际性能吗?还是我的测试有问题?
更新:
根据接受的答案,我发现原因是我的消息大小太大 (300kB)。
要检查的事项:
- CPU 负载是多少?满了吗?如果没有,您可能遇到带宽或延迟问题。
- 邮件的大小是多少?乘以转移
你看到的速率,它是否与你(期望)的带宽相当
有吗?
- Redis 实例的 ping 是什么?也许往返需要很多时间。在那种情况下,您可以使用具有多个连接的多个线程来增加吞吐量。
我手头有一个用来回答另一个问题的基准。在 Java(生菜客户端库)中,我有 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
将它与您拥有的硬件进行比较,也许它会帮助您评估库的性能。请注意,远程性能如何下降 10 倍,即使知道 CPU 慢 2 倍,也很多。
而下面是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
我正在尝试使用 Redis pub/sub 在应用程序之间高速传输数据(每秒 25000 条消息)。
我已经测试如下:
拓扑结构:
1 个发布者、1 个订阅者和 Redis 服务器。所有都托管在同一台电脑上。
电脑硬件:
CPU: Intel(R) Core(TM) I7-4578U CPU@3.00GHz 内存: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();
结果:
如结果所示,发布10k条消息大约需要6秒。
我想确认是redis(或StackExchange.Redis)的实际性能吗?还是我的测试有问题?
更新:
根据接受的答案,我发现原因是我的消息大小太大 (300kB)。
要检查的事项:
- CPU 负载是多少?满了吗?如果没有,您可能遇到带宽或延迟问题。
- 邮件的大小是多少?乘以转移 你看到的速率,它是否与你(期望)的带宽相当 有吗?
- Redis 实例的 ping 是什么?也许往返需要很多时间。在那种情况下,您可以使用具有多个连接的多个线程来增加吞吐量。
我手头有一个用来回答另一个问题的基准。在 Java(生菜客户端库)中,我有 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
将它与您拥有的硬件进行比较,也许它会帮助您评估库的性能。请注意,远程性能如何下降 10 倍,即使知道 CPU 慢 2 倍,也很多。
而下面是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