Skip to content

Commit 6d52aa6

Browse files
Yaroslav Onischenkoxmav
authored andcommitted
MAGETWO-66343: [Performance] Anomaly increase in redis traffic
1 parent e767697 commit 6d52aa6

File tree

5 files changed

+50
-19
lines changed

5 files changed

+50
-19
lines changed

app/code/Magento/Config/App/Config/Type/System.php

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class System implements ConfigTypeInterface
2424
private $source;
2525

2626
/**
27-
* @var DataObject[]
27+
* @var DataObject
2828
*/
2929
private $data;
3030

@@ -129,6 +129,10 @@ public function get($path = '')
129129

130130
/**
131131
* Check whether configuration is cached
132+
*
133+
* In case configuration cache exists method 'load' returns
134+
* value equal to $this->cacheExistenceKey
135+
*
132136
* @return bool
133137
*/
134138
private function isCacheExists()
@@ -139,6 +143,9 @@ private function isCacheExists()
139143
/**
140144
* Explode path by '/'(forward slash) separator
141145
*
146+
* In case $path string contains forward slash symbol(/) the $path is exploded and parts array is returned
147+
* In other case empty array is returned
148+
*
142149
* @param string $path
143150
* @return array
144151
*/
@@ -154,6 +161,11 @@ private function getPathParts($path)
154161
/**
155162
* Check whether requested configuration data is read to memory
156163
*
164+
* Because of configuration is cached partially each part can be loaded separately
165+
* Method performs check if corresponding system configuration part is already loaded to memory
166+
* and value can be retrieved directly without cache look up
167+
*
168+
*
157169
* @param string $path
158170
* @return bool
159171
*/
@@ -166,6 +178,9 @@ private function isConfigRead($path)
166178
/**
167179
* Load configuration from all the sources
168180
*
181+
* System configuration is loaded in 3 steps performing consecutive calls to
182+
* Pre Processor, Fallback Processor, Post Processor accordingly
183+
*
169184
* @return array
170185
*/
171186
private function loadConfig()
@@ -206,6 +221,10 @@ private function cacheConfig($data)
206221
/**
207222
* Read cached configuration
208223
*
224+
* Read section of system configuration corresponding to requested $path from cache
225+
* Configuration stored to internal property right after load to prevent additional
226+
* requests to cache storage
227+
*
209228
* @param string $path
210229
* @return mixed
211230
*/
@@ -219,12 +238,11 @@ private function readFromCache($path)
219238
$pathParts = $this->getPathParts($path);
220239
if (!empty($pathParts)) {
221240
$result = $this->cache->load(self::CONFIG_TYPE . '_' . $pathParts[0] . $pathParts[1]);
222-
}
223-
224-
if ($result !== false && $result !== null) {
225-
$readData = $this->data->getData();
226-
$readData[$pathParts[0]][$pathParts[1]] = $this->serializer->unserialize($result);
227-
$this->data = new DataObject($readData);
241+
if ($result !== false) {
242+
$readData = $this->data->getData();
243+
$readData[$pathParts[0]][$pathParts[1]] = $this->serializer->unserialize($result);
244+
$this->data->setData($readData);
245+
}
228246
}
229247

230248
return $this->data->getData($path);
@@ -233,6 +251,10 @@ private function readFromCache($path)
233251
/**
234252
* Clean cache and global variables cache
235253
*
254+
* Next items cleared:
255+
* - Internal property intended to store already loaded configuration data
256+
* - All records in cache storage tagged with CACHE_TAG
257+
*
236258
* @return void
237259
*/
238260
public function clean()

app/code/Magento/Config/Test/Unit/App/Config/Type/SystemTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@ public function setUp()
6969
$this->preProcessor = $this->getMockBuilder(PreProcessorInterface::class)
7070
->getMockForAbstractClass();
7171
$this->serializer = $this->getMockBuilder(SerializerInterface::class)
72-
->disableOriginalConstructor()
73-
->setMethods(['serialize', 'unserialize'])
7472
->getMock();
73+
7574
$this->configType = new System(
7675
$this->source,
7776
$this->postProcessor,

dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
$tpExtensionAttributesFactory = $objectManager->get(ProductTierPriceExtensionFactory::class);
2222

2323
$adminWebsite = $objectManager->get(\Magento\Store\Api\WebsiteRepositoryInterface::class)->get('admin');
24-
$tierPriceWebsiteId = $tpExtensionAttributesFactory->create()->setWebsiteId($adminWebsite->getId());
24+
$tierPriceExtensionAttributes1 = $tpExtensionAttributesFactory->create()
25+
->setWebsiteId($adminWebsite->getId());
26+
2527
$tierPrices[] = $tierPriceFactory->create(
2628
[
2729
'data' => [
@@ -30,7 +32,8 @@
3032
'value' => 8
3133
]
3234
]
33-
)->setExtensionAttributes($tierPriceWebsiteId);
35+
)->setExtensionAttributes($tierPriceExtensionAttributes1);
36+
3437
$tierPrices[] = $tierPriceFactory->create(
3538
[
3639
'data' => [
@@ -39,7 +42,8 @@
3942
'value' => 5
4043
]
4144
]
42-
)->setExtensionAttributes($tierPriceWebsiteId);
45+
)->setExtensionAttributes($tierPriceExtensionAttributes1);
46+
4347
$tierPrices[] = $tierPriceFactory->create(
4448
[
4549
'data' => [
@@ -48,11 +52,11 @@
4852
'value' => 5
4953
]
5054
]
51-
)->setExtensionAttributes($tierPriceWebsiteId);
55+
)->setExtensionAttributes($tierPriceExtensionAttributes1);
5256

53-
$tierPricePercentageValue = $tpExtensionAttributesFactory->create()
54-
->setPercentageValue(50)
55-
->setWebsiteId($adminWebsite->getId());
57+
$tierPriceExtensionAttributes2 = $tpExtensionAttributesFactory->create()
58+
->setWebsiteId($adminWebsite->getId())
59+
->setPercentageValue(50);
5660

5761
$tierPrices[] = $tierPriceFactory->create(
5862
[
@@ -61,7 +65,7 @@
6165
'qty' => 10
6266
]
6367
]
64-
)->setExtensionAttributes($tierPricePercentageValue);
68+
)->setExtensionAttributes($tierPriceExtensionAttributes2);
6569

6670
/** @var $product \Magento\Catalog\Model\Product */
6771
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);

dev/tests/integration/testsuite/Magento/Store/_files/second_website_with_second_currency.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
0
2929
);
3030

31+
/**
32+
* Configuration cache clean is required to reload currency setting
33+
*/
3134
/** @var Magento\Config\App\Config\Type\System $config */
3235
$config = $objectManager->get(\Magento\Config\App\Config\Type\System::class);
3336
$config->clean();

lib/internal/Magento/Framework/App/Config/ConfigTypeInterface.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313
interface ConfigTypeInterface
1414
{
1515
/**
16-
* Retrieve configuration raw data array.
16+
* Retrieve configuration data.
17+
*
18+
* Returns full configuration array in case $path is empty.
19+
* In case $path is not empty return value can be either array or scalar
1720
*
1821
* @param string $path
19-
* @return mixed
22+
* @return array|int|string|boolean
2023
*/
2124
public function get($path = '');
2225

0 commit comments

Comments
 (0)