6

I updated to 2.2.1 from 2.1.10 and that looked good. But my CPU is increasing a lot and it went to over 100% in a few days.

The problem is the cron jobs because also the table cron_schedule was very full with 249.000 rows.

Any idea what causes the problem in the cronjobs?

3
  • I've seen bigger cron_schedule table, but you have a point, it should be dealt with. Can use this query to get the most frequent crons : SELECT count(*), job_code FROM cron_schedule group by job_code order by count(*) DESC
    – medmek
    Dec 21, 2018 at 17:01
  • Did you get any solution?
    – Mahi M
    Nov 21, 2019 at 7:34
  • @manoM I did, but now 2 years ago. So i don't know the exact sollution anymore Nov 22, 2019 at 13:37

2 Answers 2

6

Maybe our questions are related

edit/update: clearing your cron_schedule table should temporarily fix your problem:

TRUNCATE cron_schedule;

to permanently fix your problem you have to find out why your cron_schedule table is growing. In my case, it is the missing mail server!

if you don't care about indexing and sending emails, you could also disable your crontab entries.

0
1

In my case, turns out the slow query was an update join on the cron_schedule table.

Found a related site on this. Solution - You can clear it with a daily script to delete completed records. https://www.optiweb.com/magento-2-cron-issues/

There should be a configuration for each cron groupfor the history cleanup and lifetimes.

<history_cleanup_every>10</history_cleanup_every>
<history_success_lifetime>60</history_success_lifetime> 
<history_failure_lifetime>600</history_failure_lifetime>

However, this only cleans up cron entries with the status »success« or »missed« and does not clean old entries with the status »pending«.

Simple Script: to delete cron_schedule records created a day ago copied from optiweb.com link above.

<?php
use Magento\Framework\App\Bootstrap;

$rootDirectory = *Magento root directory*;
require $rootDirectory . '/app/bootstrap.php';

$params = $_SERVER;
$bootstrap = Bootstrap::create(BP, $params);
$objectManager = $bootstrap->getObjectManager();
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();
$tableName = $resource->getTableName('cron_schedule');


$sql = "DELETE FROM " . $tableName . " WHERE created_at < DATE_SUB(NOW(), INTERVAL 1 DAY)";

try{
    $result = $connection->query($sql);
}catch(Exception $ex){
    print_r($ex);
}

Seems to do the trick, although I'm not sure about the interval may bump it to 7 days.

2
  • also useful when you want to clear it one time, here's the full SQL statement: DELETE FROM `cron_schedule` WHERE `created_at` < DATE_SUB(NOW(), INTERVAL 1 DAY) Aug 16, 2020 at 17:01
  • Also in a long running Magento 2 site, I found that running optimize table on everything seemed to reduce disk usage by a lot. (A site with mirsvit elastic search module with large full text index files on disk in /var/mysql/magento dir.) Aug 18, 2020 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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