New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible Node API performance regression with concurrency #7382
Comments
@williamluke4 Thanks, works. With latest version, with high concurrency (see #6301 (comment)) it's still twice as slow per query compared to without napi. I will look at publishing my ORM benchmarking repo today if you want to see. Originally posted by @vjpr in #6301 (comment) |
How do you measure. I just did a tight loop: import { PrismaClient } from '@prisma/client'
const metrics = require('metrics');
const prisma = new PrismaClient();
function now() {
var hrTime = process.hrtime();
return hrTime[0] * 1000000 + hrTime[1] / 1000;
}
async function main() {
let histogram = new metrics.Histogram();
var report = new metrics.Report();
report.addMetric('queryTime', histogram);
var reporter = new metrics.ConsoleReporter(report);
reporter.start(1000);
while (true) {
var start = now();
const all = await prisma.a.findMany({
include: {
bs: true,
},
});
histogram.update(now() - start);
}
}
main()
.catch((e) => {
throw e;
})
.finally(async () => {
await prisma.$disconnect();
}) And results:
Numbers are in microseconds. If there is a specific query that is slow, file an issue. I also must underline here that our priority with N-API is not performance, but simplifying the codebase and closing that extra TCP port the engine binary opens up. Originally posted by @pimeys in #6301 (comment) |
@pimeys Your example is only testing sequential runs. I'm using to run concurrent queries. Originally posted by @vjpr in #6301 (comment) |
@vjpr I am getting the following results with concurrency via p-times: import { PrismaClient } from "@prisma/client";
import { performance } from "perf_hooks";
import metrics from "metrics";
import pTimes from "p-times";
const prisma = new PrismaClient();
async function main() {
let start, finish;
let histogram = new metrics.Histogram();
let report = new metrics.Report();
report.addMetric("queryTime", histogram);
let reporter = new metrics.ConsoleReporter(report);
reporter.start(1000);
while (true) {
start = performance.now();
await pTimes(1000, () =>
prisma.test.findUnique({
select: {
id: true,
name: true,
},
where: {
id: 1,
},
})
);
finish = performance.now();
histogram.update(finish - start);
}
}
main(); Results:
This doesn't indicate a regression. Can you try this test out? Version used:
Schema: generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model test {
id Int @id @default(autoincrement()) @db.Integer
name String @db.Text
}
So can you please try this once again or maybe share the benchmark code which detects the regression. Originally posted by @pantharshit00 in #6301 (comment) |
@pantharshit00 he said that above, I will check myself today. My guess would be the issue is related to the size of the dataset and how NAPI handles findMany with many hundred (maybe thousand) objects. Originally posted by @Sytten in #6301 (comment) |
@pantharshit00 Will try your benchmark script to see I can replicate. @Sytten I am running on https://github.com/lerocha/chinook-database (see morenoh149/postgresDBSamples#1 (comment) for an error that you need to work around when importing it) Originally posted by @vjpr in #6301 (comment) |
@pantharshit00 You need to add option with . await pTimes(async () => {
await ...
}, {concurrency: 100}) Originally posted by @vjpr in #6301 (comment) |
Out of interest, what is the when your is 100? If much less than that, you're basically just measuring the waiting time to get a connection from the database. I'd try lowering the to the same value as the is (default: number of logical cores + 1). Originally posted by @pimeys in #6301 (comment) |
Other ORMs using Originally posted by @vjpr in #6301 (comment) |
p-times
](https://github.com/sindresorhus/p-times)), I'm seeing a big perf regression:
See: #7404 |
Duplicate of #7404 and fixed in prisma/prisma-engines#1986 |
After testing 1000 queries with 100 currency (), I'm seeing a big perf regression:
with napi: 420ms (findMany) 200ms (queryRaw)
without napi: 178ms (findMany) 100ms (queryRaw)
Using sample database and .
Originally posted by @vjpr in #6301 (comment)
The text was updated successfully, but these errors were encountered: