Hi all, I was wondering if someone would be able t...
# orm-help
a
Hi all, I was wondering if someone would be able to help us debug an issue we are having. Occasionally when making large queries we can an errors of the following:
Whoops. Looks like an internal server error. Search your server logs for request ID: local:ckggp3hu1707s0799v326pd31
When we check the log, we see the following:
Copy code
{
  "key": "error/unhandled",
  "requestId": "local:ckggzgqyi71x90799fj7rnx4x",
  "clientId": "default$default",
  "payload": {
    "exception": "java.sql.SQLTransientConnectionException: database - Connection is not available, request timed out after 5005ms.",
    "query": "query ($where: TransactionWhereUniqueInput!) {\n  transaction(where: $where) {\n    sender {\n      id\n      isDeactivated\n    }\n  }\n}\n",
    "variables": "{\"where\":{\"id\":\"ckfmulguy26xr0799cqliqrwl\"}}",
    "code": "0",
    "stack_trace": "com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:676)\\n com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:190)\\n com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:155)\\n com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:100)\\n slick.jdbc.hikaricp.HikariCPJdbcDataSource.createConnection(HikariCPJdbcDataSource.scala:14)\\n slick.jdbc.JdbcBackend$BaseSession.<init>(JdbcBackend.scala:494)\\n slick.jdbc.JdbcBackend$DatabaseDef.createSession(JdbcBackend.scala:46)\\n slick.jdbc.JdbcBackend$DatabaseDef.createSession(JdbcBackend.scala:37)\\n slick.basic.BasicBackend$DatabaseDef.acquireSession(BasicBackend.scala:250)\\n slick.basic.BasicBackend$DatabaseDef.acquireSession$(BasicBackend.scala:249)\\n slick.jdbc.JdbcBackend$DatabaseDef.acquireSession(JdbcBackend.scala:37)\\n slick.basic.BasicBackend$DatabaseDef$$anon$3.run(BasicBackend.scala:275)\\n java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)\\n java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)\\n java.lang.Thread.run(Thread.java:748)",
    "message": "database - Connection is not available, request timed out after 5005ms."
  }
}
Our connection limit is already at 200. Any idea what we can do to fix this? Thanks!
l
Is this prisma 1? How many connections can your db handle? 200 connectionLimit seems high.. the recommended limit is cpu-cores x 2 + 1. Is prisma the only client using the database? I think the limitation is in the db itself. If you need more connections than the dB can handle you need to use something like pgbouncer, but I’m not sure if it’s compatible with prisma1
My guess is that you are querying a to-many relationship and for each record querying further relationships. This generates many queries, and with that setting prisma will try to use a new connection for each query up to the limit. Your db can probably handle fewer connections than the limit (20 or so maybe depending on the dB server size)
a
Hi Lars, thanks for the response. To answer some of your questions: • We are using prisma 1 • Our DB can handle up to 245 connections • Prisma is the only client using the DB • We’ve read pgBouncer is not compatible with prisma 1 • This is happening on a to-many relationship with further relationships. Is there anything we can do to ensure Prisma does not try to exceed the connection limit?
@Lars-Jørgen Kristiansen Just wanted to check in again and see if you had any ideas. We’re really stumped here.
l
My best guess is that the server can’t handle running 200 connections. It runs out of threads and times out. I would try lowering the number of connections to 2 x cpu cores + 1 as is the recommended value.
To solve the scaling issue you would either have to horizontally scale prisma or optimize the queries in the backend..
We are struggling with n+1 problems ourself and are migrating to knex + dataloaders