Improving your WordPress workload performance on Azure Database for MySQL
Published May 26 2020 03:29 PM 17.8K Views
Microsoft

WordPress is one of the most popular blogging tools in the world. Azure Database for MySQL allows users to create, configure and optimize a cloud-based WordPress site that enables easy customization and the ability to handle a large number of site visitors. 

 

WordPress workloads tend to be read-heavy, which occasionally causes issues with performance.  With research, and by using optimization techniques and performance testing, we’ve been able to identify some parameters that you can change to improve performance for your WordPress workloads.  

 

How to leverage the research we've done

To improve the out-of-the-box experience that customers have for a newly provisioned WordPress instance, we've set the following parameters and values by default for both General Purpose 2 vCore and 4 vCore instances.  You may notice a resource tag with the label: ‘AppProfile’: ‘Wordpress for your Azure Database for MySQL instance.  Behind the scenes, this enables us to set the optimal parameter values automatically for you.   

 

For any existing General Purpose 2 vCore and 4 vCore servers you already have, there are two options available for you to take advantage of the performance optimizations we will be explaining in this blog.  

 

  • If you want the MySQL service to handle updating the server parameters on your behalf, you can update your server's resource tag with the following name and value. Once you've saved the resource tag, the service backend will need to be triggered to allow for automatic server parameter defaults. You can trigger this by scaling the vCores of your server up to 4 vCores and back down to 2 vCores.   
    • Name: AppProfile  
    • Value: Wordpress 
  • Update the server parameters manually based on the ranges we describe in the rest of the blog. Learn about how to update server parameters yourself by referring to the Azure portal and Azure CLI documentation.   

 

Follow the recommended tuning guidance below to see performance improvements within your WordPress workload.   

 

Understand metrics for your WordPress workload 

With a read-heavy workload, queries executing against your WordPress server could exceed the in-memory temporary table sizes. This will cause your server to switch to writing temporary tables to diskthus affecting the performance for your WordPress instance. 

 

To determine if your server is writing to disk as a result of exceeding temporary table size, look at the following metrics: 

show global status like 'created_tmp_disk_tables'; 
show global status like 'created_tmp_tables'; 

The created_tmp_disk_tables metric indicates how many tables were created on disk, while the created_tmp_table metric tells you how many temporary tables have to be formed in memory given your workload. 

 

To determine if running a specific query will use temporary tablesrun explain on the query. The detail in the 'extra' column indicates 'Using temporary' if the query will run using temporary tables. 

 

To calculate the percentage of your workload with queries spilling to disks, use your metric values in the formula below: 

(created_tmp_disk_tables / (created_tmp_disk_tables + created_tmp_tables)) * 100 

Ideally, this percentage should be less 25%. If you see that the percentage is 25% or greater, we suggest modifying two server parameters, tmp_table_size and max_heap_table_size. 

 

Calculate optimal parameter values 

To calculate the values required for tmp_table_size and max_heap_table_size, look at the total per-connection memory values and the base memory. The sum of per-connection memory parameters, excluding tmp_table_size, combined with the base memory accounts for total memory of the server.   

 

To calculate the largest possible size of tmp_table_size and max_heap_table_sizeuse the following formula: 

(total memory - (base memory + (sum of per-connection memory * # of connections)) / # of connections 

Total memory indicates the total amount of memory the server has across the vCores provisioned.  For example, in a General Purpose 2 vCore Azure Database for MySQL server, the total memory will be 5GB * 2, and in a General Purpose 4 vCore Azure Database MySQL server, the total memory will be 5GB * 4. More details about memory for each tier can be found in the pricing tier documentation. 

 

Base memory indicates the memory variables, like query_cache_size and innodb_buffer_pool_size, that MySQL will initialize and allocate at server start.  Per connection memory, like sort_buffer_size and join_buffer_size, is memory that is allocated only when a query requires it. 

 

Adjust parameter values for performance improvement 

Using the information above, we ran a few experiments using General Purpose 2 vCore and 4 vCore Azure Database for MySQL servers separately with a workload that consisted of ~90% read queries across 150 concurrent connections.  

 

First, we increased both tmp_table_size and max_heap_table_sizeNext, since we increased tmp_table_size and max_heap_table_size, we also decreased innodb_buffer_pool_size The values we set were within the range: 

2vCore 

innodb_buffer_pool_size: 6442450944 - 6979321856 
max_heap_table_size: 41943040 - 54525952 
tmp_table_size: 41943040 - 54525952 

 

4vCore 

innodb_buffer_pool_size: 15111379968 16106127360 
max_heap_table_size: 114322780 - 134217728 
tmp_table_size: 114322780 - 134217728 

 

Making this adjustment improved performance in our read-heavy scenario and enhanced our out-of-the-box experience using WordPress with Azure Database for MySQL. 

 

How to provision a server with these optimized server parameters

To take advantage of the adjustments we've made, you can set the following resource tag on your General Purpose 2 vCore or 4 vCore server at time of server creation: 

  • Name: AppProfile
  • Value: Wordpress

 

We're always looking to improve, so let us know if you have other parameters you tune to get better performance with WordPress by leaving a comment below!  You can also provide us feedback on Uservoice.

 

Thanks for reading!

 

Mollee Jain & Yanwen Jin

Software Engineer, Azure OSS Databases team

9 Comments
Copper Contributor

I run my Wordpress instance using Azure AppService and Azure MySQL and this article was recommended to me by the automated Azure service recommendations engine.  Clicking in to this post, I've got to say that I was *very* confused about where I should put these parameters -- App Service?  App Service Plan?  MySQL instance?  I'm pretty sure that it should be on the MySQL instance but it would be helpful to add that detail somewhere in this article.  It would also be helpful to put in some screenshots.  

Copper Contributor

If we apply the resource tag to let Azure apply recommendations automatically, how quickly will azure adjust the sever and how do you tell if it is working?

Copper Contributor

Hi @benday_ , this article was recommended for me also by the automated Azure service engine.  I did find that I could set the tags suggested in this article (AppProfile : Wordpress) at the MySQL server instance, under Overview, Essentials section on the top, there is the Tags option where we can add or update tags.  I did add the suggested tag and wondering how it will perform after that.

On this server I have other non-Wordpress databases and will check on how they'll perform also after this change.

Copper Contributor

@vsuarezd -- yah.  I got that applied but I've gotten the same recommendations a bunch of times since applying it, too.  (shrug)

Microsoft

Did this fix anybody's issue?  WordPress on Azure is so slow.  The initial connection to (I think MySQL) is crazy slow.  I tried many things and eventually just had to move off of Azure where performance is greatly approved.

 

Copper Contributor

@Jordan McDonald We're having the same problem. The time to first byte is way too long.

Microsoft

@schmidt975  I could never fix it.  I moved to FlyWheel.  Very fast and cheaper.

Copper Contributor

Same here - we were unable to get WordPress on Azure App Service to perform -- very slow, and very expensive. After a year's worth of trying we reluctantly moved from the App Service to setting up a VM with CyberPanel + LiteSpeed. Including CyberPanel's support, this is much cheaper and much faster.

Copper Contributor

I use AZURE because Microsoft generously offers grants to not-for-profit organizations. THANK YOU MICROSOFT.

 

But if not for that grant, I would never use it for WordPress, and several of my clients would rather pay hard cash for reasonable service, rather than get free service on Azure that just runs far too slowly.

 

I came to this article because of an email I received, but it seems that I already set this tag. I am glad I did, because I don't think I would have figured it out again.  I don't know why I received the email recommendation a second time.

Co-Authors
Version history
Last update:
‎Mar 29 2023 11:25 AM
Updated by: