The difference between thread pool and connection pool

This article is reserved for searching information: https://blog.csdn.net/sjyttkl/article/details/75577178
1. The principle of thread pool:

Thread pool, what is going on? In fact, the principle of the thread pool is very simple, similar to the concept of the buffer in the operating system, and its process is as follows:

Start a certain number of threads first, and let these threads sleep. When the client has a new request, it will wake up a sleeping thread in the thread pool and let it process the client's request. After the request, the thread is sleeping again.

Maybe you may ask: why bother, if every time the client has a new request, I just create a new thread and it's over? This may be a good approach because it makes writing code relatively easier, but you're missing an important issue - performance

Take my unit as an example. My unit is a bank network center with a large concentration of provincial data. During peak periods, the number of concurrent client requests per second exceeds 100. If a new thread is created for each client request, The CPU time and memory consumption will be staggering. If a thread pool with 200 threads is used, it will save a lot of system resources, so that more CPU time and memory can be used to process actual business applications, while Not frequent thread creation and destruction.

2. Database connection pool

Database connections are a critical, limited and expensive resource, especially in multi-user web applications.

A database connection object corresponds to a physical database connection, each operation opens a physical connection, and closes the connection after use, which results in low performance of the system. The solution of the database connection pool is to establish enough database connections when the application starts, and combine these connections into a connection pool (simply put: a lot of semi-finished database connection objects are placed in a "pool"), which is dynamically controlled by the application. Apply, use, and release connections in the pool. For concurrent requests that are more than the number of connections in the connection pool, they should be queued in the request queue. And the application can dynamically increase or decrease the number of connections in the pool according to the usage of connections in the pool.

The connection pool technology reuses memory-consuming resources as much as possible, greatly saves memory, improves server service efficiency, and can support more customer services. By using the connection pool, the efficiency of the program will be greatly improved. At the same time, we can monitor the number and usage of database connections through its own management mechanism.

1) The minimum number of connections is the database connection that the connection pool has always maintained, so if the application does not use a large amount of database connections, a lot of database connection resources will be wasted;
2) The maximum number of connections is the maximum number of connections that the connection pool can apply for The number of connections. If database connection requests exceed this number, subsequent database connection requests will be added to the waiting queue, which will affect subsequent database operations.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325151537&siteId=291194637