当前位置:网站首页>What is the appropriate setting for the number of database connections?
What is the appropriate setting for the number of database connections?
2022-06-13 11:32:00 【Programming life】
Introduction
Many engineers are used to using a component , Parameter settings depend on default values . Or sometimes you want to rely on data analysis to obtain more appropriate values , Finally, it is found that the data considered is too one-sided or difficult to collect. Finally, the size of the parameters is determined by patting the head . Today, let's take the database connection number parameter as an example to illustrate how to design parameters .
Prerequisite knowledge
First, let's explain the concept of the number of database connections . The number of database connections generally refers to the database connection pool . The database connection pool is responsible for allocation 、 Manage and release database connections , It allows applications to reuse an existing database connection , Instead of building a new ; Release database connection with idle time exceeding the maximum idle time to avoid missing database connection caused by no free database connection .
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 limited by the minimum number of database connections . Whether these database connections are used or not , 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 .
The following factors should be considered when setting the minimum and maximum connection numbers of database connection pool :
1. maximum connection
it (maxActive) Is the maximum number of connections that the connection pool can apply for , If database connection requests exceed this number , Later database connection requests will be added to the waiting queue , This will affect subsequent database operations .
2. Minimum connections
it (minIdle) Is the database connection that the connection pool keeps , So if the application uses a small amount of database connections , There will be a lot of database connection resources wasted .
3. The difference between the minimum number of connections and the maximum number of connections
The difference between the minimum number of connections and the maximum number of connections is too large , Then the first connection request will be profitable , Then a connection request that exceeds the minimum number of connections is equivalent to establishing a new database connection . however , These database connections greater than the minimum number of connections will not be released immediately after use , It will be put into the connection pool to be reused or released after idle timeout .
How to determine the maximum number of connections ?
Many friends feel that their systems need a lot of throughput , High concurrency , You should set the number of connections as large as possible . Let's take a look at an experiment done by crooked nuts :
Askew nut pair Oracle The database was stress tested , simulation 9600 Concurrent threads to operate the database , Between every two database operations sleep 550ms, The initially set thread pool size is 2048.
result :
Each request is waiting in the connection pool queue 33ms, After getting the connection , perform SQL take 77ms, CPU Consumption is maintained at 95% about ;
Next , We'll make the connection pool smaller , Set to 1024, Other test parameters remain the same .
result :
The waiting time for getting the connection is basically the same , however SQL The execution time of is reduced .
Next , Let's make it smaller , The size of the connection pool is reduced to 96, Other parameters such as concurrent number are unchanged .
result :
The average waiting time for each request in the connection pool queue is 1ms, SQL The execution time is 2ms.
Actually , In general , maximum connection 200 yes DBA I will be afraid of the number after reading it .200 A connection , It means that there is 200 Concurrent channels . In terms of system impact , When the concurrency is high , It will affect CPU、 Memory 、 disk IO Indicators of , It may even bring down the server . In terms of business impact , quite a lot SQL Parallel execution , Added SQL The probability of interaction , Resulting in a higher lock waiting rate .
For the impact on the server, please refer to my previous article on concurrency . It should be noted that the number of connections is the protection of the database server , The quality of the general database server is OK SSD Hard disk device , No slow queries , The average database processing time is 2ms The following request , maximum connection 10 Accessible TPS To 5000. It is sufficient for general systems . More accurate still depends on the actual pressure measurement results .
Programming lifetime
Because the official account platform changed the push rules. , If you don't want to miss the content , Remember to click after reading “ Looking at ”, Add one “ Star standard ”, In this way, each new article push will appear in your subscription list for the first time .
Want to know what updates you missed , Please refer to the information I update from time to time 《 A collection of articles 》.
边栏推荐
- Interval modification multiplication and addition (a good example of understanding lazy tags)
- MFC自定义button实现颜色控制
- 统计特殊子序列数目(0,1,2)DP
- Meta universe land: what makes digital real estate valuable
- St table learning
- Vivo large scale kubernetes cluster automation operation and maintenance practice
- ue5 小知识点 geometry script modeling
- Ubuntu installs MySQL compressed package for future reference
- 以梦为马之89c51单片机驱动lcd
- Web3和NFT中的匿名性问题
猜你喜欢
元宇宙土地:是什么让数字房地产变得有价值
ARM64 上的性能怪兽:API 网关 Apache APISIX 在 AWS Graviton3 上的安装和性能测试
数位DP例题
Interval modification multiplication and addition (a good example of understanding lazy tags)
17 pictures: read and understand the first domestic guide for mainframe security capacity building
ARM64 上的性能怪兽:API 网关 Apache APISIX 在 AWS Graviton3 上的安装和性能测试
View the default MySQL password in the pagoda
Go 要加个箭头语法,这下更像 PHP 了!
Audio and video technology development weekly 𞓜 249
[tcapulusdb knowledge base] tcapulusdb operation and maintenance doc introduction
随机推荐
22、ADS使用记录之E类功放设计(下)
Gauss elimination for solving N-element equations
Determine the maximum match between bipartite graph and bipartite graph
Ubuntu installs MySQL compressed package for future reference
Web3和NFT中的匿名性问题
22. Class E power amplifier design of ads usage record (Part 2)
【TcaplusDB知识库】Tmonitor单机安装指引介绍(二)
元宇宙土地:是什么让数字房地产变得有价值
【TcaplusDB知识库】TcaplusDB运维单据介绍
Analysis and summary of 2021ccpc online games
程序员面试这么重视考察概念还是第一次见
【TcaplusDB知识库】Tmonitor系统升级介绍
【TcaplusDB知识库】TcaplusDB集群管理介绍
Mac 安装 MySQL 教程
我是如何解决码云图床失效问题?
Acwing game 55
2020 ICPC Asia Taiwan Online Programming Contest C Circles
Use of servers
关于 SAP Spartacus CmsService.getComponentData 可能的优化思路
Codeforces Round #798 (Div. 2)ABCD