代码之家  ›  专栏  ›  技术社区  ›  Tom Gullen

stackexchange.redis超时

  •  14
  • Tom Gullen  · 技术社区  · 8 年前

    生产环境在Azure上,使用 Redis Cache Standard 2.5GB .

    实施例1

    system.web.httpunhandledException(0x80004005):类型的异常 引发了“System.Web.HttpUnhandledException”。---> stackexchange.redis.redistimeoutexception:执行setnx超时 user.313123,inst:49,mgr:inactive,err:never,queue:0,qu:0,qs: 0,qc:0,wr:0,wq:0,in:0,ar:0,客户名称:prd-vm-web-2, serverEndpoint:未指定/construct3.redis.cache.windows.net:6380, keyhashslot:15649,iocp:(busy=0,free=1000,min=1,max=1000),worker: (busy=1,free=32766,min=1,max=32767)(请看这个 有关可能导致超时的一些常见客户端问题的文章: http://stackexchange.github.io/StackExchange.Redis/Timeouts AT stackexchange.redis.connectionmultiplexer.executesyncImpl[t](消息) 消息,结果处理器 1 processor, ServerEndPoint server) in c:\code\StackExchange.Redis\StackExchange.Redis\StackExchange\Redis\ConnectionMultiplexer.cs:line 2120 at StackExchange.Redis.RedisBase.ExecuteSync[T](Message message, ResultProcessor 1个处理器,服务器端点服务器)在 C:\code\stackexchange.redis\stackexchange.redis\stackexchange\redis\redisbase.cs:line 八十一

    实施例2

    stackexchange.redis.redistimeoutexception:执行get时超时 forumtopic.33831,inst:1,mgr:inactive,err:never,queue:2,qu:0, qs:2,qc:0,wr:0,wq:0,in:0,ar:0,clientname:prd-vm-web-2, serverEndpoint:未指定/construct3.redis.cache.windows.net:6380, keyhashslot:5851,iocp:(busy=0,free=1000,min=1,max=1000),worker: (busy=1,free=32766,min=1,max=32767)(请看这个 有关可能导致超时的一些常见客户端问题的文章: http://stackexchange.github.io/stackexchange.redis/超时 )在 stackexchange.redis.connectionmultiplexer.executesyncImpl[t](消息) 消息,结果处理器 1 processor, ServerEndPoint server) in c:\code\StackExchange.Redis\StackExchange.Redis\StackExchange\Redis\ConnectionMultiplexer.cs:line 2120 at StackExchange.Redis.RedisBase.ExecuteSync[T](Message message, ResultProcessor 1个处理器,服务器端点服务器)在 C:\code\stackexchange.redis\stackexchange.redis\stackexchange\redis\redisbase.cs:line 81在stackexchange.redis.redisdatabase.stringget(redisky key, commandflags flags)在 C:\code\stackexchange.redis\stackexchange.redis\stackexchange\redis\redisdatabase.cs:line 1647年 c3.code.controls.application.caching.distributed.distributedcacheController.get[t](字符串) cachekey)在 C:\construct.net\source\c3alpha2\code\controls\application\caching\distributed\distributedcacheController.cs:line 115在 c3.code.controls.application.caching.manager.manager.get[t](字符串) 键,func`1 getFromExternanFunction,Boolean SkiploCalcChies)in C:\construct.net\source\c3alpha2\code\controls\application\caching\manager\manager.cs:line 159,位于c3.pagecontrols.forums.topicrender.page_load(对象发送器, 事件参数e)in C:\construct.net\source\c3alpha2\pagecontrols\forums\topicrender.ascx.cs:line 40 at system.web.ui.control.onload(事件参数e)at system.web.ui.control.loadRecursive()位于 system.web.ui.control.loadRecursive()位于 system.web.ui.control.loadRecursive()位于 system.web.ui.control.loadRecursive()位于 system.web.ui.control.loadRecursive()位于 system.web.ui.control.loadRecursive()位于 system.web.ui.control.loadRecursive()位于 system.web.ui.page.processRequestMain(布尔值 includeStagesBeforeAsyncPoint,boolean includeStagesAfterAsyncPoint)

    这些错误是零星的,一天几次。

    这是一个Azure网络Blip,还是我可以减少的?查看错误中的数字似乎没有什么异常,而且服务器负载似乎从未超过7%,如Azure报告的那样。

    Redis连接

    internal static class RedisController
    {
        private static readonly object GetConnectionLock = new object();
        public static ConnectionMultiplexer GetConnection()
        {
            if (Global.RedisConnection == null)
            {
                lock (GetConnectionLock)
                {
                    if (Global.RedisConnection == null)
                    {
                        Global.RedisConnection = ConnectionMultiplexer.Connect(
                            Settings.Deployment.RedisConnectionString);
                    }
                }
            }
            return Global.RedisConnection;
        }
    
    4 回复  |  直到 7 年前
        1
  •  4
  •   Marc Gravell    7 年前

    有3种情况会导致超时,很难知道哪种情况在起作用:

    1. 库正在被绊倒;特别是,有一些已知的问题与TLS实现以及我们如何在v1.*版本的库中处理读取循环有关-我们已经投资了 许多 为V2工作的时间*(但是: 更新到v2总是很简单的,特别是当您将库作为依赖于特定版本的其他代码的一部分使用时)
    2. 服务器/网络正在被绊倒;这是一个非常现实的可能性——如果“slowlog”是服务器端的,那么它会有帮助,但我对此没有任何可见性。
    3. 服务器和网络都很好,库正在尽其所能地工作,但是在客户机和服务器之间有一些巨大的斑点正在延迟其他操作;这是我正在进行更改以帮助识别 马上 ,如果这表明自己是一个常见的问题,我们可能会考虑更好地利用并发连接(这不会增加带宽,但可以减少阻塞操作的延迟)-注意,这只是一个版本2的更改
        2
  •  3
  •   janniks    7 年前

    延迟连接

    作为最佳实践,请确保使用以下模式连接到StackExchange Redis客户端:

    private static Lazy<ConnectionMultiplexer> lazyConnection = new Lazy<ConnectionMultiplexer>(() => {
        return ConnectionMultiplexer.Connect("cachename.redis.cache.windows.net,ssl=true,abortConnect=false,password=password");
    });
    
    public static ConnectionMultiplexer Connection {
        get {
            return lazyConnection.Value;
        }
    }
    

    如果上述方法不起作用,则在 Source 1 关于区域、带宽和nuget包版本等。

    IO线程

    另一种选择是增加最小IO线程数。它通常建议将IOCP和工作线程的最小配置值设置为大于默认值的值。由于一个应用程序的正确值对于另一个应用程序来说太高/太低,因此没有一个大小适合所有关于该值应该是什么的指导。一个好的起点是200或300,然后根据需要进行测试和调整。

    如何配置此设置:

    • ASP.NET ,使用 minIoThreads 配置设置在 <processModel> machine.config中的配置元素。根据Microsoft的说法,您可以通过编辑web.config(即使在过去也可以这样做)来更改每个站点的该值,因此您在此处选择的值是所有.NET站点将使用的值。请注意,如果autoconfig设置为false,则无需添加每个属性,只需将 autoConfig="false" 覆盖这个值就足够了: <processModel autoConfig="false" minIoThreads="250" />

    重要提示: 此配置元素中指定的值是每个核心的设置。例如,如果您有一台4核机器,并且希望运行时MiniothReads设置为200,那么您将使用 <processModel minIoThreads="50"/> .

    资料来源:

    1. Microsoft Azure - Investigating timeout exceptions in StackExchange.Redis for Azure Redis Cache
    2. StackExchange.Redis
        3
  •  0
  •   Srini Sydney    7 年前

    打开网络流量监视器以确认/拒绝该blip。对该问题有一个解决方案,但只是一个粗略的解决方案。选项1-尝试在Azure中重新启动托管Redis Instamce。

        4
  •  0
  •   tukan    7 年前

    我的猜测是网络稳定性存在问题——因此超时。

    因为没有人提到 responseTimeout 我会到处玩的。默认值为 50ms 很容易到达。我想试试看 200毫秒 看看这是否有助于传递信息。

    取自 configuration options :

    responseTimeout={int}   ResponseTimeout     SyncTimeout     Time (ms) to decide whether the socket is unhealthy
    

    在GitHub上有多个问题。把一切结合起来的那一个可能是 #871 The "network stability" / 2.0 / "pipelines" rollup issue

    还有一件事:你有没有试着和 ConnectionMultiplexer.ConnectAsync() 相反 ConnectionMultiplexer.Connect() ?