Election Day in the U.S. and the holiday season are just around the corner, which can mean a surge in online activity.
With increased customers visiting your sites, ensuring your application is well-prepared to handle the increased traffic and provide a seamless experience is essential.
WordPress VIP has timely, expert advice to help your teams prepare for the rush. Below, you’ll find our Professional Services team’s top recommendations—from identifying performance bottlenecks to optimizing object caching—to set your sites up for success.
Identify performance bottlenecks
The first step in preparing an application for the heightened demands of the peak Election and e-commerce season is identifying performance bottlenecks. Performance analysis tools such as New Relic and Query Monitor can pinpoint those bottlenecks.
New Relic slow transaction traces offer a great starting point for identifying which parts of a transaction are responsible for latency. Sorting by “Most Dissatisfying” is an effective way of surfacing the slowest pain points overall.
Query Monitor helps pinpoint what’s happening on a page, surfacing specific query-related details and highlighting slow database queries that warrant further attention. For the most reliable results, make sure to leverage Query Monitor when logged out, as code pathways used when logged in can surface false positives or false negatives.
Leverage full-page caching
Full-page caching is the primary scaling mechanism for sites on the VIP Platform. It protects a site’s origin server from increased load (where a high cache hit rate exists) by retaining valuable backend resources to handle sudden changes in traffic.
For e-commerce, some sites require cookies on some pages, but many do not, and setting cookies that mistakenly bust the cache on all pages is a common observation of e-commerce sites. To better position your application for scale:
- Avoid setting user cookies that bust the cache across all pages
- Limit the use of query parameters and non-GET requests that bypass the cache
- Increase the cache lifetime (max-age) for less frequently updated & requested URLs
Fix slow database queries
Slow database queries are often a quick path to poor application performance. Our Slow Query Logs page in the VIP Dashboard can help identify issues bogging down application performance, setting you on a course to debug connections to your database. The following are practical and quickly adopted methods to improve slow database queries:
- Offload non-performant queries with Enterprise Search (ES). Not all queries should be offloaded to Enterprise Search, but those that demonstrate evidence of performance issues are often better served via ES. For guidance, check our documentation.
- Add extra object caching to queries, particularly around custom queries.
- Reduce the use of JOINs, CALC_FOUND_ROWS, and limit the results returned. Review our documentation to modify WP_Query requests for better performance.
- Build queries with indexes in mind, such as the difference between post_date vs. post_date_gmt. View information about the core WordPress database schema on WordPress.org and WPVIP’s custom post meta index in our documentation.
In our documentation, we have more information on optimizing database queries.
Avoid database writes
Applications hosted on the VIP Platform leverage multiple databases for optimum performance, with writes sent to an environment’s primary database and reads sent to database replicas.
Frontend requests resulting in database writes can cause subsequent queries to read only from the primary database, negatively affecting site performance and stability under load.
- Use Query Monitor to identify if queries are writing to the database.
- Wherever possible, avoid direct database queries in code. Instead, WordPress API functions are used to fetch and manipulate data.
- If direct database queries are required, follow these best practices.
- When required, frontend database queries should always be related to a user-requested interaction—not automated (such as a “hit counter”). Processing AJAX or REST API requests through Javascript can also increase the full-page cache hit ratio.
Optimize object caching
Each WordPress environment is provisioned with Memcached, allowing one to cache repetitive or expensive computations in memory to improve performance. Optimizing the use of object caching can be an effective way to improve application performance via methods such as those below:
- Assess object cache statistics with Query Monitor, including request time, volume of GETs, and the total size of all objects stored in memory
- Leverage wp_cache_get_multiple() to group high volumes of Memcached GET requests and minimize the overhead when retrieving data from the object cache via high volumes of lookups/sets.
- Upgrade to WordPress 6.2 or greater to take advantage of multi-get functionality built into WordPress core.
- Keep individual cache objects under 1 MB in size (compressed), or they may fail to be stored–this is particularly important for the alloptions option, as mentioned in our documentation. Keeping object size down also reduces the amount of data being sent back and forth over the network and makes the request much faster. For example, instead of caching the entire result of a WP_Query request, which could mean many full WP_Post objects, consider caching the Post IDs and performing a much faster database query via IDs.
- Try to cache many small requests together in a larger request. For example, generating a page that will gather data from the post object, then collect thumbnail data from post meta, and then term/term metadata for additional context can quickly multiply the number of cache requests to build a page. Instead, cache the generated HTML output to perform this process in one single cache request rather than dozens or hundreds.
- Use helpers like the Cache Nav Menus plugin, which provides a drop-in replacement for WordPress core’s wp_nav_menu() and adds additional caching to reduce database and Memcached usage when generating complicated navigation menus.
Questions or thoughts about any of these recommendations? Our Support Team is here to help.
Armor up for your website’s biggest day
To ensure your application is prepared for the demands of heightened traffic, we encourage you to explore our VIP High-Traffic Event Planning Service.
Led by WordPress experts, our team will help you prepare your applications to withstand the heightened demands associated with sudden influxes of traffic and the unique behaviors that surface during critical moments. The service includes planning, load testing, deep application-level analysis, and recommendations for improvement where applicable.
If you want to learn more, please contact your Relationship Manager or VIP Support.