Slow performance after moving from public DB connection to private.
I unknowingly initialized my app with a public connection between my app (c#) and my dB (postgres).
It cost me significantly and I switched to private connection at around 3:30 pm today. The network usage is negligible after that in my metrics.
However, the app is now glacier slow. According to my app's metrics, after switching to private connection, my cpu usage became almost 5x. I'm on hobby plan so the only available region is US-West. I'm based in US-east. But it legit takes 20-30 seconds to log me in or perform any action which talks to the dB.
The region for both dB and app is the same.
projectId: 2eaf5e06-33cb-4195-a8d7-bb0c024c13ee
Attaching a screenshot of my app service's metrics.
I'm new to this, how should I proceed to improve the performance?
7 Replies
Project ID:
2eaf5e06-33cb-4195-a8d7-bb0c024c13ee
if it helps - this is the metric screenshot for my database service
that is very odd, ive never seen a slow down from using the private network, its usually the other way around, the private network is just a ipv6 only wireguard tunnel, the database itself doesnt change
an absolutely wild guess i had: your code opens a new connection to the database for every query you run on it and it tries to connect via ipv4 for a while and finally falls back to ipv6
Sorry if this is an amateur question but would the fix be in my code or in the variables that I setup in railway that are used to connect the app to dB?
well you said that it does work, just super slowly, so that wouldn't be an issue with the variables, but with your code
I do wish I knew what the issue is, but unfortunately I don't have any real idea besides my wild guess I gave
Really appreciate your help Brody. You're Godsent. I haven't solved it but yes it does look like the issue.
I don't see "error logs".
But for example I clicked the login button at exactly 7:11:50, I see a query being logged at 7:12:16. That's 24s gap. But the query in and of itself doesn't take time.
Interestingly, my landing page (no query involved) is returned in no time.
maybe look into a way to set the network type to ipv6 for the postgres client (when running on railway) so that the client knows how to connect properly, and also keep a pool open so you aren't re-connecting for each query your app runs on the database