Open hostep opened 1 week ago
Hi @hostep. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce.
@magento I am working on this
Join Magento Community Engineering Slack and ask your questions in #github channel. :warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting. :clock10: You can find the schedule on the Magento Community Calendar page. :telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.
Performed some statistics calculations across the projects we maintain ourselves.
These are the number of lock files found across the production versions of these shops, per Magento version. All our shops on Magento 2.4.7 got the temporary workaround to delete lock files if they haven't been touched in 10 days. Without this workaround the numbers would exceed 1 million.
Average:
- Magento 2.3.7 => 373
- Magento 2.4.5 => 129
- Magento 2.4.6 => 14144
- Magento 2.4.7 => 87441 (without temporary cleanup workaround it would be ~1.856.666)
Median:
- Magento 2.3.7 => 75
- Magento 2.4.5 => 129
- Magento 2.4.6 => 1642
- Magento 2.4.7 => 87450 (without temporary cleanup workaround it would be ~1.900.000)
So we can indeed see a slight increase of number of lock files used since Magento 2.4.6 which can be explained in a lock file per order being needed now. And a huge increase since Magento 2.4.7, since generating cache for Blocks need a lock file per Block now, instead of using the database for those locks.
Suggestion for the simple solution, to cleanup old lock files using a cronjob: https://github.com/magento/magento2/pull/39372
This is probably only a partial fix for this issue, it's a cleanup afterwards, maybe we can also already beforehand try to prevent writing too many files somehow...
Hi @engcom-Hotel. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
Area: XXXXX
label to the ticket, indicating the functional areas it may be related to.2.4-develop
branch2.4-develop
branch, please, add the label Reproduced on 2.4.x
.Issue: Confirmed
once verification is complete. Hello @hostep,
Thanks for the report and collaboration!
The issue has been reproducible for us. Hence confirming this issue.
Thanks
:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-13367 is successfully created for this GitHub issue.
:white_check_mark: Confirmed by @engcom-Hotel. Thank you for verifying the issue.
Issue Available: @engcom-Hotel, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.
Preconditions and environment
Steps to reproduce
var/locks
directoryIdeally you should look at a shop running for many months and where file based locking has been enabled, and inspect the directory that contains those lock files.
Expected result
var/locks
directory should not overflow with an ever increasing amount of filesActual result
var/locks
can contain up to millions of files after several months of running a Magento shopExample filenames:
We had one project that had 3.5 million files in that directory, up to a point where the filesystem started complaining with errors like
Failed to open stream: No space left on device
every time a lock file was needed (there was plenty of disk space, it's just that a directory can't handle that large amount of files in one directory). Another project had 1.9 million files and another had ~170.000 files.So that's really bad. We need some kind of bugfix or cleanup mechanism to keep this under control.
Additional information
The locking mechanism in Magento is used for various things:
Most of these things result in lock names that are predictable and remain the same over time:
However, some of these are pretty dynamic and those names can change over time:
getCacheKeyInfo
is called and that gets hashed and that hash is being used for the lock name, sometimes with a suffix for thefinal_price
blocks that contain ID's and dates and currencies and so onMore observations:
/var/www/html/release123/
, the next one in/var/www/html/release124/
, and it turns out that one of the parameters to generate a lock name contains the absolute path to template files, so for each deploy that path changes and the lock name changes as well, so we get an ever growing, never stopping, number of lock files after each deployPossible solutions:
For the last observeration, instead of using absolute paths, we could choose to use relative paths, which should result in more stable lock names, I already came up with this solution, but I have no idea if there will be regressions caused by this, because this data is not used solely for generating lock names:
$this->getTemplateFile(),
$this->getRelativeTemplateFile(), 'template' => $this->getTemplate() ]; } diff --git a/lib/internal/Magento/Framework/View/Element/Template.php b/lib/internal/Magento/Framework/View/Element/Template.php index e68d059c079..116452b4d8c 100644 --- a/lib/internal/Magento/Framework/View/Element/Template.php +++ b/lib/internal/Magento/Framework/View/Element/Template.php @@ -328,12 +328,17 @@ class Template extends AbstractBlock return [ 'BLOCK_TPL', $this->_storeManager->getStore()->getCode(),
$this->getTemplateFile(),
$this->getRelativeTemplateFile(), 'base_url' => $this->getBaseUrl(), 'template' => $this->getTemplate() ]; }
protected function getRelativeTemplateFile(): string
{
return $this->getRootDirectory()->getRelativePath($this->getTemplateFile());
}
/**
Maybe for the block generating locks through
LockGuardedCacheLoader
, we can mark those as temporary (if file storage is used) and to be removed immediately after they have been unlocked. No idea if this is a good idea and won't lead to race conditions or other problemsMaybe a new configuration setting in
env.php
should be added to determine what lock storage we should use for theLockGuardedCacheLoader
, Adobe specifially disabled the database one in 2.4.7, for Galera clusters as they have issues with this for some reason, but if this would be configurable and we could choose ourselves what locking mechanism should be used for theLockGuardedCacheLoader
, then we can already prevent a big deal of lock files being written to the filesystemAnd then the obvious one: write a cronjob that runs every hour or so that looks at the lock files (if file storage is used) and finds the ones that are not locked and haven't been touched in 24 hours or so and remove those
These are just some random ideas, in case other people have other suggestions, feel free to let me know in the comments below.
Temporary solution: Setup something like this in the
crontab
on your server:Thanks!
Release note
No response
Triage and priority