Skip to content

Commit

Permalink
Static Content Deploy - Decrease time waste on sleep()
Browse files Browse the repository at this point in the history
Issue #1: Static content deploy waits 3 sec in single-job mode after finish
Fixed by moving this sleep() into if ($this->isCanBeParalleled()) { ... }

Issue magento#2: Static content deploy has 5 secs delay between checking if worker job finished processing.
It leads up to 5 sec time waste before next job will start.
Improved by decreasing time from 5 sec to 0.5 sec with saving log refresh rate (10*0.5 sec)

On 4 themes and 7 locales these fixes improve time of static content deploy by 10-15 secs
  • Loading branch information
andrey-legayev committed Oct 7, 2019
1 parent db0dce6 commit 88e7a87
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions app/code/Magento/Deploy/Process/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,32 @@ public function getPackages()
public function process()
{
$returnStatus = 0;
$logDelay = 10;
$this->start = $this->lastJobStarted = time();
$packages = $this->packages;
while (count($packages) && $this->checkTimeout()) {
foreach ($packages as $name => $packageJob) {
// Unsets each member of $packages array (passed by reference) as each is executed
$this->assertAndExecute($name, $packages, $packageJob);
}
$this->logger->info('.');
// phpcs:ignore Magento2.Functions.DiscouragedFunction
sleep(3);
foreach ($this->inProgress as $name => $package) {
if ($this->isDeployed($package)) {
unset($this->inProgress[$name]);

// refresh current status in console once in 10 iterations (once in 5 sec)
if ($logDelay >= 10) {
$this->logger->info('.');
$logDelay = 0;
} else {
$logDelay++;
}

if ($this->isCanBeParalleled()) {
// in parallel mode sleep before trying to check status and run new jobs
// phpcs:ignore Magento2.Functions.DiscouragedFunction
usleep(500000); // 0.5 sec (less sleep == less time waste)

foreach ($this->inProgress as $name => $package) {
if ($this->isDeployed($package)) {
unset($this->inProgress[$name]);
}
}
}
}
Expand Down Expand Up @@ -243,15 +256,25 @@ private function executePackage(Package $package, string $name, array &$packages
*/
private function awaitForAllProcesses()
{
$logDelay = 10;
while ($this->inProgress && $this->checkTimeout()) {
foreach ($this->inProgress as $name => $package) {
if ($this->isDeployed($package)) {
unset($this->inProgress[$name]);
}
}
$this->logger->info('.');

// refresh current status in console once in 10 iterations (once in 5 sec)
if ($logDelay >= 10) {
$this->logger->info('.');
$logDelay = 0;
} else {
$logDelay++;
}

// sleep before checking parallel jobs status
// phpcs:ignore Magento2.Functions.DiscouragedFunction
sleep(5);
usleep(500000); // 0.5 sec (less sleep == less time waste)
}
if ($this->isCanBeParalleled()) {
// close connections only if ran with forks
Expand Down

0 comments on commit 88e7a87

Please sign in to comment.