3

im running magento 2 (2.2.1) on nginx and enable the cronjob by default.

php bin/magento cron:install

i dont customize any configuration regarding schedule of cronjobs.

after running the machine a few days, i saw that mysql service is always nearly 30-40% usage and machine is running a lot of "php7.1" processes

i reboot the machine and the error is the same, right now there are only a "few" php7.1 processes but it continue to raise

http://prntscr.com/hxryjs

i already checked the logs, no errors there or exeptions.

i only found an issue on m2 backend

http://prntscr.com/hxrztv

this indexer is always not "up to date"

can you please give me a hint how i can fix this problem?

attached a screenshot from the crontab

http://prntscr.com/hxs0p3

  • thank you user5198077 - i solved this problem manual but is there a way to use this command also on schedule? maybe every hour or something like that? are there bugfixes available from m2 side? – Micha Jan 10 '18 at 15:13
  • I've edited the answer. To run every hour, edit * * * * * to 0 * * * * (or replace 0 with whatever minute you want). For permanent fix, have a look on the github issue below, it seems there is one pull-request that may fix it, but it is not done as of today: github.com/magento/magento2/pull/12497 – user5198077 Jan 14 '18 at 13:08
7

My best guess,

See this at stackexchange and this at github. The issue somehow appears as some cronjobs aren't indicated as completed. It freaked me out for quite some time.

The quick diagnosis to see if you have the issue is to run below query and if it comes back with more than a 1200-1500 or so, you likely have the issue:

select count(*) from cron_schedule;

The quick fix is to delete most of the stuff that have status running in cron_schedule:

delete from cron_schedule where scheduled_at < date_sub(now(), interval 1 hour);

To avoid recurrence, establish a cron-job that periodically deletes the stuck jobs. Below job can be added in cron-tab. However, if you have it on a shared server, the MySQL password and username will be visible by other users running top -c and similar and it is not advisable, read more on guidelines for password security.

* */8 * * * <path_to_mysql_binary_dir>/mysql -u<sql_user> -p'<sql_user_pass>' <database_name> -e "delete from cron_schedule where scheduled_at < date_sub(now(), interval 1 hour)";

Adjust the * * * * * to fit the frequency, I don't see the need to run it very often, as I still haven't faced the same issue again after months of doing the quick fix.

  • If you have magerun installed in production, then you could pipe the mysql query to magerun db:console to avoid having the MySQL credentials in your crontab. The magerun command will get the credentials out of your env.php. – Scott Buchanan Jan 25 '18 at 20:09
0

There's a module to fix this issue:

https://github.com/magemojo/m2-ce-cron

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.