#747·postgres

A weird issue: speed dropped

Author: stan023Created Nov 30, 2023Updated Sep 29, 2026
Labelsbug

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.