I've been tasked with dealing with a load of performance problems in an existing Adonis/Knex/Postgres API app. I'm new to Knex, and one issue I'm noticing right away is that the majority of time servicing an API request is spent in releasing connections to the pool. I'm often seeing times over 100ms, and have seen up to 400ms.
The problem is made worse by the fact that Knex acquires and releases the connection for each query (there are usually multiple DB queries behind a single API hit).
For example one API request is taking around 450ms, and only 150ms of that is retrieving the data. According to the knex log output, the vast majority of that 300ms overhead is releasing connections.
So, a few questions
Is it expected that releasing the connection would take so long?
Is there anything I can do to speed it up?
I see there is support for manually acquiring a connection and passing it to queries, but that seems like going against the grain. Is it normal to do that to improve performance?
Thanks very much