2

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?

  • 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 '18 at 17:01
  • Did you get any solution? – Mano M Nov 21 at 7:34
  • @manoM I did, but now 2 years ago. So i don't know the exact sollution anymore – Jilco Tigchelaar Nov 22 at 13:37
2

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.

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.

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.