简体   繁体   中英

How can I fix this timeout exception in Azure redis cache?

We have a web application which uses Microsoft.Web.Redis.RedisSessionStateProvider as the session state provider. We've had no problems with this until recently when suddenly the application is reporting a large number of exceptions as detailed below.

The message suggests some kind of timeout. But I've no idea how to resolve this. The application is an instance of Kentico CMS and we haven't customised its session caching mechanism in any way.

Main exception:

Message:

Exception of type 'System.Web.HttpException' was thrown.

Stack Trace:

at System.Web.HttpAsyncResult.End() 
at System.Web.HttpApplication.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) 

Inner exception:

Message:

Timeout performing EVAL, inst: 1, mgr: Inactive, err: never, queue: 0, qu: 0, qs: 0, qc: 0, wr: 0, wq: 0, in: 0, ar: 0, IOCP: (Busy=0,Free=1000,Min=2,Max=1000), WORKER: (Busy=3,Free=32764,Min=2,Max=32767), clientName: KSCOMAZUATWEB2

Stack Trace:

at StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl[T](Message message, ResultProcessor`1 processor, ServerEndPoint server) in c:\TeamCity\buildAgent\work\3ae0647004edff78\StackExchange.Redis\StackExchange\Redis\ConnectionMultiplexer.cs:line 1927 
at StackExchange.Redis.RedisBase.ExecuteSync[T](Message message, ResultProcessor`1 processor, ServerEndPoint server) in c:\TeamCity\buildAgent\work\3ae0647004edff78\StackExchange.Redis\StackExchange\Redis\RedisBase.cs:line 80 
at StackExchange.Redis.RedisDatabase.ScriptEvaluate(String script, RedisKey[] keys, RedisValue[] values, CommandFlags flags) in c:\TeamCity\buildAgent\work\3ae0647004edff78\StackExchange.Redis\StackExchange\Redis\RedisDatabase.cs:line 866 
at Microsoft.Web.Redis.StackExchangeClientConnection.<>c__DisplayClass4.<Eval>b__3() in d:\TeamCityBuildAgent\work\f55792526e6d9089\src\Shared\StackExchangeClientConnection.cs:line 113 
at Microsoft.Web.Redis.StackExchangeClientConnection.RetryForScriptNotFound(Func`1 redisOperation) in d:\TeamCityBuildAgent\work\f55792526e6d9089\src\Shared\StackExchangeClientConnection.cs:line 129 
at Microsoft.Web.Redis.StackExchangeClientConnection.RetryLogic(Func`1 redisOperation) in d:\TeamCityBuildAgent\work\f55792526e6d9089\src\Shared\StackExchangeClientConnection.cs:line 155 
at Microsoft.Web.Redis.StackExchangeClientConnection.Eval(String script, String[] keyArgs, Object[] valueArgs) in d:\TeamCityBuildAgent\work\f55792526e6d9089\src\Shared\StackExchangeClientConnection.cs:line 113 
at Microsoft.Web.Redis.RedisConnectionWrapper.TryTakeWriteLockAndGetData(DateTime lockTime, Int32 lockTimeout, Object& lockId, ISessionStateItemCollection& data, Int32& sessionTimeout) in d:\TeamCityBuildAgent\work\f55792526e6d9089\src\RedisSessionStateProvider\RedisConnectionWrapper.cs:line 182 
at Microsoft.Web.Redis.RedisSessionStateProvider.GetItemFromSessionStore(Boolean isWriteLockRequired, HttpContext context, String id, Boolean& locked, TimeSpan& lockAge, Object& lockId, SessionStateActions& actions) in d:\TeamCityBuildAgent\work\f55792526e6d9089\src\RedisSessionStateProvider\RedisSessionStateProvider.cs:line 272 
at Microsoft.Web.Redis.RedisSessionStateProvider.GetItemExclusive(HttpContext context, String id, Boolean& locked, TimeSpan& lockAge, Object& lockId, SessionStateActions& actions) in d:\TeamCityBuildAgent\work\f55792526e6d9089\src\RedisSessionStateProvider\RedisSessionStateProvider.cs:line 190 
at System.Web.SessionState.SessionStateModule.GetSessionStateItem() 
at System.Web.SessionState.SessionStateModule.PollLockedSessionCallback(Object state) 

After experiencing the same issue and having read various posts on setting min & max thread values etc, it transpired that the issue was with the subscription tier.

C1 basic (£35/GBP mth) boasts a 1gb cache, 1000 concurrent connections which are exactly the same headline figures as the C1 Standard tier (£95GBP/Mth). It's a natural assumption that when you only require a few MB of cache and have only 50 concurrent sessions active at any point, that the C! basic would be adequate, if not overkill.

The difference seems to be that C1 Basic works, if you have 10 or less concurrent users on your website. In fairness, it is mentioned in the fine print that the basic is only suitable for development and testing environments.

I was just working through this on a client site and what helped me was to add this to the connection string of your provider:

throwOnError="true" retryTimeoutInMilliseconds="500"

What I learned is sometimes there is a latency issue and if it doesn't resolve fast enough the default is to just "quit". So adding this allows it to continue to retry.

Your string might look like this

<add name="MySessionStateStore" throwOnError="true" retryTimeoutInMilliseconds="500" type="Microsoft.Web.Redis.RedisSessionStateProvider" host="mysite-prod.redis.cache.windows.net" accessKey="mykey" ssl="true" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM