Creating a database connection pool

前端 未结 7 2076
失恋的感觉
失恋的感觉 2020-12-30 12:48

Need information on creating a connection pool to the database (irrespective of the database) , and how efficient they are? What are the conditions where they can enhance pe

7条回答
  •  旧时难觅i
    2020-12-30 13:40

    Creating a database connection may or may not be an expensive operation, depending on your environment and what you intend to do with it.

    If you're going to run a single very easy query, then connecting probably takes as long (or longer) than the query.

    Some databases have a much bigger connection overhead than others; if tuned correctly, mysql should have very little (above the time to make a tcp connection and do the protocol handshake). However, if latency to your server is very high, even this can be quite significant (particularly if you intend to do only a few queries).

    If you're planning to do, say, 100 queries, or a few really slow queries, then the connection time disappears into insignificance.

    In generally I'd say open a new connection each time until you can demonstrate that it's a real performance problem. Using connection pooling can lead to BUGS, which we don't like:

    • Connection state wasn't COMPLETELY reset after the previous use in the pool - so some state lingers and creates unexpected behaviour resulting in a bug
    • Connection was closed in some way (perhaps by a stateful firewall timeout) which cannot be detected, therefore an app tries to use a closed connection, causing a long delay or failure

提交回复
热议问题