This article provides a fix for poor performance due to indexers being set on Update on Save mode, and how it is a best practice to set indexers to Update on Schedule mode to optimize performance in Magento.
Affected products and versions
- Magento Commerce, versions 2.2.x and 2.3.x
- Magento Commerce Cloud, versions 2.2.x and 2.3.x
Issue
Magento has two types of indexer modes: Update on Save (default setting) and Update on Schedule.
In Update on Save mode, indexed data is updated as soon as a change is made in the Admin. An example of this is the category products index is re-indexed after products are added to a category in the Admin.
In Update on Schedule mode, the index is set to Update on Schedule according to a Cron job.
Cause
Having a large store with multiple admins working in the backend or having many imports/exports can cause the indexes to be triggered constantly. The Update on Save mode degrades MySQL performance, and for large stores, the process can take hours to complete.
To avoid this issue, set the indexers to Update on Schedule.
Solution
- To view the current indexer configuration, run the following commands from CLI:
bin/magento indexer:show-mode [indexer]
Where[indexer]
is a space-separated list of indexers.bin/magento indexer:show-mode [indexer]
Omit[indexer]
to show the mode of all indexers. - To specify the indexer mode, run following command from CLI:
bin/magento indexer:set-mode {realtime|schedule} [indexer]
Where:
realtime
: Sets the selected indexers to Update on Save.schedule
: Sets the specified indexers to save according to the Cron schedule. Use this setting to set Update on Schedule.indexer
: Is a space-separated list of indexers. Omit[indexer]
to configure all indexers the same way.