I am trying to fix issues with very slow Azure App Services to Azure Database connection.
After Wordpress migration form cheap OVH hosting I noticed extremely long TTFB: increase from 300-400ms to 1500-3000ms.
I narrowed the problem to app service - database connection issue. To pinpoint the problem I created clean Wordpress installation. According to P3 - Plugin Performance Profiler, clean WP installation creates 38 database queries.
With PHP/MySQL CPU performance statistics plugin I ran MySql Test:
- Azure App Service: 20-50 db queries / second
- Cheap OVH hosting: 200+ db queries / second
I think the problem is pretty obvious if 200 USD/mo Azure stack is roughly 20 times slower than 10 USD OVH (however: I have found out that even ~40 db queries per second can result in TTFB around 300ms, which I am aiming for).
To fix this issue I tried the following tests/changes:
- different App Service Plans (from dev to P2v3)
- different Azure Database servers (from cheapest to ~300 usd/mo)
- PHP 7.4 and PHP 8.0
- Apache and nginx (comes automatically with php 7/8 change)
- Azure Database Single and Flexible servers
- Azure Database for MySQL and for MariaDB
- app service to database connection via public IP and via vnet integration
- placing database in exactly same availability zone
- ssl and non-ssl app/database connections
- database redirections with mysqlnd_azure
- tried connection persistance
- Wordpress in App Service docker container
None of the above made any significant change in performance. The only "fix" that "works" is to enable cache. If cache is hit, TTFB is around 100 ms as expected.
I also benchmarked AWS Elastic Beanstalk/RDS and Google App Engine/CloudSQL and they work perfect (~250 ms TTFB out of the box). An Azure VM (PHP+ Apache) connected to same Azure Database works fine (<300ms TTFB).
I am out of ideas. What am I missing? To be clear: I am not trying to achieve single digit response times or ultimate performance - 300ms would be acceptable for a clean WP installation.