Stackexchange.Redis .net-core 超时异常

Stackexchange.Redis timeout exception in .net-core

我正在将 net 4 库移植到 net-core 1.0.0-preview 2

它在开发我的 net-core 库时使用 Stackexchange.Redis 版本 1.2.1,net 4 版本使用 1.2.0。

在 net 4 中,我的库在调用 Redis 命令时从未失败过。

在net-core中,我随机得到这个错误:

 System.TimeoutException: Timeout performing GET netkey, inst: 6, queue: 10, qu: 0, qs: 10, qc: 0, wr: 0, wq: 0, in: 645, ar: 0, clientName: XXXXXX, serverEndpoint: Unspecified/XXXXXXX, keyHashSlot: XXXXX(Please take a look at this article for some common client-side issues that can cause timeouts: https://github.com/StackExchange/StackExchange.Redis/tree/master/Docs/Timeouts.md)
   at StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl[T](Message message, ResultProcessor`1 processor, ServerEndPoint server)
   at StackExchange.Redis.RedisBase.ExecuteSync[T](Message message, ResultProcessor`1 processor, ServerEndPoint server)
   at StackExchange.Redis.RedisDatabase.StringGet(RedisKey key, CommandFlags flags)

更新 我正在使用默认配置(连接超时、连接重试等)

更新 添加了保持活动配置但仍然失败

有什么想法吗?

您是否尝试过增加可用线程? (注意,这不是来自 .Net Core 项目,所以我不能 100% 确定语法相同。)

我在 Global.asax.cs

Application_Start 方法中有以下内容
private static int THREAD_MIN = 50; // 4 cores in production = 200
...                
//Per Redis docs, upping the number of threads available to handle the IO demands on the cloud.   
//https://github.com/StackExchange/StackExchange.Redis/blob/master/Docs/Timeouts.md 
ThreadPool.SetMinThreads(THREAD_MIN, THREAD_MIN);       

解决方案:将 SyncTimeout 配置更新为 10000。尝试使用 5000 失败,然后使用 10000 并修复。默认值为 1000。

更新的 SyncTimeout 不是一个好的选择,因为你的 redis 命令 运行ing 非常慢 超时的原因是线程池中的.net-core默认线程数太低。

只需在环境变量中设置 maxThreads。

例如:

ComPlus_ThreadPool_ForceMaxWorkerThreads 1000 ComPlus_ThreadPool_ForceMinWorkerThreads50

然后运行app以管理员身份(允许app读取系统环境变量)

对我有用

我在我的 ASP MVC .NET Core 2.1 项目中使用 Microsoft.Extensions.Caching.Redis (2.1.2),并且在从服务 [=] 调用同步方法 GetString(key) 时也有相同的 TimeoutException 12=]。解决方案是调用异步方法:

var val = await distributedCache.GetStringAsync(key)

问题不再出现。