Horizon: Question: What's the difference between horizon, horizon:work & horizon:supervisor

Created on 13 Sep 2017  Â·  2Comments  Â·  Source: laravel/horizon

Hello I have a question about the difference between horizon, horizon:work & horizon:supervisor?
Because they seem to be the same, just that horizon:work and horizon:supervisor accepts parameters like --timeout or --queue .... . Also the official documentation doesn't explains it, which is very odd.

Most helpful comment

@neorganic

  • horizon is the master process, controlling everything
    (from below: php(1613), …)
  • for each queue worker setting in your config horizon.environments.(prod or dev).* you get a single supervisor process
    (from below: php7.1(1771), php7.1(1772), …)
  • each supervisor process will run n worker processes are per your configuration.
    (from below: php7.1(1915), php7.1(1914), …)

So in a nutshell, you've a "process tree" looking like this:

init(1)-+-acpid(1230)
        |-supervisord(1398)-+-php(1613)-+-php7.1(1771)-+-php7.1(1915)
        |                   |           |              `-php7.1(18509)
        |                   |           |-php7.1(1772)-+-php7.1(1914)
        |                   |           |              `-php7.1(1918)
        |                   |           |-php7.1(1773)---php7.1(1912)
        |                   |           |-php7.1(1774)---php7.1(1930)
        |                   |           |-php7.1(1775)-+-php7.1(1913)
        |                   |           |              `-php7.1(1917)
        |                   |           |-php7.1(1776)-+-php7.1(1916)
        |                   |           |              `-php7.1(1920)
        |                   |           |-php7.1(1777)---php7.1(1921)
        |                   |           |-php7.1(1778)-+-php7.1(1923)
        |                   |           |              |-php7.1(1924)
        |                   |           |              |-php7.1(1926)
        |                   |           |              `-php7.1(1927)
        |                   |           `-php7.1(1779)---php7.1(1928)

Note that in this (real life) example there's also supervisord on top which handles re-starting horizon should it terminate (i.e. for deployments).

just that horizon:work and horizon:supervisor accepts parameters like --timeout or --queue

This is because a supervisor is started with these values from the configuration and spawns children on its own and "passes" on these values; that's why you will see many arguments repeated:

php artisan horizon:supervisor hostname-Ec9z:someWorker redis --delay=0 --memory=128 --queue=someQueue --sleep=3…
…
php artisan horizon:work redis --delay=0 --memory=128 --queue=someQueue --sleep=3 --timeout=60 --tries=1 --supervisor=hostname-Ec9z:someWorker…

Also each horizon:work has an argument referencing its supervisor so in the process list you can easily see what worker belongs to which supervisor.

All 2 comments

Horizon command is all you need to run, it runs the supervisor command and work command as per the options you specify in your Horizon config file.

@neorganic

  • horizon is the master process, controlling everything
    (from below: php(1613), …)
  • for each queue worker setting in your config horizon.environments.(prod or dev).* you get a single supervisor process
    (from below: php7.1(1771), php7.1(1772), …)
  • each supervisor process will run n worker processes are per your configuration.
    (from below: php7.1(1915), php7.1(1914), …)

So in a nutshell, you've a "process tree" looking like this:

init(1)-+-acpid(1230)
        |-supervisord(1398)-+-php(1613)-+-php7.1(1771)-+-php7.1(1915)
        |                   |           |              `-php7.1(18509)
        |                   |           |-php7.1(1772)-+-php7.1(1914)
        |                   |           |              `-php7.1(1918)
        |                   |           |-php7.1(1773)---php7.1(1912)
        |                   |           |-php7.1(1774)---php7.1(1930)
        |                   |           |-php7.1(1775)-+-php7.1(1913)
        |                   |           |              `-php7.1(1917)
        |                   |           |-php7.1(1776)-+-php7.1(1916)
        |                   |           |              `-php7.1(1920)
        |                   |           |-php7.1(1777)---php7.1(1921)
        |                   |           |-php7.1(1778)-+-php7.1(1923)
        |                   |           |              |-php7.1(1924)
        |                   |           |              |-php7.1(1926)
        |                   |           |              `-php7.1(1927)
        |                   |           `-php7.1(1779)---php7.1(1928)

Note that in this (real life) example there's also supervisord on top which handles re-starting horizon should it terminate (i.e. for deployments).

just that horizon:work and horizon:supervisor accepts parameters like --timeout or --queue

This is because a supervisor is started with these values from the configuration and spawns children on its own and "passes" on these values; that's why you will see many arguments repeated:

php artisan horizon:supervisor hostname-Ec9z:someWorker redis --delay=0 --memory=128 --queue=someQueue --sleep=3…
…
php artisan horizon:work redis --delay=0 --memory=128 --queue=someQueue --sleep=3 --timeout=60 --tries=1 --supervisor=hostname-Ec9z:someWorker…

Also each horizon:work has an argument referencing its supervisor so in the process list you can easily see what worker belongs to which supervisor.

Was this page helpful?
0 / 5 - 0 ratings