We had a very small MySQL DB of 150MB, which was running very fast with AWS t2.large database as Self Hosted.
H/W spec: Azure: 2vCPU, 10GB memory, AWS: 2 vCPU, 8GB Memory.
However, the company decided to move the AWS DB to the Azure Managed MySQL, and keep the PHP application in the EC2 for now.
H/W both servers equal in fact Azure had 2GB extra memory, with both have vCPU = 2,
Once moved to the Azure we saw massive performance degradation,
Example: In AWS ajax request took 15 sec, In Azure same ajax request takes 2.5 minutes.
Azure MySQL DB - the average %CPU and % Memory have never reached 50% of their allocated resource, so the specs do not seem to be the problem.
As per the question below PHP on Azure App Service slow performance when connected to Azure Database for MySQL
We did turn the Azure MySQL DB server parameter redirect_enabled to ON and enabled Enforce SSL with TLS 1.2.
And installed the "mysqlnd_azure" extension as well, usinge
sudo pecl install mysqlnd_azure
As per this below link we check this has any effect on the connection but it seems hostname is the same with no change
https://learn.microsoft.com/en-us/azure/mysql/howto-redirection#confirm-redirection
In the below "Test code" if redirection is set to ON it gives me a error "Connect error (2002):" If redirection set to off in the ini file, Test code goes to the else with same HOST name, which suggest that redirection is not working, However can see mysqlnd_azure extension is loaded and table names are shown correctly in the resultset
<?php
$host = '<yourservername>.mysql.database.azure.com';
$username = '<yourusername>@<yourservername>';
$password = '<yourpassword>';
$db_name = 'testdb';
echo "mysqlnd_azure.enableRedirect: ", ini_get("mysqlnd_azure.enableRedirect"), "\n";
$db = mysqli_init();
//The connection must be configured with SSL for redirection test
$link = mysqli_real_connect ($db, $host, $username, $password, $db_name, 3306, NULL, MYSQLI_CLIENT_SSL);
if (!$link) {
die ('Connect error (' . mysqli_connect_errno() . '): ' . mysqli_connect_error() . "\n");
}
else {
echo $db->host_info, "\n"; //if redirection succeeds, the host_info will differ from the hostname you used used to connect
$res = $db->query('SHOW TABLES;'); //test query with the connection
print_r ($res);
$db->close();
}
?>
Application is done with Code-igniter and PEAR.
Does anyone have a similar experience when running Code Igniter with Azure MySQL DB with AWS EC2? and Any suggestions to fix this issue?