Open arkmech opened 1 year ago
Could it be that opening a connection to the database just takes this amount of time you are observing? If not, can you share a minimal reproduction of this please?
Could it be that opening a connection to the database just takes this amount of time you are observing? If not, can you share a minimal reproduction of this please?
When I first started using prisma, virtually no latency. It seems that after my database tables increased to 350+ tables, I had latency. Prisma client generation takes quite some time as well. But not sure how this would effect initial connection pooling latency.
How do I share a minimal reproduction without sharing my database models
The easiest way would be to see if a manually created list of fake models (foo1
, foo2
) etc is enough to reproduce. Might need to add some fields and relations as well - but that already tells us something what triggers this.
Alternatively you can also share in private via schemas@prisma.io and/or invite me to a GitHub repo. Will only be shared internally.
Hey @arkmech, are you still around?
We recently improved the startup performance a lot (read more about it in our blog post: https://www.prisma.io/blog/prisma-and-serverless-73hbgKnZ6t). This also applies to non serverless environments, so I am pretty positive that by upgrading to the newest version and enabling the jsonProtocol
preview feature you could seriously improve this situation and probably get rid of the problem overall.
@janpio, hey yeah I haven't been working with Prisma lately, but when I get back to it I will check it out!
@arkmech Did you by chance get back to this along the way? We still have no idea what might be going on there, and as there have been no other similar reports it is very hard to figure out what might be going on.
Bug description
I have a single instance of Prisma client stored in global variable.
There is significant latency on initial request to my API with Prisma when initializing the connection pool.
After I see this log:
prisma:info Starting a postgresql pool with 5 connections.
, aka connection pool has finished initializing, then the requests are regular speed.Docker for both API (Node.js Typescript Apollo Server Express Prisma) and Postgresql
I use Nodemon for development, so every change, rebuilds and restarts my API, thus Prisma needs to build a new connection pool again. Aka every change to code, the first request has significant latency.
How to reproduce
prisma.ts
withconst prisma = new PrismaClient({ log: [ { emit: 'event', level: 'query', }, { emit: 'stdout', level: 'error', }, { emit: 'stdout', level: 'info', }, { emit: 'stdout', level: 'warn', }, ], });
prisma.$on('query', (e) => { console.log('Query: ' + e.query); console.log('Params: ' + e.params); console.log('Duration: ' + e.duration + 'ms'); });
export default prisma;
4.4.0