php -mysql performance issue - too many aborted connections

时间:2017-04-24 17:33:32

标签: php mysql mariadb

I'm testing performance using php and mysql. The symptom - after sustaining heavy load, all connections are closed and next trials to connect to db fails for a few seconds, then resume.

I've noticed mysql.error.log has thousand lines like this:

017-04-24 13:20:27 122496980240128 [Warning] Aborted connection 202348 to db: 'db' user: 'dbuser' host: '10.0.0.1' (CLOSE_CONNECTION)

I use this script to check what happens in a simple call to db and I've found that this script generate 10 lines like that

    $connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
mysql_select_db($dbname) or die("Could not open the db '$dbname'");
$test_query = "SHOW TABLES FROM $dbname";
$result = mysql_query($test_query);
$tblCnt = 0;
while($tbl = mysql_fetch_array($result)) {
  $tblCnt++;
  #echo $tbl[0]."<br />\n";
}
if (!$tblCnt) {
  echo "There are no tables<br />\n";
} else {
  echo "There are $tblCnt tables<br />\n";
}

my question - why is this behavior and is there any way to reduce it to 1 call or max 2 calls as it should.

0 个答案:

没有答案