StackExchange.Redis超时
StackExchange.Redis timeout
生产环境在 Azure 上,使用 Redis Cache Standard 2.5GB
。
示例 1
System.Web.HttpUnhandledException (0x80004005): Exception of type
'System.Web.HttpUnhandledException' was thrown. --->
StackExchange.Redis.RedisTimeoutException: Timeout performing 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, clientName: PRD-VM-WEB-2,
serverEndpoint: Unspecified/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) (Please take a look at this
article for some common client-side issues that can cause timeouts:
http://stackexchange.github.io/StackExchange.Redis/Timeouts) at
StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl[T](Message
message, ResultProcessor1 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 processor, ServerEndPoint server) in
c:\code\StackExchange.Redis\StackExchange.Redis\StackExchange\Redis\RedisBase.cs:line
81
示例 2
StackExchange.Redis.RedisTimeoutException: Timeout performing 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: Unspecified/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) (Please take a look at this
article for some common client-side issues that can cause timeouts:
http://stackexchange.github.io/StackExchange.Redis/Timeouts) at
StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl[T](Message
message, ResultProcessor1 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 processor, ServerEndPoint server) in
c:\code\StackExchange.Redis\StackExchange.Redis\StackExchange\Redis\RedisBase.cs:line
81 at StackExchange.Redis.RedisDatabase.StringGet(RedisKey key,
CommandFlags flags) in
c:\code\StackExchange.Redis\StackExchange.Redis\StackExchange\Redis\RedisDatabase.cs:line
1647 at
C3.Code.Controls.Application.Caching.Distributed.DistributedCacheController.Get[T](String
cacheKey) in
C:\Construct.net\Source\C3Alpha2\Code\Controls\Application\Caching\Distributed\DistributedCacheController.cs:line
115 at
C3.Code.Controls.Application.Caching.Manager.Manager.Get[T](String
key, Func`1 getFromExternFunction, Boolean skipLocalCaches) in
C:\Construct.net\Source\C3Alpha2\Code\Controls\Application\Caching\Manager\Manager.cs:line
159 at C3.PageControls.Forums.TopicRender.Page_Load(Object sender,
EventArgs e) in
C:\Construct.net\Source\C3Alpha2\PageControls\Forums\TopicRender.ascx.cs:line
40 at System.Web.UI.Control.OnLoad(EventArgs e) at
System.Web.UI.Control.LoadRecursive() at
System.Web.UI.Control.LoadRecursive() at
System.Web.UI.Control.LoadRecursive() at
System.Web.UI.Control.LoadRecursive() at
System.Web.UI.Control.LoadRecursive() at
System.Web.UI.Control.LoadRecursive() at
System.Web.UI.Control.LoadRecursive() at
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
这些错误是零星的,一天几次。
这是 Azure 网络问题,还是我可以减少的问题?查看错误中的数字似乎没有任何异常,服务器负载似乎从未超过 Azure 报告的 7%。
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;
}
打开网络流量监视器以confirm/deny blip.have 解决问题的方法,但很粗糙。选项 1 - 尝试在 azure 中重新启动托管的 redis 实例。
延迟连接
作为最佳实践,请确保您使用以下模式连接到 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 和 WORKER 线程的最小配置值设置为大于默认值的值。对于该值应该是多少,没有一刀切的指导,因为一个应用程序的正确值对于另一个应用程序来说太 high/low 了。一个好的起点是 200 或 300,然后根据需要进行测试和调整。
如何配置此设置:
- 在ASP.NET中,使用machine.config中
<processModel>
配置元素下的minIoThreads
配置设置。根据 Microsoft 的说法,您无法通过编辑 web.config 来更改每个站点的此值(即使您过去可以这样做),因此您在此处选择的值是所有 .NET 站点都将使用的值采用。请注意,如果将 autoConfig 设置为 false,则不需要添加每个 属性,只需添加 autoConfig="false"
并覆盖该值就足够了:
<processModel autoConfig="false" minIoThreads="250" />
Important Note: the value specified in this configuration element is a per-core setting. For example, if you have a 4 core machine and want your minIOThreads setting to be 200 at runtime, you would use <processModel minIoThreads="50"/>
.
- ASP.NET以外,使用ThreadPool.SetMinThreads()API.
- 在 .Net Core 中,根据 Environment/Registry Configuration Knobs 添加环境变量 COMPlus_ThreadPool_ForceMinWorkerThreads 以覆盖默认的 MinThreads 设置 - 您也可以使用相同的
ThreadPool.SetMinThreads()
方法如上所述。
来源:
我的猜测是网络稳定性存在问题 - 因此超时。
因为没有人提到 responseTimeout
的增加,所以我会尝试一下。默认值为50ms,可以轻松达到。我会在 200ms 左右尝试一下,看看是否对消息有帮助。
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()
?
14.12.2021 - 更新
在stackexchange.redis v2.2.4中:为
给出以下内容
'responseTimeout' : Warning CS0618
'ConfigurationOptions.ResponseTimeout' is obsolete: 'This setting no
longer has any effect, and should not be used
更新由 MX313
发送
有 3 种情况会导致超时,很难知道是哪种情况:
- 图书馆被绊倒了;特别是,存在与 TLS 实施以及我们如何处理库的 v1.* 版本中的读取循环相关的已知问题 - 我们已经投入了 很多 的时间来解决这个问题对于 v2.*(但是:not 更新到 v2 总是微不足道的,特别是如果您将该库用作依赖于特定版本的其他代码的一部分)
- server/network 被绊倒了;这是一个非常真实的可能性 - 如果它是服务器端的,查看 "slowlog" 会有所帮助,但我没有任何可见性
- 服务器和网络都很好,图书馆也在尽其所能,但是客户端和服务器之间有一些巨大的斑点在延迟其他操作;这是我正在做的更改以帮助识别现在,如果这表明它本身是一个常见问题,我们也许会考虑更好地利用并发连接(不会增加带宽,但可以减少阻塞操作的延迟)——这将是一个仅 v2 的变化,注意
生产环境在 Azure 上,使用 Redis Cache Standard 2.5GB
。
示例 1
System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> StackExchange.Redis.RedisTimeoutException: Timeout performing 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, clientName: PRD-VM-WEB-2, serverEndpoint: Unspecified/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) (Please take a look at this article for some common client-side issues that can cause timeouts: http://stackexchange.github.io/StackExchange.Redis/Timeouts) at StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl[T](Message message, ResultProcessor
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 processor, ServerEndPoint server) in c:\code\StackExchange.Redis\StackExchange.Redis\StackExchange\Redis\RedisBase.cs:line 81
示例 2
StackExchange.Redis.RedisTimeoutException: Timeout performing 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: Unspecified/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) (Please take a look at this article for some common client-side issues that can cause timeouts: http://stackexchange.github.io/StackExchange.Redis/Timeouts) at StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl[T](Message message, ResultProcessor
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 processor, ServerEndPoint server) in c:\code\StackExchange.Redis\StackExchange.Redis\StackExchange\Redis\RedisBase.cs:line 81 at StackExchange.Redis.RedisDatabase.StringGet(RedisKey key, CommandFlags flags) in c:\code\StackExchange.Redis\StackExchange.Redis\StackExchange\Redis\RedisDatabase.cs:line 1647 at C3.Code.Controls.Application.Caching.Distributed.DistributedCacheController.Get[T](String cacheKey) in C:\Construct.net\Source\C3Alpha2\Code\Controls\Application\Caching\Distributed\DistributedCacheController.cs:line 115 at C3.Code.Controls.Application.Caching.Manager.Manager.Get[T](String key, Func`1 getFromExternFunction, Boolean skipLocalCaches) in C:\Construct.net\Source\C3Alpha2\Code\Controls\Application\Caching\Manager\Manager.cs:line 159 at C3.PageControls.Forums.TopicRender.Page_Load(Object sender, EventArgs e) in C:\Construct.net\Source\C3Alpha2\PageControls\Forums\TopicRender.ascx.cs:line 40 at System.Web.UI.Control.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
这些错误是零星的,一天几次。
这是 Azure 网络问题,还是我可以减少的问题?查看错误中的数字似乎没有任何异常,服务器负载似乎从未超过 Azure 报告的 7%。
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;
}
打开网络流量监视器以confirm/deny blip.have 解决问题的方法,但很粗糙。选项 1 - 尝试在 azure 中重新启动托管的 redis 实例。
延迟连接
作为最佳实践,请确保您使用以下模式连接到 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 和 WORKER 线程的最小配置值设置为大于默认值的值。对于该值应该是多少,没有一刀切的指导,因为一个应用程序的正确值对于另一个应用程序来说太 high/low 了。一个好的起点是 200 或 300,然后根据需要进行测试和调整。
如何配置此设置:
- 在ASP.NET中,使用machine.config中
<processModel>
配置元素下的minIoThreads
配置设置。根据 Microsoft 的说法,您无法通过编辑 web.config 来更改每个站点的此值(即使您过去可以这样做),因此您在此处选择的值是所有 .NET 站点都将使用的值采用。请注意,如果将 autoConfig 设置为 false,则不需要添加每个 属性,只需添加autoConfig="false"
并覆盖该值就足够了:<processModel autoConfig="false" minIoThreads="250" />
Important Note: the value specified in this configuration element is a per-core setting. For example, if you have a 4 core machine and want your minIOThreads setting to be 200 at runtime, you would use
<processModel minIoThreads="50"/>
.
- ASP.NET以外,使用ThreadPool.SetMinThreads()API.
- 在 .Net Core 中,根据 Environment/Registry Configuration Knobs 添加环境变量 COMPlus_ThreadPool_ForceMinWorkerThreads 以覆盖默认的 MinThreads 设置 - 您也可以使用相同的
ThreadPool.SetMinThreads()
方法如上所述。
来源:
我的猜测是网络稳定性存在问题 - 因此超时。
因为没有人提到 responseTimeout
的增加,所以我会尝试一下。默认值为50ms,可以轻松达到。我会在 200ms 左右尝试一下,看看是否对消息有帮助。
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()
?
14.12.2021 - 更新
在stackexchange.redis v2.2.4中:为
给出以下内容'responseTimeout' : Warning CS0618 'ConfigurationOptions.ResponseTimeout' is obsolete: 'This setting no longer has any effect, and should not be used
更新由 MX313
发送有 3 种情况会导致超时,很难知道是哪种情况:
- 图书馆被绊倒了;特别是,存在与 TLS 实施以及我们如何处理库的 v1.* 版本中的读取循环相关的已知问题 - 我们已经投入了 很多 的时间来解决这个问题对于 v2.*(但是:not 更新到 v2 总是微不足道的,特别是如果您将该库用作依赖于特定版本的其他代码的一部分)
- server/network 被绊倒了;这是一个非常真实的可能性 - 如果它是服务器端的,查看 "slowlog" 会有所帮助,但我没有任何可见性
- 服务器和网络都很好,图书馆也在尽其所能,但是客户端和服务器之间有一些巨大的斑点在延迟其他操作;这是我正在做的更改以帮助识别现在,如果这表明它本身是一个常见问题,我们也许会考虑更好地利用并发连接(不会增加带宽,但可以减少阻塞操作的延迟)——这将是一个仅 v2 的变化,注意