当前位置:网站首页>. net mysql Too many connections
. net mysql Too many connections
2022-06-12 07:54:00 【Ruoyun Liufeng】
One 、 problem
use .net Multithreaded mysql Data query and update , After the discovery program starts , You will report this error .
Too many connections
Two 、 analysis
1. Database side
use show processlist; Check the connection list . Many connections are found sleep, And it keeps increasing .
show variables like '%max_connections%'; see mysql The maximum number of connections found is only 100 many .
When the connection increases to the maximum number of connections , Not increasing , There are no new database connections .
2. Program side
Frequently used in each thread .net establish mysql The connection of , But it happens every time close.
The code snippet is as follows :
string ConnectStr = Connectconfig.GetReadNameConfig("MySql");
MySqlConnection conn = new MySqlConnection(ConnectStr);
connect.Open();
// Do something
connect.Close();
connect.Dispose();3. The problem is :
Mingming closes and releases it every time , Why is it mysql Inside the connection , The connection is not automatically released , It's just sleep 了 .
4. analysis :
After analysis, as long as the connection is created , also open,mysql There is a discount to store this connection , Whether or not close. because mysql The mechanism is that if you use this connection next time , direct open Just fine . You don't have to create connections every time , Yes mysql It's also consumption .
3、 ... and 、 solve
Scheme 1 ( Treat the symptoms, not the root cause ): utilize mysql The timeout mechanism of + Set the maximum number of connections
take mysql Set the maximum number of connections to 1000, Set the timeout to 30( second ), That is to say, before the number of connections reaches the set maximum , The first connection has been released due to timeout . Here's a premise , The first connection will not be used in the future , But generally, this problem can be encountered , It is estimated that the first connection will be difficult to use again in the program .
Set timeout method :
max_connections=1024Set the maximum number of connections method , Add... To the configuration file :
wait_timeout=30
interactive_timeout=30Option two :
This problem is first encountered frequently in threads the new Connection operation , If only new once mysql The connection of , Then only use this connection , It can solve the problem .
边栏推荐
- Voice assistant - overall architecture and design
- Numerical calculation method chapter6 Iterative method for solving linear equations
- 20220607. 人脸识别
- NaiveBayes function of R language e1071 package constructs naive Bayes model, predict function uses naive Bayes model to predict and reason test data, and table function constructs confusion matrix
- Multithread decompression of tar
- Vscode 1.68 changes and concerns (sorting and importing statements / experimental new command center, etc.)
- Search and rescue strategy of underwater robot (FISH)
- Leetcode notes: Weekly contest 296
- Voice assistant -- Architecture and design of Instruction Assistant
- Pytorch profiler with tensorboard.
猜你喜欢

Symfony 2: multiple and dynamic database connections

Leverage contextual information

AI fanaticism | come to this conference and work together on the new tools of AI!

tar之多线程解压缩

Primal problem and dual problem

Voice assistant - Qu - single entity recall

Scoring prediction problem

Explanation and explanation on the situation that the volume GPU util (GPU utilization) is very low and the memory ueage (memory occupation) is very high during the training of pytoch

Bi skills - beginning of the month

Utilize user behavior data
随机推荐
Chapter 3 - Fundamentals of cryptography
Ecmascript6 interview questions
Architecture and performance analysis of convolutional neural network
Multithread decompression of tar
LeetCode笔记:Biweekly Contest 79
Voice assistant - potential skills and uncalled call technique mining
Logistic regression
Chapter 4 - key management and distribution
Bi skills - beginning of the month
20220526 yolov1-v5
Voice assistant -- Qu -- semantic role annotation and its application
vscode 1.68变化与关注点(整理导入语句/实验性新命令中心等)
CONDA reports an error when creating a virtual environment, and the problem is solved
Improvement of hash function based on life game (continued 2)
Summary of machine learning + pattern recognition learning (V) -- Integrated Learning
Symfony 2: multiple and dynamic database connections
Compiling principle on computer -- functional drawing language (I)
Rnorm function of R language generates positive distribution data, calculates descriptive statistical summary information of vector data using sum function of epidisplay package, and visualizes ordere
Voice assistant - Multi round conversation (theory and concept)
2021.10.24-25 scientific research log