1

I have three websites in the single Magento 2.4.2 application. When I load any one of the website it will load all the websites configurations data in the configuration cache. I'm looking for a way to load specific scope data instead of loading all.

Reproduce steps:

  1. Create three websites and each has one store and one store view. enter image description here
  2. Configure Redis for page cache, default cache and session.
  3. Flush Magento cache.
  4. Load website_two URL frontend and check the redis.

Expecting result:

Redis stored only website_two scope data.

Actual result:

Redis stored all the websites and store configurations. enter image description here

For Redis GUI, I'm using this tool.

$ redis-commander --redis-host=172.18.0.6
Using scan instead of keys
No Save: false
listening on 0.0.0.0:8081
access with browser at http://127.0.0.1:8081

When the sites count increases, that time PHP took more memory to create the configuration cache on the first time load. Approximately 600 sites utilize 2-3GB of PHP memory to create a configuration cache for each website's first-time load.

Example

website.one -> utilize 2-3GB PHP memory
website.one/* -> Utilize 200MB, because configuration cache generated above.
website.two -> utilize 2-3GB PHP memory
website.two/* -> Utilize 200MB, because configuration cache generated above.

If 20+ uncached website URLs are loading concurrently, it will down the server.

I have seen the below comments in core code vendor/magento/module-config/App/Config/Type/System.php but not sure about what is the cleaner approach.

/**
 * Get configuration value by path
 *
 * System configuration is separated by scopes (default, websites, stores). Configuration of a scope is inherited
 * from its parent scope (store inherits website).
 *
 * Because there can be many scopes on single instance of application, the configuration data can be pretty large,
 * so it does not make sense to load all of it on every application request. That is why we cache configuration
 * data by scope and only load configuration scope when a value from that scope is requested.
 *
 * Possible path values:
 * '' - will return whole system configuration (default scope + all other scopes)
 * 'default' - will return all default scope configuration values
 * '{scopeType}' - will return data from all scopes of a specified {scopeType} (websites, stores)
 * '{scopeType}/{scopeCode}' - will return data for all values of the scope specified by {scopeCode} and scope type
 * '{scopeType}/{scopeCode}/some/config/variable' - will return value of the config variable in the specified scope
 *
 * @inheritdoc
 * @since 100.1.2
 */
public function get($path = '')
{
    if ($path === '') {
        $this->data = array_replace_recursive($this->loadAllData(), $this->data);

        return $this->data;
    }

    return $this->getWithParts($path);
}

Thanks in advance.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.