postgres
postgres copied to clipboard
A weird issue: speed dropped
Here is my code:
import express from "express";
import postgres from "postgres";
const sql = postgres('postgres://test:[email protected]:5432/test')
const port = 3000;
const app = express();
app.get("/", async (req, res) => {
for (let i = 1; i <= 20; i++) {
const xs = await sql`select * from posts where id=1`
}
res.send(`ok`);
});
app.listen(port, () => {
console.log(`Listening on port ${port}...`);
});
I run the following ab test:
ab -n 2000 -c 5 http://localhost:3000
( number:2000, concurrency: 5 requests at a time)
The result is stable at around 900/sec, whatever times repeat the command.
Then I run:
ab -n 2000 -c 10 http://localhost:3000
(change 5 to 10)
The result is still around 900/sec
Then issue came. When I run
ab -n 2000 -c 5 http://localhost:3000
(change 10 back to 5)
After repeat this command several times, the results significantly dropped to 150/sec, and even keep dropping.
If I restart the express server, and run the above command, it become stable at 900/sec again.
This issue is that, if I set -c 10 and then set -c 5, the reqeusts/sec will drop significantly.
I have tested both ts-node and bun, both express and bun native serve, same issue occured.
Can confirm experiencing same issue in bun, performance degrades between stress test. Notably the issue is only present when max connections is set great than 1. So it may be a pooling issue.
This is a very nice repro @lnlife ! Thank you! I've looked closer, and there's a really bad regression all the way back from 3.0.1. I'll be looking deeper into this tomorrow.
Is this still happening? I was about to go all in on postgres
for some of the services in our codebase given the sheer amount of performance problems with Prisma.
Is this still happening? I was about to go all in on
postgres
for some of the services in our codebase given the sheer amount of performance problems with Prisma.
Yes it is. I have to set {max:1}
in the connection option to stop pool. Even so, it is still the fasted client.
any update on this?