When Magento is running on multiple web-nodes, media files need be shared between them. One way to do it is to mount the directory /pub/media as a network filesystem, such as NFS or EFS. In such scenario file system operations become way more costly. It was discovered that the DB upgrade unnecessarily traverses files in the media directory causing it to hang up for a long time.
/pub/media is mounted as NFS/EFS filesystemphp bin/magento setup:upgrade
\Magento\Framework\Setup\FilePermissions::getMissingWritablePathsForInstallation()The issue is caused by the code in the Setup sub-application that cannot be targeted by any customization mechanisms, including DI and plugins. That makes it impossible to develop a workaround w/o patching the Magento codebase.
@sshymko thank you for report. Magento is working on internal ticket MAGETWO-65186 reported by @samm-git, also based on the live installation.
Ticket MAGETWO-65186 was closed and delivered to the mainline https://github.com/magento/magento2/commit/76a33bd762489d731b4030067df448b71fa33218.
We decided to decrease max depth for recursive permission check to 2 level as the solution.
Thanks @andimov, your change reduced the deploy time from one of our webshops (which uses a loadbalancer with NFS sharing) from 24 minutes to 10 minutes. Where the bin/magento setup:upgrade step previously took around 300 seconds per server, and now only takes 14 seconds per server. Pretty significant change!
@hostep
setup:upgradestep previously took around 300 seconds per server
Database is shared between web-servers, so the DB upgrade must be done once, not per server.
@sshymko: we rely on setup:upgrade to also modify the app/etc/config.php file, because we currently don't version that file in Magento 2.1.x. That's why we run it on multiple nodes.
But your comment is correct though, if setup:upgrade would only manipulate the database we should only run it on a single server.
@hostep
Storing the deployment configuration app/etc/env.php and app/etc/config.php under the version control has worked for us very well.
Yes, I know it's recommended to store config.php in version control, we will probably start doing this in Magento 2.2.x. But you should never put env.php in version control, it contains sensitive data (like the database password), and you should never put sensitive data in version control :)