magento2: Cron using too many resources.
Preconditions (*)
- Magento CE 2.3.4
- PHP 7.2
Steps to reproduce (*)
- Upgrade existing store from 2.2.9 to 2.3.4
Expected result (*)
- Site and server continue to function as prior to upgrading
Actual result (*)
- Huge increase in CPU and RAM usage.
You can clearly see the increased load on our system graphs here. It has forced the server to start using swap. Graphs showing 12 hours before and after the M2.2.9 -> 2.3.4 upgrade. The upgrade was done at Tue 4 @ 18:00.

Same graphs but for 3 days before and 4 days after the M2.2.9 -> 2.3.4 upgrade.

I did some benchmarking on the memory and duration of the cron before and after the upgrade:
- 2.2.9 Completed in 2.44 seconds using 330MB RAM
- 2.3.4 Completed in 6.15 seconds using 714MB RAM
That is over double the time and memory used to do the same thing.
Measured with while [ true ] ; do echo $(date +%s.%3N ; free | tail -n2 ) ; sleep .1 ;done | tee cron.csv and plotted in libre office calc.
2.2.9:

2.3.4:

I see similar issues here but the solutions do not make much difference:
https://github.com/magento/magento2/issues/25634 https://github.com/magento/magento2/issues/26507
I did truncate the cron table Wed morning… you can see on the graphs the swap usage is lowered slightly but creeps back up over the next few days, so although that may well also be an issue, I think the increase in mem usage is something different.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 16 (9 by maintainers)
We have been seeing stuck processes, but maybe its an effect of running out of ram resources on the VPS. Although I have made two changes that have so far seemed to improve things:
1, Truncated the cron log as it was getting very large 2, We were seeing errors in the system log relating to aqmp not being configured. We don’t use RabbitMQ so I just added the code below to env.php:
The stuck processes could be an effect of a few things happening at once, so it might require a longer period to see if things really have improved…
Hi @bobemoe. Thank you for your report. The issue has been fixed in magento/magento2#28007 by @driskell in 2.4-develop branch Related commit(s):
The fix will be available with the upcoming 2.4.3 release.
Try to install each group separetely with locks This way you only run cron groups you want Processes are not overlaped and stay locked
https://github.com/magento/magento2/issues/25987#issuecomment-576034263 e.g. add in crontab smth like this
We’ve also disabled the
cron_consumers_runner/cron_run = falsebut also addedqueue/consumers_wait_for_messages = 0(both in env.php). This makes the processes stop when the’re not receiving any messages. We’re now running each individual process as a separate cron process. The enables you to control how often the process spawns (Magento will just spawn it on each cron run). For example theproduct_action_attribute.updateis started every minute, butqueue:consumers:start exportProcessoronly runs once an hour (we don’t really use the export functionality, but did’t want to completely disable it).Word of caution: This can delay certain processes. As an example
product_action_attribute.updateis responsible for processing mass attribute updates. If you only run this process once every hour, every mass update can take up to an hour before it’s actually processed.Reading material: https://github.com/magento/community-features/issues/180 https://github.com/magento/magento2/issues/17951
Just a heads up (not sure if that’s the issue, but it might have been overlooked); Since Magento 2.3.3 the cron spawns several consumer processes (about 5). Each of these processes uses resources (~200Mb in RAM, not sure on the cpu but it’s more than nothing). In our case it will also occasionally leave
queue:consumers:start async.operations.allprocesses running while starting new ones (resulting in 4-5 duplicate processes).So all in all it could easily consume an additional ~1GB in memory compared to earlier versions.