Slow REDIS config cache in Magento 2 - source and possible solution.
The problem:
In one of our projects, MultiStore, I've found out an interesting thing regarding how Magento 2 works with REDIS cache for config storage.
Situation:
During the day, this is an average REDIS hGet load time on every single page (even in customer/section/load operation). This method is called 217 times (on average)
In the last few days, I've tried to resolve this after hours and I had to dig into the entire process of how the cache instances are created, managed, loaded, and saved by the platform.
What I've learned is the fact that Magento, during System configuration load, done by this class \Magento\Config\App\Config\Type\System Magento loads creates and loads all configuration scopes: default, websites, and store views. What is interesting is that the same cache is created on both IDs and Website / Store Codes.
It results in creating a lot of cache entries for System configuration:
In the end, it looks like this ( REDIS keys)
领英推荐
In our scenario, we have approximately 30 store views. As a result, Magento fetches 121 cache entries during its system initialization process. If we assume each request takes 1 ms, it results in the page taking an additional 121 ms to load.
Yet, this isn’t the full picture of what's retrieved from the REDIS cache. During a single-page rendering, Magento also attempts to load more cache entries. For this particular project, another 67 cache entries are loaded.
Ultimately, the system fetches around 200 cache entries from the REDIS config cache, which adds 200ms to the load time of every uncached page. Notably, some of these entries are loaded multiple times.
I've tried the following approach (DEV site)
However, it didn't solve the issue and I was only getting a difference between 15-20ms for a single page load - no great IMHO.
The best solution, so far, to reduce this load speed was simply to remove the REDIS config cache from env.php. At least for this project.
Possible solutions:
I've come up with a few ideas I'll try to experiment with in my free time (so probably never ;-)):
I wonder how others approach this issue, Share your ideas, and let's implement a solution that will benefit everyone :-)
Desenvolvedor Magento na VML Commerce
1 年Great article. It's a fair topic considering Magento loads these tons of cached data on each request. I would consider also splitting the project, websites in multiple Magento instances. It looks like the Magento redis performance decreases when increasing the websites and stores ??
e-Commerce Specialist / Magento Solution Architect / 3x Adobe Commerce Certified
1 年Well... your finds are very interesting, it opens a lot of possibilities for improvements and defintely reducing the amount of redundant cache entries will improve the performance, not too much but it's a gain in the end. Thank you for sharing the results of your investigation.