StackExchange.Redis.RedisTimeoutException:等待响应超时 [英] StackExchange.Redis.RedisTimeoutException: Timeout awaiting response

查看:86
本文介绍了StackExchange.Redis.RedisTimeoutException:等待响应超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Redis 集群,有 6 个实例,3 个主节点和 3 个从节点.我的 ASP .NET Core 应用程序将其用作缓存.有时我会收到这样的错误:

I have a Redis cluster of 6 instances, 3 master and 3 slaves. My ASP .NET Core application uses it as a cache. Sometimes I get such an error:

StackExchange.Redis.RedisTimeoutException:等待响应超时(出站=0KiB,入站=5KiB,5504 毫秒已过,超时为 5000 毫秒),命令=GET,下一步:GET CRM.UsersMainService.GetUserInfoAsync.vvs1@domain.org, inst: 0, qu: 0, qs: 6, aw: False, rs: DequeueResult, ws: Idle, in: 0, in-pipe: 5831, out-pipe: 0, serverEndpoint: 5.178.85.30:7002, mgr: 9 of 10 可用, clientName: f0b7b81f5ce5, PerfCounterHelperkeyHashSlot: 9236, IOCP: (Busy=0,Free=1000,Min=2,Max=1000), WORKER: (Busy=10,Free=32757,Min=2,Max=32767), v: 2.0.601.3402(请查看这篇文章,了解一些可能导致超时的常见客户端问题:https://stackexchange.github.io/StackExchange.Redis/Timeouts)(最近一次调用最后一次)

推荐答案

正如我从您的异常消息中看到的,您的最小工作进程数对于您拥有的流量来说太低了.

As I can see from your exception message, your minimum worker process count is too low for the traffic you have.

工人:(忙碌=10,空闲=32757,最小=2,最大=32767)

WORKER: (Busy=10,Free=32757,Min=2,Max=32767)

发生此异常时,您有 10 个繁忙的工作线程,而您有 2 个工作线程用于启动.

You had 10 busy worker threads when this exception happened, while you had 2 worker threads for start.

当您的应用程序用完可用线程来完成操作时,.NET 会启动一个新线程(当然,直到最大值为止).并稍等片刻,看看是否需要额外的工作线程.如果您的应用程序仍然需要工作线程,那么 .NET 会启动另一个工作线程.然后一个,然后另一个……但这需要时间.它不会在 0 毫秒内发生.通过查看您的异常消息,我们可以看到 .NET 创建了 8 个额外的工作线程 (10 - 2 = 8).在创建过程中,这个特定的 Redis 操作已经等待并最终超时.

When your application runs out of available threads to complete an operation, .NET starts a new one (until maximum value, of course). And waits a bit to see if an additional worker thread is needed. If your application still needs worker threads, then .NET starts another one. Then another, then another... But this requires time. It doesn't occur in 0 ms. By looking your exception message, we can see that .NET had created 8 additional worker threads (10 - 2 = 8). While the creation process, this particular Redis operation had waited and eventually timed out.

您可以在应用程序的开头使用 ThreadPool.SetMinThreads(Int32, Int32) 方法来设置最小线程数.我建议您从 ThreadPool.SetMinThreads(10, 10) 开始,并在测试时对其进行调整.

You could use ThreadPool.SetMinThreads(Int32, Int32) method at the beginning of your application to set minimum thread count. I suggest you to start with ThreadPool.SetMinThreads(10, 10) and tweak it as you test it.

额外阅读:

https://docs.microsoft.com/en-us/dotnet/api/system.threading.threadpool.setminthreadshttps://stackexchange.github.io/StackExchange.Redis/Timeouts.html

这篇关于StackExchange.Redis.RedisTimeoutException:等待响应超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆