0

I am writing my backend using nodejs (express), and my database is PostgreSQL. I am using node-postres (pg) to connect to the postgres database.

Currently I am using the pg.Pool concept, so that I will have clients connected to serve the request/response. What I observe is the node-postgres takes more than 2 seconds to connect to the DB, and hence the response time is quite long.

In the node-postgres document, they mention that initial connection takes only 20 - 30 milliseconds. But I see more than 2-3 secs, to establish the connection. I did a load test on my app hitting around 1000 requests/ sec, but the average response time, is quite high due to the initial connection establish time. I have only a single SELECT query, where I get the response. The response processing time is very less, only the connection and getting data from DB takes more time.

I tried all the ways of releasing a client to the pool, after receiving the response etc.. Now I'm using pool.query which will take care of connecting, as well as releasing the client to the pool, after the task is done.

Is there any alternate for node-postgres which an provide a better performance for the DB operations.

user2733130
  • 157
  • 3
  • 16
  • Are your node server and pgSQL server on the same machine in this case? Or is the db hosted somewhere? Have you benchmarked just the connection part with all your application logic removed ? – Shobhit Chittora Apr 29 '19 at 07:08
  • No, both are in different machines. Yes the connection part only takes 2-3 secs. The application logic time is 10-12 milliseconds. The same pgSQL server, connection is faster if we use springboot. I did a small POC to connect to same pgSQL via spring boot. – user2733130 Apr 29 '19 at 07:13
  • Hmm.. I'm not sure if I have enough info here to dig any further. Can you possibly share some code snippets and also shed some light on your setup process ? – Shobhit Chittora Apr 29 '19 at 07:48
  • or does pg-native improve the perfomance ? Do you have any samples using pg-native? – user2733130 Apr 30 '19 at 10:17

0 Answers0