Skip to content

Cronjobs increasing CPU usage and slow queries #26507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Zyles opened this issue Jan 23, 2020 · 21 comments
Closed

Cronjobs increasing CPU usage and slow queries #26507

Zyles opened this issue Jan 23, 2020 · 21 comments
Labels
Component: Cron Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. Progress: done Reported on 2.3.3 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. Triage: Performance

Comments

@Zyles
Copy link

Zyles commented Jan 23, 2020

Cronjobs stuck in pending state. CPU usage increasing. Mysql slow queries increasing.

image

Time is 13:28.

Logs filled with:

use magento;
SET timestamp=1579781526;
SELECT GET_LOCK('|CRON_GROUP_default', '5');
# Time: 200123 13:13:06
# User@Host: magento[magento] @ localhost []
# Thread_id: 20330  Schema: magento  QC_hit: No
# Query_time: 2.951003  Lock_time: 0.000000  Rows_sent: 1  Rows_examined: 0
# Rows_affected: 0
SET timestamp=1579781586;

Load goes down after disabling cronjob in crontab:

image

Preconditions (*)

Magento 2.3.3 & 2.4-develop
PHP-FPM 7.2.24

Steps to reproduce (*)

  1. Install Magento
  2. Setup cron jobs
  3. Run store for a week
  4. Break store

Expected result (*)

Normal working store.

Actual result (*)

  1. Increased CPU usage
  2. Increased cronjobs count
  3. Increased slow queries
  4. Slow store
@m2-assistant
Copy link

m2-assistant bot commented Jan 23, 2020

Hi @Zyles. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

@Zyles do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • yes
  • no

@gwharton
Copy link
Contributor

Do ypu have any jobs stuck "running"

@devchris79
Copy link

We see some cron jobs stuck in the running status:
cron

That's with a Magento 2.3.3 installation.

@gwharton
Copy link
Contributor

If you manually delete the rows that are stuck running, the pending jobs should be cleaned back to normal levels over the next few cron runs.

@gwharton
Copy link
Contributor

But you need to look at why they do not complete. It would be better if magento had some timeout to terminate stuck running jobs.

@devchris79
Copy link

I have deleted them out before, but they returned (as I suppose you would expect). I will try again and try to understand the sticking.

I agree with the timeout to terminate stuck routines, that would be great. I also don't understand why we have routines stuck in the "running" state with no execution time stamp, surely that should be the first thing done....

@Zyles
Copy link
Author

Zyles commented Jan 23, 2020

Didn't check "running". Truncated table as it took up too much server resources.

Clearly a bug.

One should not routinely have to empty the table manually.

@engcom-Hotel engcom-Hotel self-assigned this Jan 27, 2020
@m2-assistant
Copy link

m2-assistant bot commented Jan 27, 2020

Hi @engcom-Hotel. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Add label Issue: Confirmed once verification is complete.

  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@engcom-Hotel engcom-Hotel added Component: Cron Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch labels Jan 27, 2020
@ghost ghost unassigned engcom-Hotel Jan 27, 2020
@magento-engcom-team magento-engcom-team added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Jan 27, 2020
@magento-engcom-team
Copy link
Contributor

✅ Confirmed by @engcom-Hotel
Thank you for verifying the issue. Based on the provided information internal tickets MC-30804 were created

Issue Available: @engcom-Hotel, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@devchris79
Copy link

I have tweaked my cron job setup slightly and so far there hasn't been any sticking in the running state. I am wondering if its possible that two or more instances of the same cron job are being run at the same time and if that's causing lockup.

@anil90
Copy link

anil90 commented Feb 9, 2020

hi @devchris79 we are also facing same issue with Magento 2.3.2 Could you please let us know your changes. Thank you

@devchris79
Copy link

Hi @anil90 we are still seeing the issues. I think the timing is a red herring.

@devchris79
Copy link

The issue #26809 contains a post that highlights the extra ram usage in the cron processes from Magento 2.3.3.

Our site currently has no jobs stuck in the running state for over a day, and I have only made two changes:

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:

,
'cron_consumers_runner' => [
        'cron_run' => false,
        'max_messages' => 1000,
        'consumers' => [
            'async.operations.all'
        ]
    ] 

@roni-sooryen
Copy link

@devchris79 Please keep me up to date with the status of your cron job processes. You can use the https://github.com/kiwicommerce/magento2-cron-scheduler to kill your cron job after the cron job runs for 3 hours.

@devchris79
Copy link

@roni-sooryen Happy to report that we still have nothing stuck :-)

@roni-sooryen
Copy link

Seems like this is the same issue here #22438

@Zyles
Copy link
Author

Zyles commented Feb 27, 2020

I've had more success using separate intervals on cronjob, so they do not lock into each other. This is on a medium store.

On a large store the problem should be even more severe since the cronjobs run for longer.

Example:

* * * * * /usr/bin/php /home/http/magento/bin/magento cron:run 2>&1 | grep -v "Ran jobs by schedule" >> /home/http/magento/var/log/magento.cron.log
10 * * * * /usr/bin/php /home/http/magento/update/cron.php >> /home/http/magento/var/log/update.cron.log
15 * * * * /usr/bin/php /home/http/magento/bin/magento setup:cron:run >> /home/http/magento/var/log/setup.cron.log

Also turning off separate processes for each cronjob in backend:

image

This is by no means a fix, rather a workaround and works for us right now.

@magento-engcom-team magento-engcom-team added Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. Progress: ready for dev Progress: dev in progress and removed Priority: P3 May be fixed according to the position in the backlog. Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: PR in progress Progress: ready for dev Progress: dev in progress labels Nov 19, 2020
@Adel-Magebinary
Copy link

Still happens in 2.4.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Cron Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. Progress: done Reported on 2.3.3 Indicates original Magento version for the Issue report. Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. Triage: Performance
Projects
Archived in project
Development

No branches or pull requests