【Azure Redis Cache】对StackExchange.Redis IOCP错误消息的解读

简介: 【Azure Redis Cache】对StackExchange.Redis IOCP错误消息的解读

问题描述

在使用StackExchange.Redis连接到Azure Redis服务时,时常出现StackExchange.Redis.RedisTimeoutException异常。

全部错误消息为:

 

关键信息为:

Timeout performing EXISTS (5000ms)

IOCP: (Busy=926, Free=1074,Min=200, Max=2000),

WORKER:(Busy=43,Free=32724,Min=200,Max=32767),

 

消息解读

执行EXISTS操作5000毫秒引起了RedisTimeoutException。 而关键信息为在执行IOCP(I/O Completion Port, IOCP threads are used when asynchronous IO happens, such as when reading from the network.) Busy线程数达到926,远远超过Min值200。参考Azure关于线程池增长的描述

一旦现有(Busy)线程数达到“Min”线程数,ThreadPool 便会将插入新线程的速率限制为每 500 毫秒一个线程。 通常情况下,如果系统中出现需要 IOCP 线程的突发工作,则它会快速处理该工作。 但是,如果突发工作多于配置的“Min”设置,则在处理某些工作时会出现一定的延迟,因为 ThreadPool 会等待发生以下两种情况之一。

  • 一个现有线程释放,以便处理工作。
  • 在 500 毫秒内没有任何现有线程释放,因此会创建一个新线程。

所以,如果 IOCP 线程受到限制,则 StackExchange.Redis 可以会超时。

 

解决办法

考虑到此信息,我们强烈建议客户将 IOCP 和辅助角色线程的最小配置值设置为大于默认值我们无法提供有关此值应是多少的通用指导,因为一个应用程序的合适值对于另一个应用程序可能会太高或太低。 此设置还可能会影响复杂应用程序其他部分的性能,因此每个客户需要按照其特定需求来微调此设置。 开始时设置为 200 或 300 会比较好,随后可进行测试并根据需要进行调整。

建议使用 global.asax.cs 中的 ThreadPool.SetMinThreads (...)法,以编程方式更改此设置。 例如

private readonly int minThreads = 200;
void Application_Start(object sender, EventArgs e)
{
    // Code that runs on application startup
    AreaRegistration.RegisterAllAreas();
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    BundleConfig.RegisterBundles(BundleTable.Bundles);
    ThreadPool.SetMinThreads(minThreads, minThreads);
}

备注

此 方法指定的值是全局设置,将影响整个 AppDomain。 例如,如果已有 4 核计算机,并想要在运行时将 minWorkerThreadsminIoThreads 设置为 50(每个 CPU),可使用 ThreadPool.SetMinThreads(200, 200) 。

 

参考资料

Azure Cache for Redis 管理常见问题解答 : https://docs.azure.cn/zh-cn/azure-cache-for-redis/cache-management-faq#important-details-about-threadpool-growth

相关文章
|
NoSQL 网络协议 Redis
【Azure Redis】AKS中使用Lettuce连接Redis Cache出现 timed out 问题的解决思路
【Azure Redis】AKS中使用Lettuce连接Redis Cache出现 timed out 问题的解决思路
638 1
【Azure Redis】AKS中使用Lettuce连接Redis Cache出现 timed out 问题的解决思路
|
NoSQL Redis 容器
【Azure Cache for Redis】Redis的导出页面无法配置Storage SAS时通过az cli来完成
【Azure Cache for Redis】Redis的导出页面无法配置Storage SAS时通过az cli来完成
219 3
|
NoSQL Unix 网络安全
【Azure Cache for Redis】Python Django-Redis连接Azure Redis服务遇上(104, 'Connection reset by peer')
【Azure Cache for Redis】Python Django-Redis连接Azure Redis服务遇上(104, 'Connection reset by peer')
247 0
【Azure Cache for Redis】Python Django-Redis连接Azure Redis服务遇上(104, 'Connection reset by peer')
|
存储 缓存 NoSQL
【Azure Redis 缓存】关于Azure Cache for Redis 服务在传输和存储键值对(Key/Value)的加密问题
【Azure Redis 缓存】关于Azure Cache for Redis 服务在传输和存储键值对(Key/Value)的加密问题
398 2
|
缓存 NoSQL Redis
【Azure Redis 缓存】Azure Cache for Redis 服务的导出RDB文件无法在自建的Redis服务中导入
【Azure Redis 缓存】Azure Cache for Redis 服务的导出RDB文件无法在自建的Redis服务中导入
298 0
|
缓存 开发框架 NoSQL
【Azure Redis 缓存】VM 里的 Redis 能直接迁移到 Azure Cache for Redis ? 需要改动代码吗?
【Azure Redis 缓存】VM 里的 Redis 能直接迁移到 Azure Cache for Redis ? 需要改动代码吗?
250 0
|
缓存 NoSQL Unix
【Azure Redis 缓存】Azure Cache for Redis 中如何快速查看慢指令情况(Slowlogs)
【Azure Redis 缓存】Azure Cache for Redis 中如何快速查看慢指令情况(Slowlogs)
242 0
|
缓存 NoSQL Redis
【Azure Redis 缓存】Azure Cache for Redis 是否记录具体读/写(Get/Set)或删除(Del)了哪些key呢?
【Azure Redis 缓存】Azure Cache for Redis 是否记录具体读/写(Get/Set)或删除(Del)了哪些key呢?
355 0
|
存储 缓存 NoSQL
【Azure Redis 缓存】Azure Cache for Redis 专用终结点, 虚拟网络, 公网访问链路
【Azure Redis 缓存】Azure Cache for Redis 专用终结点, 虚拟网络, 公网访问链路
252 0
|
存储 缓存 NoSQL
【Azure Redis 缓存】Azure Cache for Redis服务中,除开放端口6379,6380外,对13000,13001,15000,15001 为什么也是开放的呢?
【Azure Redis 缓存】Azure Cache for Redis服务中,除开放端口6379,6380外,对13000,13001,15000,15001 为什么也是开放的呢?
437 0