Now Hiring: Are you a driven and motivated PHP (Laravel) Developer?

img

How we found slow API requests on a WordPress site

and got more than x40 speed boost after making fixes

Background

We are developing an educational platform that allows you to:

Сreate lesson presentations with slides with different types of content

Share them with other teachers

Clone and edit content to adapt to different age groups

Show these presentations to students and receive feedback from them in the form of answers to questions

How we found and fix slow API requests on a WordPress site

All actions with content involve large amounts of data and active communication with the database.

Sometime after the test launch of the project, we found that the loading, saving, and cloning of lessons began to take too much time. This prompted us to study the problem in detail and search for solutions based on the identified bottlenecks.

Platform technical stack

Code

We used WordPress as the engine and the famous LearnDash plugin to implement the Learning Management System (LMS) functionality. This combination allowed the client to develop the necessary functionality and launch a demo to test the perception by end users in a short period of time. In the process of changing the requirements, we had to abandon most of the features that LearnDash provides and restructure the approach to creating content – replacing courses with lessons and lessons with slides.

How we found and fix slow API requests on a WordPress site
How we found and fix slow API requests on a WordPress site

We chose Vue.js as the front-end framework, which allowed us to make the UI of the main functionality of the project responsive. That is to say, the functionality of the editor and the presentation of lessons. The peculiarity of the implementation lay in the construction of communication between the client and the server in the form of API requests. The requests are sent in large numbers due to the approach to managing posts in the selected CMS (WordPress), so reducing the number of requests was not possible. However, parallelization and asynchronous execution made it possible to achieve the desired results in performance.

Server

The scalable architecture based on AWS allowed us to make sure that the server capacity was sufficient to process a large flow of users and guarantee decent performance at peak loads. However, this time the situation turned out to be so unpredictable that horizontal and vertical scaling did not give any better results.

How we found and fix slow API requests on a WordPress site

Finding the problem and fixing it

Problems

The initial description of the problem explained that the developed front-end lesson editor as well as the pages for editing records in the administrative panel were taking too long to load. The first thing that came to mind was that the admin panel was written in React and used API requests to fetch categories, taxonomies and tags. Our lesson editor also used API requests to read and write lesson content.

After exploring the “network” tab in the browser dev tools, we found that all asynchronous requests to the server worked as expected, with the exception of API requests that took at least 3 seconds each. A detailed view of the request showed a high TTFB (time to first byte), indicating slowness on the backend or server-side.

It was empirically calculated that no matter what actions the API endpoint performed, the result would always be the same – at least 3 seconds for processing, increasing to 5-6 seconds with the growth of the database.

Of particular note, production turned out to be the slowest phase because it had the largest amount of data – posts and metadata for the posts. In order to verify that the load speed decreased as the amount of data increased, the production base was deployed in a test environment where we received confirmation of this theory.

How we found and fix slow API requests on a WordPress site
Image background

We constantly asked ourselves the same question:

Why is the speed of an API request that does not use the database when processing internal logic being affected by the size of the database?

Solutions

So, it was decided to turn off the plugins used one by one in order to find out their impact on the load speed. The first result came after the deactivation of the LearnDash plugin, the content of which is the basis of the entire platform. The processing speed of API requests was instantly 40 times faster! However, based on the impossibility of abandoning the plugin and resorting to the search for analogs, the investigation continued.

Going through the LearnDash plugin code, starting with initialization and including files, we commented on large blocks of code and checked their impact on the speed. Particular attention was paid to the REST API functionality, where the first hook appeared. By fully commenting out the use of the REST API by the plugin, the issue was resolved. However, this was also not a viable solution. Moving along the chain, we did find the reason for this behavior.

The LearnDash plugin was using the rest_api_init WordPress hook not only to register its own API endpoints and fields to them but also to include additional controllers with logic, one of which contained a huge unoptimized sequential selection from several tables in the database. Thus, regardless of the route API function, this selection was performed every time we sent an API request to the server (and, as mentioned above, a lot of requests are sent). The reason for this approach was not clear, however, a request for clarification was sent to the LearnDash plugin developers with the hope of a fix in future releases in mind.

The presence of a filter in the plugin code (provided by the LearnDash support team in response to our ticket) helped to fix the situation without problems and allow the exclusion of controllers loaded with logic before they were loaded. This is what we did for the problematic controller.

Results:

First of all, the problem with the slow operation of API requests was resolved. Now they load even faster than before on the minimum data set. The overall increase in load speed on the current amount of data is 40 times!

Thanks to getting rid of the “heavy” fetch with each API request, we managed to reduce the overall load on the database server, which is a nice bonus and justified the time spent looking for the bottleneck.

Based on information provided by CitrusDev WordPress Team Lead, the LearnDash support team responded to our ticket and a plugin update was provided. These improvements were integrated into the basic plugin source code. As a result, users around the world of the LearnDash plugin and WordPress REST API obtained a great speedup on their websites. That is why it is so critical to update WordPress and all plugins in a timely manner.

How we found and fix slow API requests on a WordPress site
Image background

Response from

LearnDash dev team

We have updated this and plan to release the changes in the next major release.

Thanks for your feedback – the dev team has taken those into consideration and also added their own improvements.

Image background

If you want our developers to analyze and
research your WordPress website
issues,
please feel free to contact us anytime.

Contact us
Jaibaida BMS: A Comprehensive guide to integration with iOS Apps
05.11.2024

Jaibaida BMS: A Comprehensive guide to integration with iOS Apps

Understanding Jaibaida Battery Management Sysytems Jiabaida BMS (JBD BMS) are intelligent devices designed to monitor and manage lithium-ion batteries, particularly Lithium Iron Phosphate (LiFePO4) batteries. These systems ensure optimal battery performance, safety, and longevity.    How JBD BMS Works A JBD BMS typically monitors and controls several key parameters:    Cell Voltage: Ensures individual cells remain within […]
Understanding Jaibaida Battery Management Sysytems Jiabaida BMS (JBD BMS) are intelligent devices designed to monitor and manage lithium-ion batteries, particularly Lithium Iron Phosphate (LiFePO4) batteries. These systems ensure optimal battery performance, safety, and longevity.    How JBD BMS Works A JBD BMS typically monitors and controls several key parameters:    Cell Voltage: Ensures individual cells remain within […]
Dokan Multivendor vs WCFM Marketplace: A Comprehensive Comparison
05.09.2024

Dokan Multivendor vs WCFM Marketplace: A Comprehensive Comparison

As the eCommerce industry grows, creating multivendor marketplaces has become a popular way for businesses to expand their offerings. WooCommerce, being one of the most customizable platforms, offers multiple plugins that allow users to set up multivendor marketplaces. Two of the leading contenders are Dokan Multivendor and WCFM Marketplace. In this article, we’ll explore the […]
As the eCommerce industry grows, creating multivendor marketplaces has become a popular way for businesses to expand their offerings. WooCommerce, being one of the most customizable platforms, offers multiple plugins that allow users to set up multivendor marketplaces. Two of the leading contenders are Dokan Multivendor and WCFM Marketplace. In this article, we’ll explore the […]
How to choose a reliable partner for the development of IoT project
12.08.2024

How to choose a reliable partner for the development of IoT project

The Internet of Things (IoT) is revolutionizing industries by connecting devices and enabling smarter decision-making. Whether you’re looking to innovate your business processes or create new revenue streams, an IoT project can be a game-changer. However, the success of your IoT initiative hinges on choosing the right development partner. With the complexity and nuances involved […]
The Internet of Things (IoT) is revolutionizing industries by connecting devices and enabling smarter decision-making. Whether you’re looking to innovate your business processes or create new revenue streams, an IoT project can be a game-changer. However, the success of your IoT initiative hinges on choosing the right development partner. With the complexity and nuances involved […]
Types of IoT Devices: Transforming the Connected World
08.07.2024

Types of IoT Devices: Transforming the Connected World

The Internet of Things (IoT) is transforming our world by linking everyday objects to the internet, enabling them to send, receive, and process data. This interconnected network of devices spans various industries, enhancing efficiency, convenience, and productivity. Here’s an exploration of the different types of IoT devices and their significant roles in modern life.   […]
The Internet of Things (IoT) is transforming our world by linking everyday objects to the internet, enabling them to send, receive, and process data. This interconnected network of devices spans various industries, enhancing efficiency, convenience, and productivity. Here’s an exploration of the different types of IoT devices and their significant roles in modern life.   […]
5 Ways to Achieve Cost Efficiency with IoT
04.07.2024

5 Ways to Achieve Cost Efficiency with IoT

The Internet of Things (IoT) is transforming industries by offering innovative solutions that enhance operational efficiency and reduce costs. Businesses leveraging IoT can achieve significant savings and streamline their processes. Here are five ways to achieve cost efficiency with IoT:   1. Predictive Maintenance One of the most impactful applications of IoT is in predictive […]
The Internet of Things (IoT) is transforming industries by offering innovative solutions that enhance operational efficiency and reduce costs. Businesses leveraging IoT can achieve significant savings and streamline their processes. Here are five ways to achieve cost efficiency with IoT:   1. Predictive Maintenance One of the most impactful applications of IoT is in predictive […]
Using IoT for Remote Patient Monitoring: Revolutionizing Healthcare
01.07.2024

Using IoT for Remote Patient Monitoring: Revolutionizing Healthcare

The advent of the Internet of Things (IoT) has been a game-changer in numerous industries, and healthcare is no exception. Remote patient monitoring (RPM) using IoT has emerged as a pivotal development, transforming how medical care is delivered and experienced. This innovative approach offers significant benefits, from enhancing patient outcomes to optimizing healthcare resources.   […]
The advent of the Internet of Things (IoT) has been a game-changer in numerous industries, and healthcare is no exception. Remote patient monitoring (RPM) using IoT has emerged as a pivotal development, transforming how medical care is delivered and experienced. This innovative approach offers significant benefits, from enhancing patient outcomes to optimizing healthcare resources.   […]
Image background

Drop a message to our team to see how we can help

We just need a couple of hours!

No more than 2 working days since receiving your request.