Hey everybody :slightly_smiling_face: We are havin...
# graphql-nexus
s
Hey everybody 🙂 We are having some performance issues with prisma and nexus. We use postgres as the database but we are finding very simple requests like
users(first: 5) { uuid }
which just has
t.crud.users()
can take 3 - 7 seconds. We are using vercel serverless to deploy an Apollo Server. What have people done to improve performance as this could end up a huge barrier.
r
Are you disconnecting Prisma Client after each request? Basic things to take note of in Serverless environments would be: 1. Initialize Prisma outside your handler 2. Don’t call
prisma.$disconnect()
after every request 3. Keeping your DB in the same region as your app to reduce latency 4. Using a DB connection pooler like PgBouncer that would help with concurrent requests We are also looking at perf considerations especially in serverless environments, but these would be the basic things to follow.
s
Hey 🙂 We are not manually disconnecting. This is our serverless function https://gist.github.com/Swapnull/de016e8b6cff809fee11f51fab04b4a6 We are doing all the things you have mentioned ( I think )
r
Looks fine. Does this happen only on the 1st request or all requests take this long?
s
1st request takes about 7s , second takes about 3.5s.
We have just set it up against a local express server and it is returning in under a second. We are going to test this properly by putting it on ec2, but serverless vercel is important to us.
r
3.5 seconds shouldn’t be the case. I recently load tested on AWS Lambda and it took around 300ms on average. Vercel uses Lambda under the hood afaik.
@Swapnull could you create an issue here with the necessary steps so that we can look into this? I will also try creating a Vercel example so that I can reproduce.
s
Sure, I will create that later today. We moved a few files around and managed to get it a little faster (around 2s).
r
Any specific files in that regard?
j
The biggest win for me was figuring out which regions to use across different providers to get the functions executing as close to the database as possible. In Europe for example we use Brussels/Amsterdam for apps spread over AWS (Vercel) / GCP / DigitalOcean
💯 1