Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache API.getSegmentMetadata better in Segment #18333

Merged
merged 7 commits into from Nov 22, 2021
Merged

Conversation

peterhashair
Copy link
Contributor

@peterhashair peterhashair commented Nov 16, 2021

Description:

fixes: #17944
add cache and lock to segment load, using lazy cache

Review

Peter Zhang added 2 commits November 17, 2021 12:31
add cache and lock to segment load
convert some variables
@peterhashair peterhashair changed the title add cache and lock to segment load Cache API.getSegmentMetadata better in Segment Nov 16, 2021
core/Segment.php Outdated Show resolved Hide resolved
core/Segment.php Outdated Show resolved Hide resolved
@peterhashair
Copy link
Contributor Author

peterhashair commented Nov 17, 2021

@tsteur just testing, I saw on the goal page, the same problem we have last time appears, happens here as well. each graphic called the API.getSegmentsMetadata. only happened when we have lots of goals. Not sure that can be fixed, because the cache won't carry to another request.

update segement to just cache
@peterhashair peterhashair added this to the 4.7.0 milestone Nov 17, 2021
@peterhashair peterhashair added the Needs Review PRs that need a code review label Nov 17, 2021
remove use import
@peterhashair peterhashair added not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. and removed Needs Review PRs that need a code review labels Nov 17, 2021
@tsteur
Copy link
Member

tsteur commented Nov 17, 2021

Using lazy cache would be ideal for performance but be quite a bit of work to invalidate all the caches in the right moments which makes it very hard and a long job. I guess the idea with transient cache is that it may be an easy fix and we already make it maybe say 50% better compared to making it 90% better but a lot of work. Be good to double check if with a few segments this method is called quite often during one request.

@peterhashair peterhashair self-assigned this Nov 17, 2021
@peterhashair peterhashair added the Needs Review PRs that need a code review label Nov 17, 2021
update segement cache ID
Copy link
Member

@sgiehl sgiehl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a comment for a small improvement. Otherwise this should be good to merge.
Checked the changes on a dashboard with a couple of widgets. Without the changes here API.getSegmentsMetadata was called over 2000 times when loading the page. With the changes it was only twice 👍

core/Segment.php Outdated Show resolved Hide resolved
@sgiehl sgiehl removed the Needs Review PRs that need a code review label Nov 22, 2021
Co-authored-by: Stefan Giehl <stefan@matomo.org>
@sgiehl sgiehl merged commit 60a9383 into 4.x-dev Nov 22, 2021
@sgiehl sgiehl deleted the m-17944-cache-sgement branch November 22, 2021 18:05
$cache = PiwikCache::getTransientCache();

//covert cache id
$cacheId = 'API.getSegmentsMetadata.'.SettingsPiwik::getPiwikInstanceId() . '.' . implode(",", $this->idSites);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just fyi, no change needed. For regular caches we don't need the instance ID in there. That was for the get_lock mysql method only.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tsteur ah, this is already merged, should I update this in another PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peterhashair no changed needed (mention this in the comment above). It's just for future when we work with caches again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cache API.getSegmentMetadata better in Segment - Improve performance on every UI request
3 participants