当前位置:网站首页>This article introduces you to the necessity of database connection pooling
This article introduces you to the necessity of database connection pooling
2022-06-23 20:45:00 【Gourmet Jianghu】
Do not use database connection pool :
In use to develop database based web The program , The traditional model Basically follow the following steps :
- In the main program ( Such as servlet、beans、DAO) Establishing database connection in .
- Conduct sql operation
- Disconnect the database .
This mode of development , The problem is :
ordinary JDBC Database connection use DriverManager To get , Every time you establish a connection to the database, you need to Connection Load into memory , Revalidation IP Address , User name and password ( It costs 0.05s~1s Time for ). When you need a database connection , Just ask the database for a , Disconnect after execution . This way will consume a lot of resources and time . The connection resources of the database are not well reused . If there are hundreds or even thousands of people online at the same time , Frequent database connection operations will occupy a lot of system resources , Serious even can cause the server to crash .
For every database connection , They have to be disconnected after use . otherwise , If the program is abnormal and Failed to close , Will lead to Memory leak in database system , It will eventually lead to a restart of the database .
This development cannot control what is created Number of connected objects , System resources will be allocated without consideration , If connected Too much , May also lead to Memory leak , Server crash .
The basic idea of database connection pool :
To solve the problem of database connection in traditional development , May adopt Database connection pool technology (connection pool) .
The basic idea of database connection pool A connection is a database “ Buffer pool ”. Put a certain number of connections in the buffer pool in advance , When you need to establish a database connection , Just from “ Buffer pool ” Take out one of , Put it back after use . The database connection pool is responsible for allocation 、 Manage and release database connections , it Allow applications to reuse an existing database connection , Instead of re establishing a .
When the database connection pool is initialized, a certain number of database connections will be created and put into the connection pool , The number of these database connections is set by the minimum number of database connections . Whether these database connections are used or not ,java train Connection pools will always guarantee at least so many connections . The maximum number of database connections in the connection pool limits the maximum number of connections that the connection pool can hold , When the number of connections the application requests from the connection pool exceeds the maximum number of connections , These requests will be added to the waiting queue .
Advantages of database connection pool technology :
Resource reuse :
Because database connections can be reused , Avoid frequent creation of , A lot of performance overhead caused by releasing connections . On the basis of reducing system consumption , On the other hand, it also increases the stability of the system operation environment .
Faster system response
The database connection pool is in the process of initialization , Often a number of database connections have been created for standby in the connection pool . At this time, the initialization of the connection is completed . For business request processing , Take advantage of the available connections directly , Avoid the time cost of database connection initialization and release , Thus, the response time of the system is reduced .
New means of resource allocation
For systems where multiple applications share the same database , It can be configured in the application layer through the database connection pool , Limit of the maximum number of available database connections for an application , Avoid an application monopolizing all database resources .
Unified connection management , Avoid database connection leaks
In a more complete database connection pool implementation , It can be set according to the pre occupation timeout , Force recycling of occupied connections , In this way, the possible resource leakage in the normal database connection operation is avoided .
边栏推荐
- Open source SPL redefines OLAP server
- Teach you how to develop desktop applications with web pages
- What is the role of short video AI intelligent audit? Why do I need intelligent auditing?
- 【Golang】深究字符串——从byte rune string到Unicode与UTF-8
- Emmet syntax specification
- Which is better for securities companies? I don't understand. Is it safe to open an account online?
- What is the main content of short video audit? What is illegal?
- JS takes two decimal places
- [golang] follow the object pool sync Pool
- What cloud disk types does Tencent cloud provide? What are the characteristics of cloud disk service?
猜你喜欢

UGeek大咖说 | 可观测之超融合存储系统的应用与设计

Applet development framework recommendation

测试的重要性及目的

Syntax of SQL union query (inline, left, right, and full)

After the collapse of UST, will the stable currency market pattern usher in new opportunities?

Kubernetes resource topology aware scheduling optimization

Implementation of microblog system based on SSM

The "open source star picking program" container pulls private images from harbor, which is a necessary skill for cloud native advanced technology

Add two factor authentication, not afraid of password disclosure, let alone 123456

vs2022scanf函数的使用,使用scanf的报错-返回值被忽略:解决·方法
随机推荐
【Golang】深究字符串——从byte rune string到Unicode与UTF-8
手续费佣金低的券商,华泰证券网上开户安全吗
【Golang】怎么实现Go程序的实时热更新
Development and code analysis of easycvr national standard user defined streaming address function
Deep learning of handlebar handwriting (15): building your own corpus on hugging face
More than 1200 phishing kits that can intercept 2fa detected in the field
Eight misunderstandings, broken one by one (final): the cloud is difficult to expand, the customization is poor, and the administrator will lose control?
Implementing MySQL fuzzy search with node and express
What are the server host security risks? How to prevent safety risks?
How to solve the problem that the ID is not displayed when easycvr edits the national standard channel?
Tupu software digital twin intelligent water service, breaking through the development dilemma of sponge City
Command line add user set password never expires add remote group add administrator group
Use of paging components in fusiondesign
Install bitgarden open source password manager
【Golang】在Go语言的角度重新审视闭包
怎么开户?在国海证券开户安全吗?需要带什么?
Short video intelligent audit software intelligent audit or manual audit
SQL聯合查詢(內聯、左聯、右聯、全聯)的語法
Row height, (top line, middle line, baseline, bottom line), vertical align
After the collapse of UST, will the stable currency market pattern usher in new opportunities?