Redis connection errors when using the Booklee Redis client in Azure VM

I recently started hosting a side project on a new Azure VM. The application uses Redis as a cache in memory. Everything worked fine in my local environment, but now that I have moved the code to Azure, I see some strange exceptions coming out of Booksleeve.

When the application starts everything, everything works fine. However, after about 5-10 minutes of inactivity, the next application request raises a network exception (I am working now and do not have exact error messages, so I will send them when I get home if people think that they are related to the discussion). This closes the internal MessageQueue, which causes each subsequent call to Enqueue () to throw an exception ("Queue closed").

So, after some googling, I found this SO post: Maintaining an open Redis connection using BookSleeve about the DIY connection manager. I can, of course, implement something like this if this is the best course of action.

So the questions are:

  • Is it okay for RedisConnection to periodically close after a certain time?
  • I saw the conn.SetKeepAlive() method, but I tried many different values, and none of them matter. Is there more to this, or am I barking the wrong tree?
  • Is the idea of โ€‹โ€‹the connection manager from the post above to deal best with this scenario?
  • Can anyone shed more light on why placing my Redis instance in the new Azure VM is causing this problem? I can also confirm that if I ran my local environment against the Azure Redis virtual machine, I ran into this problem.

As I said, if it is unusual for Redis to die after inactivity, I will send stack traces and exceptions from my logs when I get home.

Thanks!

UPDATE Didier noted in the comments that this could be due to the load balancer that uses Azure: http://blogs.msdn.com/b/avkashchauhan/archive/2011/11/12/windows-azure-load-balancer-timeout -details.aspx

Assuming the case, what would be the best way to implement a connection manager that could explain this problem. I assume that I should not create the connection per unit of work correctly?

+6
source share
2 answers

From the other answers / comments, it looks like this is because the azure infrastructure is closing sockets that look idle. You could just have a timer somewhere that periodically performs some operation, but note that this is already built into Bookslee: when it connects, it checks what the redis connection timeout is and sets the heartbeat to prevent closing the socket again. You may be able to correct this to prevent the azure closing of the socket. For example, in a redis-cli session:

 config set timeout 30 

should configure redis (on the fly, without restart) to have a 30-minute connection timeout. Booksleeve then automatically takes steps to ensure that there is a heartbeat shortly before 30 seconds. Please note: if this succeeds, you must also edit your configuration file so that this parameter is applied after the next restart.

+6
source

The load balancer in Windows Azure will close the connection after the X-time is dependent on the total load on the load balancer, and because of this you will get a random timeout in your connection.

Since Iโ€™m not well known for Redis connections, I canโ€™t suggest how to implement it correctly, but in the general case, the proposed workaround solution is the pulse rate to keep your session alive. Do you have a chance to find a workaround suggested on the blog and try to implement it on Redis if this works for you?

+1
source

Source: https://habr.com/ru/post/917898/


All Articles