pgx icon indicating copy to clipboard operation
pgx copied to clipboard

default MaxConnections to runtime.NumCPU()

Open nhooyr opened this issue 9 years ago • 2 comments

I think MaxConnections of ConnPoolConfig should default to runtime.NumCPU()

nhooyr avatar Jan 29 '17 11:01 nhooyr

I think there are 2 cases:

  1. MaxConnection may be limited be application architecture (for example only 3 threads can make db request). For this case defaults to number of cpu is useless.
  2. MaxConnection can be limited by system performance (for example high load app). In this case NumCPU is not an ideal: what if db server has 64 cores, but app server has only 4 cores and performs hard-for-db-server quires?

As a result NumCPU looks not better than current "5". I think it is better to require always set this parameter manually.

anton-becker avatar Jan 29 '17 14:01 anton-becker

MaxConnections should usually be determined by the server. A general rule for a PostgreSQL server is the server is most efficiently used with around 2 * numCores connections (https://wiki.postgresql.org/wiki/Number_Of_Database_Connections).

However, there is no way for a client application to know the resources of the server and the resources used by other clients.

5 is simply a safe default that allows some parallelism on the client side and ensures that it doesn't consume an unexpectedly high amount of server connections.

jackc avatar Jan 29 '17 15:01 jackc