Slow Redis Response Times in Rails 🤔

Hi there, I made the switch to from Heroku recently and am loving it in general.

I ran into a strange issue with Redis today though and can’t quite figure out what might be going wrong.

I have a fairly conventional Rails 7 app set up that makes use of Kredis, which is basically just a wrapper around Redis.

Kredis is connected to one of two Redis Upstash instances I’ve set up for my app (200MB plan, eviction enabled).

When I run the app locally, I get response times under 1ms:

# Taken from the logs while running the app locally
Kredis Proxy (0.3ms)  EXISTS? users:4:show_sidebar 

When I run it on Fly, however, that figures jumps massively for the same query:

# Taken from the logs while running the app on Fly
Kredis Proxy (20059.6ms)  EXISTS? users:4:show_sidebar 

The strange thing is, when I ssh into the app and run the same query manually the time comes back down to a decent level. Not as fast as development, obviously, but fast enough:

> Kredis Proxy (26.0ms)  EXISTS? users:4:show_sidebar

So, in short, it’s just when I’m using the app in the browser (rather than accessing it from the command line) that the response times become so slow. The Redis instance still returns the expected value eventually, it just takes ~20 seconds to do so.

Hoping someone can help point me in the right direction with this one :crossed_fingers:

Many thanks!

Are you running this app in more than one region? If so, this might happen if you have an app instance deployed in a region where you don’t have a Redis read replica setup.

@jsierles thanks for the quick response :slight_smile:

Are you running this app in more than one region?

Good question but, no, I’m not. The app is only running in fra, as are both of its Redis instances.

Quick update though: I just ran fly apps restart and that seems to have actually set things straight again for now. Kredis response times are much faster so whatever was causing the issue seems to have been tackled by the classic Turn It Off And On Again method.

Thanks for your help anyway!