Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redis Timeout #1673

Closed
EminemJK opened this issue Jan 20, 2021 · 4 comments
Closed

Redis Timeout #1673

EminemJK opened this issue Jan 20, 2021 · 4 comments

Comments

@EminemJK
Copy link

EminemJK commented Jan 20, 2021

StackExchange.Redis.RedisConnectionException: No connection is available to service this operation: GET ippp; 
It was not possible to connect to the redis server(s). To create a disconnected multiplexer, disable AbortOnConnectFail. ConnectTimeout; 
IOCP: (Busy=0,Free=1000,Min=8,Max=1000), WORKER: (Busy=30,Free=32737,Min=8,Max=32767), Local-CPU: n/a
 ---> StackExchange.Redis.RedisConnectionException: It was not possible to connect to the redis server(s). To create a disconnected multiplexer, disable AbortOnConnectFail. ConnectTimeout
   --- End of inner exception stack trace ---
   at StackExchange.Redis.ConnectionMultiplexer.ThrowFailed[T](TaskCompletionSource`1 source, Exception unthrownException) in C:\projects\stackexchange-redis\src\StackExchange.Redis\ConnectionMultiplexer.cs:line 2201
--- End of stack trace from previous location where exception was thrown ---

#1150
#716

I use the lazy pattern:

private static ConnectionMultiplexer _instance = null;
public static ConnectionMultiplexer Instance
{
            get
            {
                return conn.Value;
            }
}

private static Lazy<ConnectionMultiplexer> conn = new Lazy<ConnectionMultiplexer>(
  () =>
  {
      _instance = ConnectionMultiplexer.Connect(“127.0.0.1:6379,password=123456,connectTimeout=5000,syncTimeout=10000,abortConnect=false”);
      _instance.ConnectionFailed += MuxerConnectionFailed;
      _instance.ConnectionRestored += MuxerConnectionRestored;
      _instance.ErrorMessage += MuxerErrorMessage;
      _instance.HashSlotMoved += MuxerHashSlotMoved;
      _instance.InternalError += MuxerInternalError;
      return _instance;
  }
  );

Could you please help as we are getting this error in production.

@EminemJK EminemJK changed the title Use JMeter for high concurrency tests Redis Timeout Jan 20, 2021
@EminemJK
Copy link
Author

I think I've solved it

@AbdulMoeedfieldforce
Copy link

I am also getting this issue
The timeout was reached before the message could be written to the output buffer, and it was not sent, command=EVAL, timeout: 5000, outbound: 111KiB, inbound: 3KiB, active: EVAL ** possible thread-theft indicated; see https://stackexchange.github.io/StackExchange.Redis/ThreadTheft ** , inst: 8, qu: 0, qs: 0, aw: True, rs: CompletePendingMessageSync, ws: Idle, in: 0, serverEndpoint: FFEastCoastRedis.redis.cache.windows.net:6380, mc: 1/1/0, mgr: 9 of 10 available, clientName: RD501AC5CEF127, IOCP: (Busy=0,Free=1000,Min=200,Max=1000), WORKER: (Busy=36,Free=8155,Min=200,Max=8191), v: 2.2.4.27433 (Please take a look at this article for some common client-side issues that can cause timeouts: https://stackexchange.github.io/StackExchange.Redis/Timeouts) .

can u guide me on how to fix it,

@EminemJK
Copy link
Author

If you use synchronous method calls, continue to use synchronous methods,vice versa.
for example:

public static ConnectionMultiplexer Instance
        {
            get
            {
                return conn.Value;
            }
        }

        private static Lazy<ConnectionMultiplexer> conn = new Lazy<ConnectionMultiplexer>(
        () =>
        {
            _instance = ConnectionMultiplexer.Connect("your redis conn");
            _instance.ConnectionFailed += MuxerConnectionFailed;
            _instance.ConnectionRestored += MuxerConnectionRestored;
            _instance.ErrorMessage += MuxerErrorMessage;
            _instance.HashSlotMoved += MuxerHashSlotMoved;
            _instance.InternalError += MuxerInternalError;
            return _instance;
        }
        );

        private static readonly SemaphoreSlim _connectionLock = new SemaphoreSlim(initialCount: 1, maxCount: 1);
        public async static Task<ConnectionMultiplexer> InstanceAsync()
        {
            if (_instance != null)
            {
                return _instance;
            }
            await _connectionLock.WaitAsync();
            try
            {
                if (_instance == null)
                {
                    _instance = await ConnectionMultiplexer.ConnectAsync("your redis conn");
                    _instance.ConnectionFailed += MuxerConnectionFailed;
                    _instance.ConnectionRestored += MuxerConnectionRestored;
                    _instance.ErrorMessage += MuxerErrorMessage;
                    _instance.HashSlotMoved += MuxerHashSlotMoved;
                    _instance.InternalError += MuxerInternalError;
                }
            }
            finally
            {
                _connectionLock.Release();
            }
            return _instance;
        }

        public static IDatabase GetDatabase(int dbIndex)
        {
            return Instance.GetDatabase(dbIndex);
        }

        public async static Task<IDatabase> GetDatabaseAsync(int dbIndex)
        {
            var conn = await InstanceAsync();
            return conn.GetDatabase(dbIndex);
        }
        public static string StringGet(int dbIndex, string key)
        {
            var db = GetDatabase(dbIndex);
            if (db != null)
            {
                return db.StringGet(key);
            }
            return string.Empty;
        }

        public static async Task<string> StringGetAsync(int dbIndex, string key)
        {
            var db = await GetDatabaseAsync(dbIndex);
            if (db != null)
            {
                return await db.StringGetAsync(key);
            }
            return string.Empty;
        }

can see my code : https://github.com/EminemJK/Banana/blob/master/Banana/Banana.Utility/Redis/RedisUtils.cs

@EminemJK
Copy link
Author

I am also getting this issue
The timeout was reached before the message could be written to the output buffer, and it was not sent, command=EVAL, timeout: 5000, outbound: 111KiB, inbound: 3KiB, active: EVAL ** possible thread-theft indicated; see https://stackexchange.github.io/StackExchange.Redis/ThreadTheft ** , inst: 8, qu: 0, qs: 0, aw: True, rs: CompletePendingMessageSync, ws: Idle, in: 0, serverEndpoint: FFEastCoastRedis.redis.cache.windows.net:6380, mc: 1/1/0, mgr: 9 of 10 available, clientName: RD501AC5CEF127, IOCP: (Busy=0,Free=1000,Min=200,Max=1000), WORKER: (Busy=36,Free=8155,Min=200,Max=8191), v: 2.2.4.27433 (Please take a look at this article for some common client-side issues that can cause timeouts: https://stackexchange.github.io/StackExchange.Redis/Timeouts) .

can u guide me on how to fix it,

up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants