Database connection pool

xiaoxiao2021-03-06  94

The database connection pool allows applications to reuse databases that exist in the pool to avoid repeatedly establish new database connections. This technology can effectively improve the scalability of the application, because limited database connections can provide a large number of customers. This technology also improves system performance, avoiding a large number of newly-established overhead. Developing a scalability, high-performance applications should minimize the time spending for the establishment of connectivity, keeping the database connection maximum effectiveness to access data. When a database connection is turned off, it is only reserved by the connection pool and is not truly released. However, if the connection pool is released, the database connection will be released. Developers should be taken not to rely on the garbage collection mechanism to release the database connection, because when the parameter is outside the scope, the database connection does not have the necessary shutdown. This database resource leak will result in the establishment of a new connection. Creating a DB connection pool When you open a database connection, a database connection pool is created. The creation of the database connection pool is accurately correlated with the database connection string (including space, case). All connection pools are distinguished according to the connection string. When you create a new database connection, you will create a different connection pool if the connection string is not exactly identical. Once the database connection pool is created, it will always exist until the end. Maintaining a non-active connection pool hardly does not need any system overhead.

The database connection connection pool in the connection pool is created according to the unique connection string. While the connection pool is created, the connection pool will create the minimum database connection. When the connection is not enough, the connection pool adds a database one by one to the maximum number, and the subsequent connection request will be joined in the request queue. When the CLOSE method or Dispose method of the database connection object is called, the database connection will be reclaimed by the database connection pool. When the database connection is complete, call the Close method or the Dispose method to return it to the connection pool. Database connections without explicitly release may not return the pool. Note Do not call any management classes such as Connection, DataReader, etc. in the class's Finalize method, you must pass the release rights of the database connection to the connection pool. Release Database Connections When the database connection timeout or service has been completed, the connection pool will release its resource, which can only be judged by trying to communicate with the database. If the database connection is discovered, it will be marked as unavailable resources. The database connection pool will schedule the database connection to release all unavailable resources. If the existing database connection is found, it may be that the connection is marked by the database connection pool as an unavailable resource, and an exception will be thrown. Despite this, you must also release the connection and return it to the connection pool. Supporting the database connection in the Transaction database connection pool is divided according to Transaction Context, and whenever the connection pool is connected to the connection request, he returns a database connection that matches the requester Transaction Context. Therefore, each connection pool consists of a database connection associated with several transaction context and a database connection-independent database connection. When the database connection is returned to the connection pool, it will be placed back in the corresponding Transaction Context group.

Database connection pool definition: Allows applications to reuse the database connections existing in the pool to avoid repeated creation of new database connections.

Benefits using a database connection pool: Avoid repeated creation of new database connections to improve system performance and the scalability of the program.

Where to pay attention: Do not use database connections in the garbage collection mechanism recovery system, the recycling and release of database connections should be handed over to the database connection pool.

转载请注明原文地址:https://www.9cbs.com/read-122122.html

New Post(0)