Slide 1

Slide 1 text

From Bottlenecks to Breakthroughs: How the New York Post Mastered Scalability Presented by Linnea Huxford

Slide 2

Slide 2 text

Agenda The New York Post’s WordPress Journey An Overview of Scaling Strategies Deep Dive into Bottlenecks & Solutions

Slide 3

Slide 3 text

Setting the Stage: The New York Post’s WordPress Journey

Slide 4

Slide 4 text

A long history of building and publishing with WordPress Number of years on WordPress 11 Years Database rows for the WP_Posts table 15 Million

Slide 5

Slide 5 text

Timeline 2013 Launched The NY Post on WordPress 2015 Redesigned NY Post & Page Six 2020 Migrated sites from VIP Classic to VIP Go 2021 A/B tests and rollout of the 2021 NY Post redesign 2023 Launched the redesign of Page Six as a child theme

Slide 6

Slide 6 text

Massive content volume Post tags 28,000 Articles 1,299,949 Database Size 244 GB

Slide 7

Slide 7 text

Mega pageviews and sudden traffic surges from Breaking News

Slide 8

Slide 8 text

Overview of Scaling Strategies

Slide 9

Slide 9 text

We run a WordPress Multisite on WordPress VIP with a “monolith” architecture ● Gutenberg block editor with custom blocks ● WP VIPʼs mu-plugins have many performance tweaks to support enterprise usage ● Persistent object cache - memcached ● Reliable Cron System with Automatticʼs Cron Control plugin ● CDN for images to deliver them quickly from servers close to the userʼs location ● Robust Page Cache to serve up pre-built HTML to the majority of users.

Slide 10

Slide 10 text

We’ve succeeded at very effective use of the Persistent Object Cache, achieving 98% hit rate!

Slide 11

Slide 11 text

A typical page request has very few database queries because most data is already in the object cache.

Slide 12

Slide 12 text

Key Principle: No database writes from frontend traffic ● API integrations often hook in on admin actions. For example, when posts are saved or updated, using the wp_after_insert_post hook. ● Scheduled cron jobs update data from external sources. ● To optimize performance, API data is stored in the object cache, minimizing the need for repeated external requests ● Rewrite rules are updated via a CLI command ● Analytics, comments, and membership functionalities are powered by external third parties, leveraging JavaScript HTTP calls and scripts instead of backend calls to WordPress.

Slide 13

Slide 13 text

We use the following Elasticsearch Plugins for better query performance SearchPress Indexes content in Elasticsearch ES WP Query Offloads query to Elasticsearch https://github.com/alleyinteractive/searchpress https://github.com/alleyinteractive/es-wp-query ES_WP_Query

Slide 14

Slide 14 text

Simply add ‘es’ => true and the query will use Elasticsearch to get the Post IDs Elasticsearch DSL Elasticsearch Cluster Post ID Post ID Post ID Post ID … Complex Query: Metro Snowstorm Posts with Video

Slide 15

Slide 15 text

ES WP Query will then shoehorn the Post IDs from Elasticsearch into a highly efficient post__in query to retrieve the full WP_Post objects from the database. es-wp-query/class-es-wp-query-shoehorn.php Post ID Post ID Post ID Post ID …

Slide 16

Slide 16 text

We built Remote Backstop as a safety net https://github.com/alleyinteractive/remote-backstop Object Cache Object Cache Object Cache Object Cache Object Cache Remote Services Remote Backstop

Slide 17

Slide 17 text

Remote backstop has several key benefits 1. Site Stability: The plugin prevents site downtime when external resources are unavailable. 2. Stress Reduction: Remote Backstop alleviates the load on a stressed resource by serving cached responses. 3. User Experience: End users are unaffected, unaware of any issues, due to the seamless fallback mechanism.

Slide 18

Slide 18 text

Deep Dive into Bottlenecks & Solutions

Slide 19

Slide 19 text

We use New Relic to monitor server performance

Slide 20

Slide 20 text

The WP New Relic Transactions plugin adds WordPress context to New Relic https://github.com/alleyinteractive/wp-new-relic-transactions

Slide 21

Slide 21 text

Identifying high-impact endpoints: A New Relic analysis

Slide 22

Slide 22 text

Bottlenecks & Quick Solutions

Slide 23

Slide 23 text

Bottleneck 1 50% of this request was checking for AMP

Slide 24

Slide 24 text

Bandaid Applied

Slide 25

Slide 25 text

Solution We used the PHP Static Keyword

Slide 26

Slide 26 text

Bottleneck 2 Simultaneous cache expiry The homepage is very long and each module’s query is cached. If all of the caches expire at the same time, the page becomes slow to build.

Slide 27

Slide 27 text

Solution Implementing staggered cache durations Random cache duration leads to more evenly distributed cache expiration, preventing server overload.

Slide 28

Slide 28 text

Bottleneck 3 Recursive function calls inside loops Solution Removing recursion

Slide 29

Slide 29 text

Bottleneck 4 Time to build 404 pages

Slide 30

Slide 30 text

Solution Cache the HTML for the 404 page https://github.com/alleyinteractive/wp-404-caching

Slide 31

Slide 31 text

Bottleneck 5 Slow database queries

Slide 32

Slide 32 text

Solutions to slow queries ● Solution 1 Avoid posts__not_in ○ Get more posts than needed and exclude posts in PHP. ● Solution 2 Disable Getting All Found Rows ○ If Pagination isnʼt necessary, set 'no_found_rows' => true ● Solution 3 Optimize Query Parameters ○ 'ignore_sticky_posts' => true ○ 'suppress_filters' => false ● Solution 4 Offload to Elasticsearch and Cache Results ● Solution 5 Avoid Unnecessary Queries ○ Whenever possible, avoid running the query entirely. Sometimes, plugins add unnecessary functionality that can be disabled to improve performance.

Slide 33

Slide 33 text

Set performant query arguments as defaults

Slide 34

Slide 34 text

Query Performance Comparison

Slide 35

Slide 35 text

Add a Date Query ● Getting 100 Recent Posts without a date query: 171 ms ● Limiting the query to the last 3 months: 46 ms

Slide 36

Slide 36 text

Conclusion WordPress, coupled with WordPress VIP hosting, offers a robust foundation for building enterprise solutions that scale effectively. Weʼve relied on several key principles to achieve this scalability: ● Leveraging Elasticsearch to enhance WP Query performance and offload complex queries. ● Utilizing Object Cache to efficiently store data from queries and external APIs, reducing load times. ● Adhering to the principle of ‘No Frontend Database Writes,ʼ ensuring data integrity and performance. ● Identifying bottlenecks using tools like New Relic and Query Monitor to pinpoint and resolve performance issues. ● Applying common solutions such as query optimizations and caching strategies to further boost efficiency.

Slide 37

Slide 37 text

“Great things are not done by impulse, but by a series of small things brought together.ˮ — Vincent Van Gogh

Slide 38

Slide 38 text

Thank You! We’re hiring software developers! https://alley.com/careers/