Automattic / Automattic/jetpack

Improve performance of do_server_site_stats

Open
#12,122 1 comment 0 reactions 0 assignees View on GitHub
[Focus] Performance Enhancement General
Dominant language
PHP
Stars
1.8k
Forks
898
Avg merge
1d 18h
Merged PRs (30d)
774

Description

`do_server_site_stats` will run multiple remote requests when multiple stats items are stored in the `$this->stats` var. https://github.com/Automattic/jetpack/blob/master/class.jetpack.php#L4316-L4348

A couple of ideas:

- [ ] - Defer all `do_server_site_stats` to run on shutdown instead of during the execution tree to improve perceived performance.
- [ ] - Speed up the overall process. Modify the endpoint endpoint to accept multiple stats at once or set the http timeout to 1, etc (while the function returns true/false if the call works, we don't actually use it) so we send the stats request but don't wait at all for a response.

Contributor guide

Open the contributing guide

Research direction

Start in class.jetpack.php around lines 4316-4348 and trace how do_server_site_stats handles multiple items in $this->stats. Compare deferring requests until shutdown with batching or a shorter timeout, then verify that multiple stats no longer cause the observed request delay while the stats still get sent.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend-api-design, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.