Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stackexchange.Redis timeout exception in .net-core

I'm porting a net 4 library to net-core 1.0.0-preview 2

It is using Stackexchange.Redis version 1.2.1 when developing my net-core library, and 1.2.0 for the net 4 version.

In net 4, my library has never failed when calling Redis commands.

In net-core, I get this error randomly:

 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)

UPDATE I'm using default configurations (connection timeout, connection retry, etc)

UPDATE Added keep-alive configuration but still failing

Any ideas?

like image 561
Jawen Avatar asked Mar 22 '17 15:03

Jawen


People also ask

What causes Redis timeout?

Redis client uses a single TCP connection and can only read one response at a time. Even when a first operation times out, it does not stop the data being sent to/from the server. Because of this, it blocks other requests and causes timeouts.

How do I change timeout in Redis?

To set an expiration time for an existing key in Redis, use the EXPIRE command. This command takes the key and the duration in seconds to assign to the specified key. The following examples illustrate how to use the EXPIRE command in Redis. The command above will create a new key and value.

What is the default timeout for Redis cache?

Azure Cache for Redis service configures a 10 minute idle server timeout for connections, independently of the client library used. This is defined on Server side and cannot be changed.

What is Redis ConnectionMultiplexer?

The ConnectionMultiplexer is the main arbiter of the connection to Redis inside the CLR, your application should maintain a single instance of the ConnectionMultiplexer throughout its runtime. You can initialize the Multiplexer with either a connection string, or with a ConfigurationOptions object.


2 Answers

Updated SyncTimeout is not a good option because your redis command is runing very slow The reason of timeout is .net-core default threads count in threadpool is too low.

Just set maxThreads in environment variable.

ex:

ComPlus_ThreadPool_ForceMaxWorkerThreads 1000 ComPlus_ThreadPool_ForceMinWorkerThreads 50

Then run app in administrator identity(allow app read system environment variable)

It works to me

like image 182
anthonywanted Avatar answered Sep 29 '22 22:09

anthonywanted


Solution: Updated SyncTimeout configuration to 10000. Tried with 5000 and failed, then with 10000 and fixed. Default value was 1000.

like image 23
Jawen Avatar answered Sep 29 '22 22:09

Jawen