brianc/node-pg-native

[performance] pg-native first query is 10x/20x slower compared to pg (parallel requests)

Opened this issue · 0 comments

Hi,

i'm making some parallel requests (local db), let's say 3/4 request to the same table, very basic query:

4x of select * from user where id = $1
running in parallel with Promise.all()

when i make the first 4 parallel requests i see a completion time of around 60ms.
calling again the code, it's much faster, ~5ms.
if i wait ~10 second, and call again the code is see again the 60ms delay,
like if the pg client needs to connect to the db, and after a shot timeout, it disconnects.

i'm using the library as it's the same as the pg javascript client (so i can switch to the native and back with easy).
no special settings, only the stuff for connecting to the database.

using the pg javascript library i only see a first delay of around ~9 - 11 ms.

if i use the pg-native client without running parallel request i don't see the huge delay of 60ms, just ~7ms.

it's probably connected somehow to pools and timeouts, any way to improve those first query?