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
prisma.$transaction: Benchmark produces unexpected results #10218
Comments
I saw this unmeaningful error too, and don't know how to fix it. :( |
@loclv if you are using transactions the underlaying error should be this: {
"is_panic": false,
"message": "Transaction API error: Unable to start a transaction in the given time.",
"meta": {
"error": "Unable to start a transaction in the given time."
},
"error_code": "P2028"
} |
@tonivj5 thank you! |
Thanks for the clear reproduction. I can reproduce this. |
I am getting the exact error mentioned in #10218 (comment) when using interactive transactions with Prisma 3.10.0 (MacOS 11.6.4 / M1) with PostgresSQL 13 on RDS. Moving back to non-interactive transactions fixes it: // not working
await prisma.$transaction(async ($prisma) => {
await $prisma.$executeRaw`SET LOCAL credential.skip_txn_data_calculation='TRUE'`;
await $prisma.txn.createMany({
data: newTxns
});
});
// working
await prisma.$transaction([
prisma.$executeRaw`SET LOCAL credential.skip_txn_data_calculation='TRUE'`,
prisma.txn.createMany({
data: newTxns
}),
]); |
Hey @codazzo, sorry to hear this. Do you perhaps have the time to share a reproduction project (setup, schema, code)? |
Hi @millsp, unfortunately I don't really have a self-contained reproduction example apart from those lines I posted. I understand it's not much to go by, but I just wanted to raise this in case it could help. |
@codazzo, have you tried increasing the timeout of the transaction? Interactive transactions are expensive, so they have default timeouts, could you please try overriding the default values? Thanks await prisma.$transaction(
async (prisma) => {
// Code running in a transaction...
},
{
maxWait: 5000, // default: 2000
timeout: 10000, // default: 5000
}
) |
Hi @millsp - apologies for the late reply, I had a few GitHub notifications to go through. Thanks for the tip! Frustratingly, I've been unable to reproduce the issue as described since posting the comment. For now I will keep using non-interactive transactions. I will try to post a more detailed reproduction if I run into this again. |
This was probably not a bug, but just a timeout on the query because the database sits too far. I'll mark this as closed, but feel free to ask for any help. Thank you. |
In addition to this, for anyone interested, I did some benchmarking on transactions on my side as well, when trying to track down connections pools issues prior to 3.13.0. In my bench, I only tested transactions and their overhead over performances. In two different contexts:
For what I observed, this is my TL;DR:
So if you hit performances issues with transactions, it'll be likely due to either:
You can found the code of the bench here: here it's done with "my code specific" but the logic should apply in every situations. |
Bug description
I have been doing some benchmarks against my project using Prisma. My project uses prisma's transactions and under high load, prisma throws an unmeaningful error
This error shadows this response from engine (captured from a breakpoint using vscode debugger):
I suspect that
StringExpected
error comes from these lines https://github.com/prisma/prisma/blob/main/packages/engine-core/src/library/LibraryEngine.ts#L119-L121, where an id is expected to be sent, butundefined
is sent really. If engine returns an error here https://github.com/prisma/prisma/blob/main/packages/client/src/runtime/getPrismaClient.ts#L1006, the rest of the code should be avoided? (these lines https://github.com/prisma/prisma/blob/main/packages/client/src/runtime/getPrismaClient.ts#L1008-L1022)I have been doing some tests with other drivers (
mysql2
), and there have'nt been problem with pressure, so I don't know if it's other additional issue, prisma should work under that pressure? I'm using https://github.com/mcollina/autocannon and the errors start when I use-p
(pipeling
). I have not too much experience with benchmarking, so I could be doing some bad assumptions or misunderstanding how I should be doing it. Anyway, that error is a real issue 😅How to reproduce
npm i
npm run start
npm run benchmark
it runs autocannonStringExpected....
)Expected behavior
Most useful errors, no errors (?)
Prisma information
I have used starter project from Prisma
Environment & setup
Prisma Version
The text was updated successfully, but these errors were encountered: