Principles of thread pool and Database Connection Pool

Source: Internet
Author: User
ArticleDirectory
    •  

This article briefly introduces the working principles of the database connection pool and thread pool, hoping to help you.

 

When the amount of data requested by the client is largeThread PoolIt can save a lot of system resources, so that more CPU time and memory can be used efficiently. WhileDatabase Connection PoolWill be greatly improvedProgramOperational Efficiency. At the same time, we can monitor the number and usage of database connections through its own management mechanism. This article mainly introduces the principle of thread pool and database connection pool. Next, let's take a look at this part.

Thread Pool principle:

In fact, the thread pool principle is very simple. It is similar to the buffer concept in the operating system. The process is as follows: Start a number of threads and make these threads sleep, when the client has a new request, it will wake up a sleep thread in the thread pool and let it process the request from the client. After processing the request, the thread is sleeping again. Maybe you may ask: why is it so troublesome? If a client has a new request, I will not finish creating a new thread? This may be a good method, because it enables you to writeCodeIt is relatively easy, But you ignore an important question? That's performance! Taking my unit as an example, my unit is a bank network center in a provincial big data set. The number of client request concurrencies per second exceeds 100 during peak periods, if you create a new thread for each client request, the CPU time and memory consumed will be astonishing. If you use a thread pool with 200 threads, this will save a lot of system resources, so that more CPU time and memory are used to deal with actual commercial applications, rather than frequent thread creation and destruction.

Principles of database connection pool:

Database connection is a key, limited, and expensive resource, which is particularly prominent in the Web applications of multiple users.

A database connection object corresponds to a physical database connection. Each operation opens a physical connection and closes the connection after use, resulting in low system performance. The solution of the database connection pool is to establish enough database connections when the application starts, and talk about these connections to form a connection pool (Simply put: store a lot of semi-finished database connection objects in a "pool"), and applications dynamically apply for, use, and release connections in the pool. For concurrent requests that exceed the number of connections in the connection pool, wait in the Request queue. In addition, the application can dynamically increase or decrease the number of connections in the pool based on the connection usage in the pool.

The connection pool technology can reuse as many memory-consuming resources as possible, greatly saving memory, improving Server service efficiency and supporting more customer services. By using the connection pool, the program running efficiency is 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 has been maintained by the connection pool. Therefore, if the application uses a small amount of database connections, a large amount of database connection resources will be wasted;

2) the maximum number of connections is the maximum number of connections that can be applied by the connection pool. If the number of database connection requests exceeds this limit, the subsequent database connection requests will be added to the waiting queue, which will affect subsequent database operations.

Here is an introduction to the principles of database connection pools and thread pools. I hope this introduction will bring you some benefits!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.