Skip to content

Commit 9cb4b55

Browse files
oshmyheliukshiftedreality
authored andcommitted
MAGECLOUD-3382: Increase default SCD_THREADS to 3 (#447)
1 parent 6faaebd commit 9cb4b55

18 files changed

+194
-146
lines changed

dist/.magento.env.yaml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -559,15 +559,6 @@
559559
# variables: #
560560
# ENV_APPLICATION: "MAGENTO_CLOUD_APPLICATION" #
561561
#######################################################################################################################
562-
# ENV_MODE - Environment variable used to get application mode. #
563-
# Magento Version: Magento 2.1.4 and later #
564-
# Default value: - "MAGENTO_CLOUD_MODE" #
565-
# Section: variables #
566-
# Example: #
567-
# system: #
568-
# variables: #
569-
# ENV_MODE: "MAGENTO_CLOUD_MODE" #
570-
#######################################################################################################################
571562
# ENV_ENVIRONMENT - Environment variable used to get application environment. #
572563
# Magento Version: Magento 2.1.4 and later #
573564
# Default value: - "MAGENTO_CLOUD_ENVIRONMENT" #

src/App/Container.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Magento\MagentoCloud\Process\PostDeploy as PostDeployProcess;
2929
use Magento\MagentoCloud\Process\ProcessComposite;
3030
use Magento\MagentoCloud\Process\ProcessInterface;
31+
use Magento\MagentoCloud\Process\SetProductionMode;
3132

3233
/**
3334
* @inheritdoc
@@ -175,6 +176,7 @@ function () {
175176
return $this->container->makeWith(ProcessComposite::class, [
176177
'processes' => [
177178
$this->container->make(BuildProcess\PreBuild::class),
179+
$this->container->make(SetProductionMode::class),
178180
$this->container->make(\Magento\MagentoCloud\Process\ValidateConfiguration::class, [
179181
'validators' => [
180182
ValidatorInterface::LEVEL_CRITICAL => [
@@ -351,7 +353,7 @@ function () {
351353
$this->container->make(DeployProcess\PreDeploy\CleanRedisCache::class),
352354
$this->container->make(DeployProcess\PreDeploy\CleanFileCache::class),
353355
$this->container->make(DeployProcess\PreDeploy\RestoreWritableDirectories::class),
354-
$this->container->make(DeployProcess\PreDeploy\SetProductionMode::class),
356+
$this->container->make(SetProductionMode::class),
355357
],
356358
]);
357359
});

src/Config/Environment.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ class Environment
2626
*/
2727
const GIT_MASTER_BRANCH_RE = '/^(master|production|staging)(?:-[a-z0-9]+)?$/i';
2828

29-
/**
30-
* @deprecated Threads environment variables must be used.
31-
*/
32-
const CLOUD_MODE_ENTERPRISE = 'enterprise';
33-
3429
const VAL_ENABLED = 'enabled';
3530
const VAL_DISABLED = 'disabled';
3631

src/Config/Schema.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ public function getSchema()
129129
StageConfigInterface::STAGE_DEPLOY
130130
],
131131
self::SCHEMA_DEFAULT_VALUE => [
132-
StageConfigInterface::STAGE_BUILD => 1,
133-
StageConfigInterface::STAGE_DEPLOY => 1,
132+
StageConfigInterface::STAGE_BUILD => StageConfigInterface::VAR_SCD_THREADS_DEFAULT_VALUE,
133+
StageConfigInterface::STAGE_DEPLOY => StageConfigInterface::VAR_SCD_THREADS_DEFAULT_VALUE,
134134
],
135135
],
136136
StageConfigInterface::VAR_SCD_EXCLUDE_THEMES => [
@@ -217,15 +217,6 @@ public function getSchema()
217217
SystemConfigInterface::SYSTEM_VARIABLES => 'MAGENTO_CLOUD_APPLICATION',
218218
],
219219
],
220-
SystemConfigInterface::VAR_ENV_MODE => [
221-
self::SCHEMA_TYPE => ['string'],
222-
self::SCHEMA_SYSTEM => [
223-
SystemConfigInterface::SYSTEM_VARIABLES
224-
],
225-
self::SCHEMA_DEFAULT_VALUE => [
226-
SystemConfigInterface::SYSTEM_VARIABLES => 'MAGENTO_CLOUD_MODE',
227-
],
228-
],
229220
SystemConfigInterface::VAR_ENV_ENVIRONMENT => [
230221
self::SCHEMA_TYPE => ['string'],
231222
self::SCHEMA_SYSTEM => [

src/Config/Stage/Deploy/MergedConfig.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Magento\MagentoCloud\Config\Schema;
1111
use Magento\MagentoCloud\Config\Stage\DeployInterface;
1212
use Magento\MagentoCloud\Config\StageConfigInterface;
13-
use Magento\MagentoCloud\Config\SystemConfigInterface;
1413

1514
/**
1615
* Returns all merged configuration for deploy phase
@@ -74,7 +73,6 @@ public function get(): array
7473

7574
$this->mergedConfig = array_replace(
7675
$this->schema->getDefaults(StageConfigInterface::STAGE_DEPLOY),
77-
$this->getDeployConfiguration(),
7876
$envConfig[DeployInterface::STAGE_GLOBAL] ?? [],
7977
$envConfig[DeployInterface::STAGE_DEPLOY] ?? [],
8078
$this->environmentConfig->getAll()
@@ -90,26 +88,4 @@ public function get(): array
9088
);
9189
}
9290
}
93-
94-
/**
95-
* Resolves default configuration value for deploy stage.
96-
*
97-
* SCD_THREADS = 3 for production environment.
98-
*
99-
* @return array
100-
* @deprecated Threads count shouldn't depend on ENV_MODE variable as this variable doesn't set anymore.
101-
* Threads environment variables or .magento.env.yaml must be used instead.
102-
*/
103-
private function getDeployConfiguration(): array
104-
{
105-
$config = [];
106-
107-
$envVar = $this->environment->getEnvVarName(SystemConfigInterface::VAR_ENV_MODE);
108-
109-
if ($this->environment->getEnv($envVar) === Environment::CLOUD_MODE_ENTERPRISE) {
110-
$config[DeployInterface::VAR_SCD_THREADS] = 3;
111-
}
112-
113-
return $config;
114-
}
11591
}

src/Config/StageConfigInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ interface StageConfigInterface
6767
*/
6868
const OPTION_MERGE = '_merge';
6969

70+
/**
71+
* Default value of SCD_THREADS variable.
72+
*/
73+
const VAR_SCD_THREADS_DEFAULT_VALUE = -1;
74+
7075
/**
7176
* Retrieves environment configuration per stage.
7277
*

src/Config/SystemConfigInterface.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ interface SystemConfigInterface
2727
const VAR_ENV_ROUTES = 'ENV_ROUTES';
2828
const VAR_ENV_VARIABLES = 'ENV_VARIABLES';
2929
const VAR_ENV_APPLICATION = 'ENV_APPLICATION';
30-
const VAR_ENV_MODE = 'ENV_MODE';
3130
const VAR_ENV_ENVIRONMENT = 'ENV_ENVIRONMENT';
3231

3332
/**

src/Process/Deploy/PreDeploy/SetProductionMode.php renamed to src/Process/SetProductionMode.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
namespace Magento\MagentoCloud\Process\Deploy\PreDeploy;
6+
namespace Magento\MagentoCloud\Process;
77

88
use Magento\MagentoCloud\Filesystem\FileSystemException;
9-
use Magento\MagentoCloud\Process\ProcessException;
10-
use Magento\MagentoCloud\Process\ProcessInterface;
119
use Magento\MagentoCloud\Config\Deploy\Writer;
1210
use Psr\Log\LoggerInterface;
1311

src/StaticContent/ThreadCountOptimizer.php

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
*/
66
namespace Magento\MagentoCloud\StaticContent;
77

8+
use Magento\MagentoCloud\Config\StageConfigInterface;
89
use Magento\MagentoCloud\Package\MagentoVersion;
10+
use Magento\MagentoCloud\Util\Cpu;
911
use Psr\Log\LoggerInterface;
1012

1113
/**
@@ -19,11 +21,14 @@ class ThreadCountOptimizer
1921
const STRATEGY_COMPACT = 'compact';
2022

2123
/**
22-
* Recommended tread count value for compact strategy
23-
*
24-
* @var int
24+
* Recommended tread count value for compact strategy before 2.2.4 version.
2525
*/
26-
const THREAD_COUNT_COMPACT_STRATEGY = 1;
26+
const THREAD_COUNT_COMPACT_STRATEGY_BEFORE_2_2_4 = 1;
27+
28+
/**
29+
* Optimal value for job count if environment has enough cpu cores.
30+
*/
31+
const THREAD_COUNT_OPTIMAL = 4;
2732

2833
/**
2934
* @var LoggerInterface
@@ -35,14 +40,21 @@ class ThreadCountOptimizer
3540
*/
3641
private $magentoVersion;
3742

43+
/**
44+
* @var Cpu
45+
*/
46+
private $cpu;
47+
3848
/**
3949
* @param LoggerInterface $logger
4050
* @param MagentoVersion $magentoVersion
51+
* @param Cpu $cpu
4152
*/
42-
public function __construct(LoggerInterface $logger, MagentoVersion $magentoVersion)
53+
public function __construct(LoggerInterface $logger, MagentoVersion $magentoVersion, Cpu $cpu)
4354
{
4455
$this->logger = $logger;
4556
$this->magentoVersion = $magentoVersion;
57+
$this->cpu = $cpu;
4658
}
4759

4860
/**
@@ -59,13 +71,18 @@ public function optimize(int $threads, string $strategy): int
5971
* in the case of using a compact strategy of static content deployment
6072
*/
6173
if ($strategy === self::STRATEGY_COMPACT && $this->magentoVersion->satisfies('<2.2.4')) {
62-
if ($threads !== self::THREAD_COUNT_COMPACT_STRATEGY) {
74+
if ($threads !== self::THREAD_COUNT_COMPACT_STRATEGY_BEFORE_2_2_4) {
6375
$this->logger->notice(
6476
'Threads count was forced to 1 as compact strategy can\'t be run with more than one job'
6577
);
6678
}
6779

68-
return self::THREAD_COUNT_COMPACT_STRATEGY;
80+
return self::THREAD_COUNT_COMPACT_STRATEGY_BEFORE_2_2_4;
81+
}
82+
83+
if ($threads === StageConfigInterface::VAR_SCD_THREADS_DEFAULT_VALUE) {
84+
$threads = $this->magentoVersion->satisfies('>2.1.10') ?
85+
min($this->cpu->getThreadsCount(), self::THREAD_COUNT_OPTIMAL) : 1;
6986
}
7087

7188
return $threads;

src/Test/Integration/Cron21Test.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@
55
*/
66
namespace Magento\MagentoCloud\Test\Integration;
77

8-
use Magento\MagentoCloud\Command\Build;
9-
use Magento\MagentoCloud\Command\Deploy;
10-
use Magento\MagentoCloud\Application;
11-
use Magento\MagentoCloud\DB\ConnectionInterface;
12-
use Magento\MagentoCloud\Filesystem\Driver\File;
13-
use Symfony\Component\Console\Tester\CommandTester;
14-
158
/**
169
* {@inheritdoc}
1710
*

0 commit comments

Comments
 (0)