I’d say 2x the number you expect to have connect to the database as you can not change the value without bouncing the service and downtime is usually hard to come by. Just set the monitoring solution at 50%. That’s what I currently do; using a max connection of 2000 with an average connection rate of around 800. That sounds like a lot but with 96 cores that’s only around 9 connections per core.
Take a look at pg_bouncer. The problem with a high number of connections is that the idle connections will wake up from poll() and spin on the cpu. I’m in the process of testing pg_bouncer to reduce the number PostgreSQL connections to resolve the high server load due to idle sessions. pg_bouncer has proven to be effective as it doesn’t suffer from the idle poll() issue and it has reduced the server load due to idle sessions. I have been wondering if PostgreSQL used kqueues instead of poll if it would allow the server to scale better without having to introduce pg_bouncer. |