R
Railway

✋|help

pgbouncer

L.lucasreinaldo9/7/2023
Hey folks, I have a supabase and Nextjs (+ prisma) project deployed in Railway, what's the best option to set the connection pool string since railway creates an server from nextjs functions?
L.lucasreinaldo9/7/2023
63ec8277-ce73-4ab7-8034-0c7e79c9c74b
my plan allows me to have

No. of direct connections - 240
No. of pooler connections - 700

but I keep getting connection timeout issues 🤔
BBrody9/7/2023
at what stage of your application lifecyle does it connect to the database?
L.lucasreinaldo9/7/2023
right after the packages are built if that's what you asking?
I believe using lambda functions the connection_limit should be as low as possible due the number of requests, but with railway I am just not sure what would be the right approach tbh :/
BBrody9/7/2023
what I'm really asking is does your app try to connect to the database right when it starts?
L.lucasreinaldo9/7/2023
I'd say so, the prisma instance is global, in a normal lambda it would instantiate at the moment the request is received, but since Railway wraps it all in a server my guess is that it is, yes
BBrody9/7/2023
would you happen to be utilising the private network?
L.lucasreinaldo9/7/2023
nope
BBrody9/7/2023
is it enabled?
if so, try disabling it
L.lucasreinaldo9/7/2023
disabled now
BBrody9/7/2023
okay let me know how that goes
L.lucasreinaldo9/7/2023
why is that?
like, why disabling ?
BBrody9/7/2023
private networking initialisation times can interfere with calls/connection attempts
L.lucasreinaldo9/7/2023
okay
aside from that, I can follow prisma docs and change the connection_limit to as low as possible
so prisma won't try to manage it, instead pgbouncer will
right ?
BBrody9/7/2023
you'd want to increase the timeout
L.lucasreinaldo9/7/2023
cause I've bumped to 500 and seems to be working haha
timeout is 300
BBrody9/7/2023
well you do get 8 vcpu so I don't even know if litestar can make use of multiple cpus
this is multiple cpus, not multiple cores btw
whoops
ignore that
L.lucasreinaldo9/7/2023
np
BBrody9/7/2023
:mildpanic:
so all good now?
L.lucasreinaldo9/7/2023
just making sure that, I want to keep the connection_limit as low as possible and increase the timeout, that's the recommendation ?
BBrody9/7/2023
I'd recommend keeping the private networking disabled so you don't need to set the timeout higher
L.lucasreinaldo9/7/2023
got it
i'll keep an eye on
BBrody9/7/2023
but from my tests the initialisation time takes about 2 seconds
L.lucasreinaldo9/7/2023
like the project is running fine, then I get a lot of data in a short period and my connection limit goes to shit and keeps timing out
BBrody9/7/2023
I mean at first glance that seems more like a code issue?
L.lucasreinaldo9/7/2023
even with 700 pooled connections? like, seems weird
BBrody9/7/2023
it is indeed weird
L.lucasreinaldo9/11/2023
should I call prisma.$disconnect at the end of the function, I reviewed all api endpoints and in all of then I am either returning success or error, so there is always a return response.json 🤔
BBrody9/11/2023
honestly no clue, I have no experience with prisma
but the team does, and you are pro after all 😉
L.lucasreinaldo9/11/2023
yep, maybe I should contact support
thanks dude
appreciate
Ggschier9/11/2023
Just chiming in here. The connection limit should not be as low as possible for Railway because you only have 1 server. If you set connection limit to 1, your code will constantly be waiting for that single connection. I would stick with Prisma's default connection limit which I think is num_cpu * 2 or something
BBrody9/11/2023
that would like eval to 64
even on trial
Ggschier9/11/2023
Okay, adjust as needed then if that's too much
We're going to fix this eventually... 😅
L.lucasreinaldo9/11/2023
yep, the low as possible is in a lambda environment, in railway I've bumped a few times.

the db allows me to:

No. of direct connections - 240
No. of pooler connections - 700

and I also have inngest (https://www.inngest.com/) that I run some fan-out/batch inserts and updates also deployed in railway
Ggschier9/11/2023
Do you have any metrics on how many prisma connections are being used?
L.lucasreinaldo9/11/2023
# HELP prisma_client_queries_total Total number of Prisma Client queries executed
# TYPE prisma_client_queries_total counter
prisma_client_queries_total 1130

# HELP prisma_datasource_queries_total Total number of Datasource Queries executed
# TYPE prisma_datasource_queries_total counter
prisma_datasource_queries_total 5349

# HELP prisma_pool_connections_closed_total Total number of Pool Connections closed
# TYPE prisma_pool_connections_closed_total counter
prisma_pool_connections_closed_total 18

# HELP prisma_pool_connections_open Number of currently open Pool Connections
# TYPE prisma_pool_connections_open counter
prisma_pool_connections_open 40

# HELP prisma_client_queries_active Number of currently active Prisma Client queries
# TYPE prisma_client_queries_active gauge
prisma_client_queries_active 0

# HELP prisma_client_queries_wait Number of queries currently waiting for a connection
# TYPE prisma_client_queries_wait gauge
prisma_client_queries_wait 0

# HELP prisma_pool_connections_busy Number of currently busy Pool Connections (executing a database query)
# TYPE prisma_pool_connections_busy gauge
prisma_pool_connections_busy 0

# HELP prisma_pool_connections_idle Number of currently unused Pool Connections (waiting for the next pool query to run)
# TYPE prisma_pool_connections_idle gauge
prisma_pool_connections_idle 400

# HELP prisma_pool_connections_open Number of currently open Pool Connections
# TYPE prisma_pool_connections_open gauge
prisma_pool_connections_open -18

# HELP prisma_pool_connections_opened_total Total number of Pool Connections opened
# TYPE prisma_pool_connections_opened_total gauge
prisma_pool_connections_opened_total 40


this only for the past 30mins
Ggschier9/11/2023
It says you don't have any active connections (usually the case if you don't have any long-running operations). Which variable in your project are you using to configure prisma?
L.lucasreinaldo9/11/2023
datasource db url
the directurl is only for migrations
Ggschier9/11/2023
So DATABASE_URL, not DATABASE_LAMBDA_URL?
L.lucasreinaldo9/11/2023
DATABASE_LAMBDA_URL I was using to test the inngest environment, they say to share a single instance of prisma within the step function but don't say anything about datasource

see here: https://www.inngest.com/docs/reference/middleware/examples#prisma-in-function-context
DATABASE_URL yes
Ggschier9/11/2023
It does seem like everything is correctly setup from a Railway perspective. I'm not sure there's much else I can do to help here unfortunately. My guess is that there's some code executing a bunch of concurrent DB operations that's exhausting the Prisma pool. We've had this internally before when running DB operations inside a Promise.all
L.lucasreinaldo9/11/2023
🤔
Ggschier9/11/2023
Curious what this output is from, and if it's possible to run if it happens again
L.lucasreinaldo9/11/2023
I'll review my Promise.all, like I do get a lot of data every minute or so and 15mins, but I already batch the inserts and updates
anyway, if it happens again I'll copy the metrics from prisma
Ggschier9/11/2023
Thanks! It does seem like a Prisma/code/config issue FWIW since you mentioned your provider said you're not even close to the limit
L.lucasreinaldo9/11/2023
yeah :/

Looking for more? Join the community!

Recommended Posts
Accessing files inside the volumewhat's the best way to export build artifacts from one service to another? during build process, a tHow usage-based resource management works ?Hello, how Railway manages resource scaling ? like how are vCPU and RAM scaled up and down automaticHow to dynamically scale the replicas of an APIs deployed via Railway based on demand?I have API service with a certain number of replicas, whats the recommended way to scale the number Laravel application failed to respondI am unsure what is causing the issue but the after deploying my laravel app, it still does not starRailway credits gone??I had $15.46 in credits, and now $5 is gone. I have a single project, and I know for a fact my projeInstalling apt packages for puppeteerHi, im trying to run puppeteer on Railway but am getting an error that it cant find some packages. IIs it possible to set permissions on volumes?Dockerfile is using user id of 1000,and the WORKDIR which they own is /app. A Volume is mounted at /Trying to pg_dump and getting this weird error:Hi guys I am following this tutorial: https://blog.railway.app/p/postgre-backup and i am getting thHow to check which region is the database in and how to request to change it (if needed)?We started on the hobby plan and now we are Pro plan. For GDPR compliance we need to check which regDjango projects loading issuesI have two Django projects that I have deployed and both projects are facing similar issues (most liClicking 'Observability' button goes to the wrong projectExpected Flow - You click on a project, go to 'Observability' and view the logs. - You then click onTell Nixpack to include public folder in buildI have an Axum build on Rust that is are web socket chat rooms, which also serves static files. When.NET 6.0 Deployment Failed during build processProject ID f8a04cde-c088-4000-923e-0de1e0d144aa I can not deploy my backend, this is the error NETSMonorepoIf I am inside monorepo how will assigning domain work I wanna asign domain in two aspectsI can not deploy angular project, killedI do not know what is the problem I hope someone can help me, Project ID dd70810d-29a4-4c5e-b7b4-f2NPM ssh dependancyHi I'm running into an issue where I'm using a private github npm dependancy and the build step is How to set mailgun to Ghost(docker) + SqliteI had used Ghost with mysql, but currently I try to use a new Ghost template with Sqlite. I did not Timeout while waiting for registry?All of my deploys have been building successfully but failing to deploy for the past ~hour or so. TContainer is failing to start.Everything was working fine, I just added a few new features to the app and now it is failing to depSeeing failures in deploying saying container shut down, but cannot find the container logs.Need help figuring out how to debug this issue with deploying to prod. From my end I don't think the