Search code examples
laravelqueuejobssupervisordworker

What is difference between Job, Queue, and Worker in Laravel?


I'm working on a Laravel project. I'm using job queue for doing some functions. I use supervisor for running job listening command. But I don't understand the concept well. Here are my questions.

  1. I have 8 workers. How do they involve in job queue system?
  2. If I increase count of them, the job processing speed will be faster?
  3. As long as I increase them, it will take more RAM too? If my server has 16GB ram, how many workers can I have?
  4. Does job go to queue? (Image below) Job Queue

Solution

    1. I have 8 workers. How do they involve in job queue system?

      Worker can be simply as a processor/user that can handle job at a time. 8 workers mean can handle 8 process/function at a time.

    2. If I increase count of them, the job processing speed will be faster?

      Maybe yes, but maybe no. Depend on your process and server resource like RAM/CPU/Disk speed. If your running workers consume high resource it could make the server freeze/slow, but if the resource consume for each worker is low it's could make faster queue.

    3. As long as I increase them, it will take more RAM too? If my server has 16GB ram, how much workers can I have?

      Yes, depend on how much free RAM and how much RAM consume each process. If free RAM 10gb, and the average process consume 100mb RAM, so the max workers should be 100. Maybe you still can increase it but it will affect other workers process. And also CPU and disk usage is also important factor too.

    4. Does job go to queque? (Image below)

      Sorry, I don't fully understand about your image. But if you have 8 workers, the queue should only 2.

    5. Could you please explain me the difference between job and queue? Job is a class that contain function/process usually created to App\Jobs folder. A job can be queued or dispatched/executed multiple time. Queue is a list of job that need to be executed when you have free worker. If you dispatch a job to queue, it will go to pending queue, if you have free worker, the job will be executed or go to running queue. After the job executed/finished, the job will be removed from the queue list.