LoginSignup
10
13

More than 5 years have passed since last update.

Laravel5のQueuesのlistenとwork --daemonを比較する

Posted at

Laravel5のQueuesはメッセージキューを抽象化したフロントエンドで、バックエンドにRedis, Amazon SQS, IronMQなどが使える。
簡単な非同期ジョブをする分には便利そう。

使うときにはキューにpushするアプリ側と、非同期で処理するワーカー側を構成することになるが、ワーカーを走らせるときに大きく2種類あるようなことがドキュメントに書いてある。
http://laravel.com/docs/5.0/queues#running-the-queue-listener

基本がqueue:listenの方で

Laravel includes an Artisan task that will run new jobs as they are pushed onto the queue. You may run this task using the queue:listen command:

php artisan queue:listen

もう1つがqueue:work --daemon。

The queue:work also includes a --daemon option for forcing the queue worker to continue processing jobs without ever re-booting the framework. This results in a significant reduction of CPU usage when compared to the queue:listen command, but at the added complexity of needing to drain the queues of currently executing jobs during your deployments.

php artisan queue:work --daemon

「work --daemonの方がCPU使わないよ。でもデプロイ中に実行中のジョブをdrain(キューから取り出す?)するのがめんでぃーよ。」
と説明されているので試してみた。

環境

MBPでVagrant
CPU 1コア、メモリ2GB

検証

queue:listenの場合

queue:listenはジョブが追加されるとワーカープロセスを立ち上げて処理する。
スクリーンショット 2015-06-25 12.58.03.png

ワーカーは以下にオプションを付けて実行されている。

php artisan queue:work

queue:work --daemonの場合

スクリーンショット 2015-06-25 13.03.50.png
デーモンで立ち上げたワーカーがジョブを処理し続ける。

まとめ

queue:listenはその都度ワーカープロセスを立ち上げる分CPU喰う
queue:work --daemonは1プロセスだからCPU喰わないというおなじみのパターン。

並列に動かせるのか、などドキュメントに記載が見当たらないのでまた試そう。

10
13
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
13