Hi @luizkowalski, it seems you’re running this app in both Frankfurt and São Paulo. Is it possible you have app instances trying to reach pg across the world? That would be really slow.
It’s unlikely this would be caused by replication lag. That would lead to stale data, but not slow requests.
@luizkowalski Are you using puma or unicorn? If so, are you running more than one process per VM? On puma, this is usually set via WEB_CONCURRENCY which sets the workers in config/puma.rb. By default, I believe you’ll get 2 workers.
I will give it a try for sure, thanks a lot @jsierles!
I still wonder why is it that the problem goes away when I scale down the postgres app…
my problem here is that I can’t easily reproduce, sometimes I open the app and it is just slow, I then scale down the postgres app, and boom, the issue is gone, later I scale up and I don’t see the problem for hours until the cycle begins again.
anyway, I will tweak my puma config, maybe disabling workers for good until it is fixed
also, I think it is worth notice that I’m having this issue on my primary region (fra), not on a secondary region (gru)
What does the DATABASE_URL in your environment look like? Is it something like top1.nearest.of.<db>.internal? Or is it just <db>.internal?
The second form will return any postgres instance. So your app in Frankfurt could be connecting to your DB in São Paulo, and then getting routed back to Frankfurt from there.
Yeah, top1 will work better for you. We deploy 2 Postgres instances in your primary region for write redundancy, so we do top2 by default. It’s actually best to run 2x fra DBs if you can. Changing to top1 should fix the problem right now though.
If I understand what you said, I should add a new “fra” volume?
anyway, you said “we do top2 by default”. why is that exactly? I’m asking because the docs don’t mention “top2”, it is always “top1” and I got this URL by attaching postgres to my app, so fly actually set “top2”.
when you say “top1 will work better for you” I wonder if there are cases where top2 is better? if so, when?
sorry, lots of questions hahaha trying to get to the bottom of it