A
A
Anamar2021-06-19 16:35:06
Task Schedulers
Anamar, 2021-06-19 16:35:06

Why is the Laravel task scheduler heavy on CPU?

Hello!
Commands are executed using the Laravel task scheduler (App\Console\Kernel.php).

protected function schedule(Schedule $schedule)
{
    $schedule->command('Cron --method=clear')->runInBackground()->everyMinute(); 
    $schedule->command('Cron --method=getData')->runInBackground()->everyMinute(); 
    ...
}


The commands themselves are located in App\Console\Commands and run controller methods.
The problem is that when you run commands, the processor (4 cores * 3600 MHz) is heavily loaded up to 100% and the site stops working.
Please tell me how can I solve the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
JhaoDa, 2021-06-19
@JhaoDa

1. Laravel does not have any special scheduler, cron is used.
2. Every minute you run unknown doing tasks. Maybe you're counting a trillion digits of pi there.
3. There are no seers and soothsayers here.
PS Commands that launch controller methods are terrible.

V
Vyacheslav Plisko, 2021-06-21
@AmdY

See how hard this task is in itself without cron and what it does. Maybe there is some kind of resource lock, database, etc.
In itself, raising php, parsing and executing a script is a rather resource-intensive thing. If this needs to be done every minute, it might be worth writing a sleep daemon.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question