You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After upgrading prisma do a version higher than 2.14 I'm experiencing performance issues with the queries. Mocha reports tests that usually took less than 60ms to now be taking more than 150ms, sometimes more than 200ms to complete
I commented about this in #5485 and analyzed the logs, but they're identical (or very similar) so it does not seems like it's the same as #5274
Expected behavior
Average performance should remain the same or improve between Prisma versions.
Prisma information
I've picked some queries to show comparing 2.14 with 2.15 and 2.17, but they were exactly the same, the only difference was the time it took to run them (54ms -> 141ms, 65ms -> 193ms) so I don't thing it make sense to show them (since they're the same). But it's not a problem to share that part of the schema and queries if needed
Environment & setup
OS: Debian 10 buster x64
Database: PostgreSQL 12 (localhost)
Node.js version: v14.15.5
Prisma version: >= 2.15.0
Please let me know if you need more information or tests that you need. Thanks!
Reacted by Cory McAboy, Janu Shan, François Cantonnet, Daniil Demidovich and Andrii Oriekhov
prisma:info Starting a postgresql pool with 5 connections.
prisma:info Fetched a connection from the pool
prisma:info Started http server on http://127.0.0.1:34325
prisma:info Fetched a connection from the pool
prisma:query DELETEFROM users
prisma:info Fetched a connection from the pool
prisma:query BEGIN
prisma:query INSERT INTO"public"."users" ("id","email","password","role","created_at","updated_at") VALUES ($1,$2,$3,$4,$5,$6) RETURNING "public"."users"."id"
prisma:query SELECT"public"."users"."id", "public"."users"."email", "public"."users"."password", "public"."users"."role", "public"."users"."created_at", "public"."users"."updated_at"FROM"public"."users"WHERE"public"."users"."id"= $1LIMIT $2 OFFSET $3
prisma:query COMMIT
prisma:info Fetched a connection from the pool
prisma:query SELECT"public"."users"."id", "public"."users"."password", "public"."users"."role"FROM"public"."users"WHERE"public"."users"."email"= $1LIMIT $2 OFFSET $3
prisma:info Fetched a connection from the pool
prisma:query DELETEFROM criadores
prisma:info Fetched a connection from the pool
prisma:query BEGIN
prisma:query SELECT"public"."users"."id"FROM"public"."users"WHERE"public"."users"."id"= $1 OFFSET $2
prisma:query INSERT INTO"public"."criadores" ("id","userId","nome","telefone","created_at","updated_at") VALUES ($1,$2,$3,$4,$5,$6) RETURNING "public"."criadores"."userId", "public"."criadores"."id"
prisma:query SELECT"public"."criadores"."userId", "public"."criadores"."id", "public"."criadores"."nome", "public"."criadores"."telefone", "public"."criadores"."created_at", "public"."criadores"."updated_at"FROM"public"."criadores"WHERE ("public"."criadores"."userId"= $1AND"public"."criadores"."id"= $2) LIMIT $3 OFFSET $4
prisma:query COMMIT
prisma:info Fetched a connection from the pool
prisma:query SELECT"public"."criadores"."userId", "public"."criadores"."id", "public"."criadores"."nome", "public"."criadores"."telefone", "public"."criadores"."created_at", "public"."criadores"."updated_at"FROM"public"."criadores"WHERE"public"."criadores"."id"= $1LIMIT $2 OFFSET $3
From the second test:
prisma:info Fetched a connection from the pool
prisma:query DELETEFROM criadores
prisma:info Fetched a connection from the pool
prisma:query BEGIN
prisma:query SELECT"public"."users"."id"FROM"public"."users"WHERE"public"."users"."id"= $1 OFFSET $2
prisma:query INSERT INTO"public"."criadores" ("id","userId","nome","telefone","created_at","updated_at") VALUES ($1,$2,$3,$4,$5,$6) RETURNING "public"."criadores"."userId", "public"."criadores"."id"
prisma:query SELECT"public"."criadores"."userId", "public"."criadores"."id", "public"."criadores"."nome", "public"."criadores"."telefone", "public"."criadores"."created_at", "public"."criadores"."updated_at"FROM"public"."criadores"WHERE ("public"."criadores"."userId"= $1AND"public"."criadores"."id"= $2) LIMIT $3 OFFSET $4
prisma:query COMMIT
prisma:info Fetched a connection from the pool
prisma:query BEGIN
prisma:query SELECT"public"."criadores"."userId", "public"."criadores"."id"FROM"public"."criadores"WHERE ("public"."criadores"."userId"= $1AND"public"."criadores"."id"= $2)
prisma:query UPDATE"public"."criadores"SET"nome"= $1, "updated_at"= $2WHERE ("public"."criadores"."userId","public"."criadores"."id") IN (($3,$4))
prisma:query SELECT"public"."criadores"."userId", "public"."criadores"."id", "public"."criadores"."nome", "public"."criadores"."telefone", "public"."criadores"."created_at", "public"."criadores"."updated_at"FROM"public"."criadores"WHERE ("public"."criadores"."userId"= $1AND"public"."criadores"."id"= $2) LIMIT $3 OFFSET $4
prisma:query COMMIT
prisma:info Fetched a connection from the pool
prisma:query SELECT"public"."criadores"."userId", "public"."criadores"."id", "public"."criadores"."nome", "public"."criadores"."telefone", "public"."criadores"."created_at", "public"."criadores"."updated_at"FROM"public"."criadores"WHERE"public"."criadores"."id"= $1LIMIT $2 OFFSET $3
The tests were performed using mocha and the generated "prisma:query" are identical between 2.14, 2.15 and 2.17, the only difference (just noticed it) are the "prisma:info" statements, where on 2.14 we only had these two:
prisma:info Starting a postgresql pool with 5 connections.
prisma:info Started http server on http+unix:///tmp/prisma-b055a1ccfdb2a3a62e187d82.sock
@Akxe that is bad, the last thing I want is having performance issues on the server due to unknown parameters.
I have conducted the test multiple times with logging disabled and the results are pretty close.
Here some added information maybe it helps regards identifying the root cause of the issue.
The database I am using is the employee database from here. It contains about 300,024 employee record Prisma schema:
I have run the both of the queries directly from the MySQL database and the result wasn't significantly large
Results
prisma raw query: 1.2ms
sequelize raw query: 0.9ms
The next step was to test the sequelize-query using prisma query.$raw:
for(letindex=0;index<2000;index++){constallEmployeesRaw=awaitprisma.$queryRaw('SELECT `emp_no`, `birth_date`, `first_name`, `last_name`, `gender`, `hire_date` FROM `employees` AS `employees` LIMIT 100;');}
Results
prisma raw without nodeApi: 26.817s
prisma raw with nodeApi: 4.452s
Notice that in the case of raw prisma queries the performance improvement wasn't significant especially that I am now ignoring most of the prisma features.
The SQL it produces is extremely long (and was posted previously), but when I copied the SQL and put it into MySQL workbench, it returned results under 0.1s. For me, the problem is within the processing of incoming result(s).
@k-sae As said above, your original problem was not the same as what this thread is about. You were experiencing a different problem, which is somehow solved by switching to Node-API - which will not help for the problem @Akxe and Co describe here. No need to investigate further here. (But you please still comment on that issue or open a new one, so we can understand better)
@janpio Thank you, I will create a reproduction here #6301, maybe it will help to identify this issue. I really appreciate the hard work of the Prisma team.
I am experiencing close to 10x difference in performance between operations executed by prisma and similar raw queries. I will make a reproduction repo soon. Just adding my voice for now. Prisma 3.8.0 and postgres 12 (macos)
Hey everyone, in Prisma 5 we have made considerable performance improvements. @GCastilho@peterrogov@k-sae@Akxe@chinanderm@Tsvetomir-M, if you are using Prisma 5 are you still experiencing these problems? Otherwise, I'd love if you could give it a try.
Hey everyone, given the age of this issue, the recent improvements in query and startup performance, and also the difficulty to reproduce, I am closing it. But don't take me wrong, if you are experiencing any performance regression, please open a new issue with the necessary information for us to reproduce it.
Activity
timsuchanek commentedon Feb 23, 2021
Thanks for reporting @GCastilho!
Could you share the specific query with us plus a subset of the schema that got slower?
GCastilho commentedon Feb 23, 2021
For sure, @timsuchanek
This is the schema:
And the queries logged by prisma:
From the first test, [email protected]:
From the second test:
The tests were performed using mocha and the generated "prisma:query" are identical between 2.14, 2.15 and 2.17, the only difference (just noticed it) are the "prisma:info" statements, where on 2.14 we only had these two:
timsuchanek commentedon Feb 23, 2021
Thanks @GCastilho!
One more thing: Could you show the Prisma Client query that you are sending?
So in the form like this:
Thanks!
GCastilho commentedon Feb 23, 2021
For sure, @timsuchanek
Here are the queries, in order:
Duplicated queries I've displayed only once. The delete queries are all used as
Because prisma (AFAIK) still does not have support for "deleteMany" with cascade relations
Akxe commentedon Mar 16, 2021
This does happen to me too! I have shared all info with @matthewmueller via email. My query however did go from less than a second to 30-40sec!
Also, I would like to note, I did test every single query sent to DB and every one finished under 100ms (6 total)
Tsvetomir-M commentedon Mar 24, 2021
A simple query on 2.19 is much slower than on 2.14.
I have tested with this example.
Environment:
Db model:
Code:
Results:
$queryRaw is slower as well.
chinanderm commentedon Mar 24, 2021
I've also noticed considerably slower performance with queries.
pantharshit00 commentedon May 16, 2021
Hello everyone,
Can you all still reproduce these regressions in the latest version of Prisma?
Akxe commentedon May 16, 2021
@pantharshit00 Yes, indeed.
I am doing and measuring 5 simultaneous queries (+ one initial query)
carriersPromise query:
The prod server is using 2.21.x. On the dev server, I tried the 2.22.x
Dev Prisma version:
8 remaining items
Akxe commentedon Jun 23, 2021
@janpio Can confirm, no change in the duration of my (prisma) query.
k-sae commentedon Jun 23, 2021
@Akxe Have you run
npx prisma generateafter addingpreviewFeatures = ["nApi"]to schema.prisma?Akxe commentedon Jun 23, 2021
Indeed I did, yet no change. Still it resulted in 36-38 sec
k-sae commentedon Jun 23, 2021
@Akxe that is bad, the last thing I want is having performance issues on the server due to unknown parameters.
I have conducted the test multiple times with logging disabled and the results are pretty close.
Here some added information maybe it helps regards identifying the root cause of the issue.
The database I am using is the employee database from here. It contains about 300,024 employee record
Prisma schema:
The query generated from prisma:
The query generated from sequelize:
I have run the both of the queries directly from the MySQL database and the result wasn't significantly large
Results
The next step was to test the sequelize-query using prisma
query.$raw:Results
Notice that in the case of raw prisma queries the performance improvement wasn't significant especially that I am now ignoring most of the prisma features.
Akxe commentedon Jun 23, 2021
@k-sae Just to clarify, I am not from Prisma. In my case the SQL Prisma creates is not the bottleneck.
I ran my test. I did enable full SQL logging, and requested
The SQL it produces is extremely long (and was posted previously), but when I copied the SQL and put it into MySQL workbench, it returned results under 0.1s. For me, the problem is within the processing of incoming result(s).
janpio commentedon Jun 24, 2021
@k-sae As said above, your original problem was not the same as what this thread is about. You were experiencing a different problem, which is somehow solved by switching to Node-API - which will not help for the problem @Akxe and Co describe here. No need to investigate further here. (But you please still comment on that issue or open a new one, so we can understand better)
k-sae commentedon Jun 24, 2021
@janpio Thank you, I will create a reproduction here #6301, maybe it will help to identify this issue. I really appreciate the hard work of the Prisma team.
peterrogov commentedon Jan 12, 2022
I am experiencing close to 10x difference in performance between operations executed by prisma and similar raw queries. I will make a reproduction repo soon. Just adding my voice for now. Prisma 3.8.0 and postgres 12 (macos)
millsp commentedon Aug 2, 2023
Hey everyone, in Prisma 5 we have made considerable performance improvements. @GCastilho @peterrogov @k-sae @Akxe @chinanderm @Tsvetomir-M, if you are using Prisma 5 are you still experiencing these problems? Otherwise, I'd love if you could give it a try.
millsp commentedon Aug 9, 2023
Hey everyone, given the age of this issue, the recent improvements in query and startup performance, and also the difficulty to reproduce, I am closing it. But don't take me wrong, if you are experiencing any performance regression, please open a new issue with the necessary information for us to reproduce it.
Thanks.