Connection Pool Strategy: Good, Bad or Ugly?

后端 未结 6 2159
甜味超标
甜味超标 2021-01-31 18:10

I\'m in charge of developing and maintaining a group of Web Applications that are centered around similar data. The architecture I decided on at the time was that each applicati

6条回答
  •  天命终不由人
    2021-01-31 18:38

    If you have a single database, and two connection pools, with 5 connections each, you have 10 connections to the database. If you have 5 connection pools with 2 connections each, you have 10 connections to the database. In the end, you have 10 connections to the database. The database has no idea that your pool exists, no awareness.

    Any meta data exchanged between the pool and the DB is going to happen on each connection. When the connection is started, when the connection is torn down, etc. So, if you have 10 connections, this traffic will happen 10 times (at a minimum, assuming they all stay healthy for the life of the pool). This will happen whether you have 1 pool or 10 pools.

    As for "1 DB per app", if you're not talking to an separate instance of the database for each DB, then it basically doesn't matter.

    If you have a DB server hosting 5 databases, and you have connections to each database (say, 2 connection per), this will consume more overhead and memory than the same DB hosting a single database. But that overhead is marginal at best, and utterly insignificant on modern machines with GB sized data buffers. Beyond a certain point, all the database cares about is mapping and copying pages of data from disk to RAM and back again.

    If you had a large redundant table in duplicated across of the DBs, then that could be potentially wasteful.

    Finally, when I use the word "database", I mean the logical entity the server uses to coalesce tables. For example, Oracle really likes to have one "database" per server, broken up in to "schemas". Postgres has several DBs, each of which can have schemas. But in any case, all of the modern servers have logical boundaries of data that they can use. I'm just using the word "database" here.

    So, as long as you're hitting a single instance of the DB server for all of your apps, the connection pools et al don't really matter in the big picture as the server will share all of the memory and resources across the clients as necessary.

提交回复
热议问题