brianc / node-pg-pool

A connection pool for node-postgres
MIT License
180 stars 64 forks source link

How to specify an optimal number for the max size of Pool #77

Open phongyu opened 6 years ago

phongyu commented 6 years ago

Hi Brianc, I have just a concern about how to specify the max size (min size) of Pool, mean an optimal number. I know it depends on the server configuration, but can you give me some hints.

Thanks

matonga commented 5 years ago

Hi, this is more difficult than it seems, so I would like to contribute a simple formula to get a very rought approximation:

Suppose you have 50 requests per second, and each request lasts for 0.2 seconds (200 milliseconds). If you set max size of pool to 1, after 1 second you would handle just 5 requests, leaving the other 45 requests still unhandled. Instead you can do something like this:

50 requests per second * 0.2 seconds per request = 10 connections needed in parallel to handle the load (i.e. set max size of pool to this value, 10 in this example)

Some caveats: