statamic / seo-pro

An all-in-one site reporting, metadata wrangling, Open Graph managing, Twitter card making, sitemap generating, turn-key addon for Statamic.
https://statamic.com/addons/statamic/seo-pro
52 stars 33 forks source link

Report generation performance improvements #310

Closed jesseleite closed 6 months ago

jesseleite commented 6 months ago

This PR massively improves report generation performance overall (up to 10x faster compared to current version 5.3.0, and up to 4x faster compared to master branch right now). It also adds the ability to chunk generation into smaller jobs for super large sites with thousands of entries.

For example, report generation on 5.3.0 (current version) for even 1000 pages is 60+ seconds with a request timeout...

CleanShot 2023-12-23 at 02 03 25

But with this PR, 1000 pages takes me ~7 seconds, which is about 10x faster 🏎️...

CleanShot 2023-12-23 at 02 06 10

But where this PR really shines is when generating reports for massive sites with thousands of entries, which you can't even do on 5.3.0 (as shown above in our 1000 page example).

On master (untagged), we can at least generate a report for 5000 pages, but it takes me about ~52 seconds...

CleanShot 2023-12-23 at 00 53 27 2

With this PR though, the same 5000 pages takes about ~29 seconds, which is nearly 2x faster 🏎️

CleanShot 2023-12-23 at 01 12 38

And if I enable async queue driver w/ 5 workers (chunked in jobs of 1000 pages each), the report generation endpoint takes about ~13 seconds, which is about 4x faster compared to master, and not even possible on 5.3.0 🏎️

Configuration

I have made the chunk size configurable in config/statamic/seo-pro.php under reports.queue_chunk_size, so that users can balance chunk size vs. worker count how they like.

Note on CPU

Of course your mileage will vary. It's pretty CPU intensive when generating a report for this many entries. The above numbers are just locally on my M1 Macbook.