IBX-5502: Added additional tag cleaning to limit down number of orphaned tag en… #477
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Rebase of ezsystems/ezplatform-kernel#372
v4.6
Due to how the cache is implemented in Symfony-based projects using the Redis adapter (and probably - not only Redis), entries (Members) inside a Tag (Set) are removed only when the tag is purged. Due to that, we can encounter on multiple occasions a situation, when a Tag is purged, resulting in cache items (Keys) being purged as well, but only the Tag that triggered a purge is cleaned up. All other tags that contain entries pointing to cache items that no longer exist will remain there until the affected tag is purged - which often is "never".
This results in orphaned entries in tags (or even in whole orphaned tags) filling up the memory. Memory allocated to tags in Redis is nonevictable, therefore it is freed only when purged on purpose (
maxmemory-policy
setting won't affect orphaned members/sets). On very big and/or constantly changing content structures, this unevictable memory allocated to orphaned tags and entries can significantly lower the amount of memory available for standard cache items to be stored.Additional Tag purging added in this PR reduces this effect, but - unfortunately - it is not possible to resolve it fully with current Symfony's cache adapters implementation, due to the fact that there is no available interface to remove an entry from a Tag, without purging it whole - and that would result in purging cache items that were nor related to the original action performed on content.
Additional tag purging introduced by PR:
ContentHandler::updateContent
:Multiple content-related entries (
ibx-c-<contentId>-<versionNo>-0
,ibx-c-<contentId>-<versionNo>-<languageCode>
,ibx-cvi-<contentId>
,ibx-cl-<contentId>-pfd
are orphaned in tags:l-<locationId>
,lp-<locationId>
,c-<contentId>-v-<versionNo>
,c-<contentId>-v-<prevVersionNo>
. Added purging of those tags to avoid it.TrashHandler::trashSubtree
:Multiple content-related entries are orphaned (
ibx-c-<contentId>-v<versionNumber>
,ibx-cl-<contentId>
,ibx-cvi-<contentId>
,ibx-l-<locationId>-<languageCode>
,ibx-c-<contentId>-<versionNo>-0
,ibx-c-<contentId>-<versionNo>-<languageCode>
,ibx-cvi-<contentId>
... (many more) are orphaned in tags:l-<locationId>
,c-<contentId>-v-<versionNo>
.Handling those two occurrences helps to limit greatly the number of orphaned members.
My tests show, that one of the biggest culprits here is
lp-<locationIdOfParent>
tag, which can have multiple orphaned entries - therefore it might be a good idea to purge it as well, to avoid blocked memory in cost of potentially small performance loss - up for discussion.This PR won't resolve the issue fully but limits the scope of it using available tools. To resolve this fully, we will need (in my opinion):
But those two are out of this PR scope.
Checklist:
$ composer fix-cs
).@ezsystems/engineering-team
).