Fokwa Best
Fokwa Best

Reputation: 3515

Laravel Queue:work is consuming all my RAM

I am experiencing an issue with Laravel 5.4 and I am hoping that someone can help. I have a laravel 5.4 project where I send emails using queue and execute various commands like below:

1. Kernel.php

protected function schedule(Schedule $schedule)
{
    // $schedule->command('inspire')
    //          ->hourly();

    $schedule->command('queue:work')->everyMinute();

    // Execute command at midnight daily to reject expired applications
    $schedule->command('application:reject')->daily();
}
  1. In /etc/crontab, I have got the following:

* * * * * bob cd /opt/lampp/htdocs/oap/ && /usr/local/bin/php artisan schedule:run >> /dev/null 2>&1 * * * * * bob cd /opt/lampp/htdocs/ims/ && /usr/local/bin/php artisan schedule:run >> /dev/null 2>&1

When I view my linux system monitor, I notice that every minute, a new php process is started and takes 13.8MB of memory. In about an hour I begin to see my free memory very low. The processes are /opt/lampp/bin/php-7.1.4 artisan queue:work and /usr/local/bin/php artisan schedule:run

When the above happens, I would run artisan queue:restart and all the php processes would be killed.

What can be the cause of this?

This is weird to me because I have this same code in Laravel 5.1 and I am not experiencing this. What can I do to solve this?

Upvotes: 2

Views: 5102

Answers (2)

num8er
num8er

Reputation: 19372

Your problem is that You're scheduling some command in code.

Some kind of scheduling inside the code that being scheduled every minute. (:

In 5.1 it was working because of there were 2 commands: queue:listen that was living long and queue:work that was working until queue is empty.

Seems like laravel team going to remove queue:listen

So here is solution:

1) Just remove Your code from Kernel.php and schedule it as normal artisan call:

# daily
0 0 * * * bob cd /opt/lampp/htdocs/ims/ && /usr/local/bin/php artisan application:reject >> /dev/null 2>&1

2) Run manually or supervise queue:work with supervisor:

cd /opt/lampp/htdocs/oap/ && nohup php artisan queue:work &

Upvotes: 0

Sandeesh
Sandeesh

Reputation: 11916

The queue worker is a daemon which will keep polling. Stop running queue workers using cron. They're long-lived processes and you run workers based on your requirements from your server, not spawning a new worker every minute.

https://laravel.com/docs/5.4/queues#running-the-queue-worker

Read the documentation. If you're not too familiar then just install Supervisor and let it handle all the work.

Upvotes: 1

Related Questions