Bad performance using planetscale, vercel, prisma

Hey all, I have been working on a website called krossahp.se - please feel free to check it out. Im finding that the site feels surprisingly sluggish, for example it takes quite a while to get auth status sometimes (upwards of 2,3 sometimes 5 seconds). I attached 2 pictures of the navbar showing the loading, and loaded state. in addition to this, the button that takes users to their dashboard pages is also very slow - often with load times in the seconds range - showed the loading state there as well if anyone wants to take a look. Im hosting on vercel, using prisma and planetscale. Do you guys have any tips on how to improve performance?
31 Replies
Christian Lind
its a swedish site so pardon the lack of english 🙂
rocawear
rocawear2y ago
Where (country) is your db hosted is it near of your vercel deploy?
Christian Lind
double checking, but yeah think both are in frankfurt vercel was in frankfurt, planetscale in dublin. Just switched both to be in dublin but i doubt that would cause the 5 second loading times. It feels more like a cold start issue, after an initial load it feels sufficiently rapid
SGeri
SGeri2y ago
prisma has cold starts with serverless environments
SGeri
SGeri2y ago
could prisma be the bottleneck part? that is actually my concert about a new project with similar stack
Christian Lind
It feel really crazy that a "bleeding" edge stack would have cold start latencys when making simple requests exceeding a couple seconds
SGeri
SGeri2y ago
GitHub
Slow queries with Prisma + Nexus + GraphQL on Vercel due to lambda ...
Bug description My Next.js app is deployed to Vercel and uses a lambda route for a GraphQL server (apollo-server-micro) that is configured with Prisma + Nexus. Lambda cold starts on Vercel lead to ...
SGeri
SGeri2y ago
this looks similar to your issue ill take a look into this i was just thinking about replacing vercel with a custom server, but vercel has such good services that it would be a shame and also the comments feature, easy integration with terraform, i really dont want to move from vercel and i guess thats the case for you...? actually this is mostly about nexus, so you can ignore it
Christian Lind
yeah exactly, i dont want to leave vercel. But i feel like there has to be a solution - otherwise larger enterprise companies wouldn't be able to use vercel - right? This is probabbly a really nooby question but is it due to problems similair to this that people use rust and other (comparativley) faster languages - or would this issue persist regardless?
SGeri
SGeri2y ago
well, i believe rust is a completely different scenario, since you build it into executables while the runtime for ts is not like that and yeah, I agree with you, there has to be a way to reduce cold starts, I'll tell ya if I find anything useful
SGeri
SGeri2y ago
i was reading this article, but it's the general advice, like reduce bundle size, optimize data sent to client etc https://medium.com/@scott82anderson/avoid-cold-starts-on-vercel-with-next-ssr-7b28fbc38bcc
Medium
Avoid cold starts on Vercel with Next SSR
This is the story of how I went from gateway timeout errors (> 10 sec) for my Next.js app hosted on Vercel, to < 0.2 sec load times (First…
SGeri
SGeri2y ago
but that doesnt solve the prisma binary problem
JulieCezar
JulieCezar2y ago
I just tried it and it works fine and pretty quick... The cold starts happen if noone accessed your lambdas for some time, then they die but if you expect relatively constant usage then it shouldnt be a problem
Sybatron
Sybatron2y ago
It's because of the grapgql burden and each time you need to connect to db for each request And that's adds up Accelerate is still closed early access and json protocol preview feature should help I think there is rust prisma too that speeds it up And other performance improvements you can search for Or if you can switch to prisma kysely To skip the db connect and other latency issues
Christian Lind
isn't graphQL something completley separate?
SGeri
SGeri2y ago
@Christian Lind actually you could utilize prisma data proxy to exclude the prisma binaries. that should improve performance, longer cold starts and even higher memory usage https://www.prisma.io/docs/data-platform/data-proxy
Christian Lind
Thanks for the tip @SGeri , but that looks like something to use when using prismas data platform, which im not using. Im just using prisma as my interface to planetscale
SGeri
SGeri2y ago
ah alright, forgot you use planetscale :/
Christian Lind
😉 thanks for the testing! But yeah the problem is when usage is not constant...
frenetic.ts
frenetic.ts2y ago
I think my Planetscale instance exists in Frankfurt, didnt you have that option? I dont know where the Vercel server lives though. But I live in Sweden and have been using the T3-stack several times without issues. So it shouldnt atleast be a general problem.
Christian Lind
thats good to know, will try moving everything to frankfurt and see if that makes it faster. Do you also experience cold starts?
Sybatron
Sybatron2y ago
Version 1 of prisma is on top of graphql so it still uses somewhat graphql behind the scenes
jamiedubs
jamiedubs2y ago
honestly this nextjs + prisma being so slow issue is baffling to me. It's a pervasive issue that's not getting nearly as much attention as it should get
Sybatron
Sybatron2y ago
This should be for connection pooling so still cold start but after that you dont have them cuz it already got the db connection I think
jamiedubs
jamiedubs2y ago
I like Prisma generally so this is super annoying. the only reliable solutions are basically switching to other libraries, like Drizzle (which is brand new)
jamiedubs
jamiedubs2y ago
here's one of the long-running issues about it: https://github.com/prisma/prisma/issues/10724
GitHub
Lambda Cold Start Time · Issue #10724 · prisma/prisma
Bug description I want to use Prisma in my AWS serverless lambda functions. I'm using Serverless Stack and NodejsFunction for bundling (which uses esbuild). I enable the minify option when bund...
Sybatron
Sybatron2y ago
Accelerate should fix some of the problems in the future and you can try jsonnprotocol as preview feature to make it a bit better
jamiedubs
jamiedubs2y ago
i have also seriously considered using vercel's new cronjob feature to hit a random serverless endpoint to try and keep it warm
Christian Lind
thought that i would revive this thread - just saw this video from theo. https://youtu.be/jIpdkbOw6Cc https://youtu.be/jIpdkbOw6Cc
Theo - t3․gg
YouTube
They FINALLY Fixed Prisma (By Deleting GraphQL)
OMG THEY FIXED IT - BLOG POST HERE https://www.prisma.io/blog/prisma-and-serverless-73hbgKnZ6t Databases are hard. I'm thankful my favorite database tools keep getting easier and better. 🙏 ALL MY VIDEOS ARE POSTED EARLY ON PATREON https://www.patreon.com/t3dotgg Everything else (Twitch, Twitter, Discord & my blog): https://t3.gg/links
Christian Lind
Seems to fix our problems?!
Want results from more Discord servers?
Add your server