Search code examples
databasedatabase-connectionconnection-poolingdistributed-computingdistributed-system

What is desirable number of connections in a pool?


Imagine we have a client which wants to send N queries in parallel and a single node DB server. Server has 4 CPU cores and network device to receive/send data. Does this mean that there is no reason to have more than 4 parallel connections to server because it can only receive 4 "streams" of data in parallel? Not even speaking about disk i/o etc...

Speaking about network, on physical level there are no parallelism so we have no gains because of parallel connections on this level, right?

What would be desirable number of connections in client's connection pool? What should be taken into consideration? Maybe some articles on this topic?

Edit: if we optimize for latency and not throughput


Solution

  • I think you ultimately need to measure and it depends on nature of your queries too but HikariCP has a nice article dealing with connection pool sizing: https://github.com/brettwooldridge/HikariCP/wiki/About-Pool-Sizing

    You should test your application, i.e. simulate expected load, and try different pool settings around this starting point: connections = ((core_count * 2) + effective_spindle_count)