Nous avons 150 bases de données qui tournent sur le serveur et parfois il y a un problème de "trop de connexions" et il y a aussi beaucoup de requêtes dormantes qui tournent sur le processus MySQL. Le temps des requêtes dormantes est supérieur à 200. Vous trouverez ci-dessous la configuration my.cnf du serveur. J'ai augmenté le max_connections de 500 à 750 mais les connexions augmentent parfois au-delà de 750. Est-il sûr d'augmenter le max_connections à 1000 ou d'avoir besoin d'une configuration supplémentaire dans le my.cnf ? Je vous demande de m'aider, s'il manque quelque chose dans la configuration.
[mysqld]
performance-schema=0
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
query_cache_type=1
slow_query_log=1
slow_query_log_file="/var/log/mysql/mysql_slow.log"
max_connections = 750
default-storage-engine=MyISAM
innodb_file_per_table=1
max_allowed_packet=268435456
open_files_limit=43000
bind-address=0.0.0.0
innodb_buffer_pool_size= 6G
wait_timeout = 300
key_buffer_size = 2G
read_buffer_size = 16M
bulk_insert_buffer_size = 512M
myisam_sort_buffer_size = 2M
sql_mode = 'NO_ENGINE_SUBSTITUTION'
query_cache_limit = 536870912
query_cache_size = 268435456
Threads Running On Mysql
mysql> show status like "%Threads%";
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| Delayed_insert_threads | 0 |
| Slow_launch_threads | 0 |
| Threads_cached | 12 |
| Threads_connected | 659 |
| Threads_created | 38451 |
| Threads_running | 1 |
+------------------------+-------+
les résultats de l'étude htop :
1 [| 1.3%] 11 [ 0.0%] 21 [ 0.0%] 31 [ 0.0%]
2 [|| 3.2%] 12 [|||| 29.5%] 22 [ 0.0%] 32 [ 0.0%]
3 [ 0.0%] 13 [ 0.0%] 23 [| 0.6%] 33 [ 0.0%]
4 [||| 21.3%] 14 [|||| 26.1%] 24 [|| 2.6%] 34 [ 0.0%]
5 [| 0.6%] 15 [| 0.6%] 25 [|| 1.9%] 35 [ 0.0%]
6 [|||| 26.3%] 16 [|| 3.2%] 26 [|| 1.3%] 36 [ 0.0%]
7 [|| 1.9%] 17 [|| 4.5%] 27 [ 0.0%] 37 [ 0.0%]
8 [|| 3.8%] 18 [|| 5.8%] 28 [ 0.0%] 38 [ 0.0%]
9 [| 0.6%] 19 [ 0.0%] 29 [ 0.0%] 39 [ 0.0%]
10 [|| 4.5%] 20 [|| 5.1%] 30 [ 0.0%] 40 [ 0.0%]
Mem[|||||||||||||||||||17.7G/62.7G] Tasks: 132, 473 thr; 3 running
Swp[| 89.0M/7.81G] Load average: 1.03 0.97 0.90
Uptime: 22 days, 16:31:03
PID USER PRI NI VIRT RES SHR S CPU% MEM% TIME+ Command
14706 mysql 20 0 29.3G 13.7G 10816 S 12.2 21.9 37h23:37 /usr/sbin/mysqld
Connexion à la base de données script (PHP) :
<?php
class setting{
private $conn;
private $dbs;
function __construct($cid){
$client=$this->getclientbyid($cid);
$db=new db_bridge($client['website']);
if(!$db->exist()){
echo($client['website']." not exist in our DB");
die;
}
else{
$db->setid();
$this->setdb($db->get());
}
}
function __destruct(){
$this->dbs=null;
}
function setdb($db){
$this->conn=$db;
self::connect();
}
function connect(){
try{
$this->dbs=new PDO("mysql:host=".$this->conn['host'].";dbname=".$this->conn['db'], $this->conn['duser'],$pass);
}
catch(Exception $e){
echo "Unable to connect Database";
}
}
protected function query($query,$both=false){
$result=$this->dbs->prepare($query);
$result->execute();
if(!$both){
$rs=$result->fetch(PDO::FETCH_ASSOC);
}
else{
$rs=$result->fetch(PDO::FETCH_BOTH);
}
return $rs;
}
}