brianc / node-pg-pool

A connection pool for node-postgres

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

phongyu opened this issue · comments

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

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:

  • Your requests may be too short (under 1 millisecond), or maybe you have less than one request per second. It's ok to set max pool size to 1 or 2 for those.
  • Your requests may be too short (under 1 millisecond) and you have thousands of requests per second, and they mostly retrieve the same value again and again: add some sort of memory cache to your application (I actually do this for an IoT server handling thousands of inserts per second, most of them duplicate inserts because of m2m packet loss).