Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Horizon dies after few seconds #375

Closed
spwin opened this issue Aug 5, 2018 · 15 comments
Closed

Horizon dies after few seconds #375

spwin opened this issue Aug 5, 2018 · 15 comments

Comments

@spwin
Copy link

spwin commented Aug 5, 2018

Hey,
I am trying to set up the local environment. I can see horizon dashboard with Inactive status.
When I am running php artisan horizon the status changes to Active for a second and then changes back to Inactive again. I tried using supervisor to run horizon but the same problem. From the supervisor logs I can see that it's running for a second, then restarting and starting again all the time. Is there any way to debug horizon and check why is it dying? I tried running php artisan horizon -vvv but every time the output is the same: Horizon started successfully. and then terminating the process. I can also confirm the queue is working fine when I run it using php artisan horizon:work.

Environment details:
Using Apache as a server on
Ubuntu 16.04.
Laravel version: 5.6.14
PHP version: 7.2
Redis server version: 4.0.11
Horizon version: 1.3

Configuration
config/queue.php

'redis' => [
            'driver' => 'redis',
            'connection' => 'default',
            'queue' => 'default',
            'retry_after' => 90,
            'block_for' => null,
        ],

config/horizon.php

'local' => [
            'supervisor-1' => [
                'connection' => 'redis',
                'queue' => ['default'],
                'balance' => 'auto',
                'processes' => 3,
                'tries' => 3,
            ],
        ],

.env

APP_ENV=local
QUEUE_DRIVER=redis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

Any suggestions?

@spwin
Copy link
Author

spwin commented Aug 6, 2018

Changed OS to Ubuntu 18.04 - this solved the problem. But some logging on horizon would be useful anyway.

@spwin
Copy link
Author

spwin commented Sep 23, 2018

If someone has the same problem, mine was crashing because of this:
https://github.com/laravel/horizon/blob/1.0/src/Listeners/MonitorMasterSupervisorMemory.php#L19

@mfn
Copy link
Contributor

mfn commented Sep 23, 2018

@spwin how did you fix it? Or did PHP due to the upgrade just use less memory and it auto-fixed itself.

@spwin
Copy link
Author

spwin commented Sep 23, 2018

@mfn I couldn't find other way than just comment MonitorMasterSupervisorMemory.php line 20 in vendor folder:

public function handle(MasterSupervisorLooped $event)
    {
        $master = $event->master;

        if ($master->memoryUsage() > 64) {
            // $master->terminate(12);
        }
    }

Works fine on local machine. If it's happening in production for you I think it's not a solution and you should increase memory on the server.
Cheers!

@mfn
Copy link
Contributor

mfn commented Sep 23, 2018

Hardcoded memory usage checks are never awesome; I think it would be very interesting what $master->memoryUsage() reports in your case. Do you think you will be able to get this value, e.g. via \Log::debug($master->memoryUsage());?

@spwin
Copy link
Author

spwin commented Sep 23, 2018

Now it's 44.018829345703, but this was happening for me periodically so I don't know what was the value before when it was crashing. This added line shows value every second so you can easily track it after php artisan horizon:

public function handle(MasterSupervisorLooped $event)
    {
        $master = $event->master;

        echo($master->memoryUsage() . "\n");
        if ($master->memoryUsage() > 64) {
            $master->terminate(12);
        }
    }

@Mohanrau
Copy link

Mohanrau commented Oct 2, 2018

Im having same issue any resolution team.Can anybody explain how this calculation calculating -->
$master->memoryUsage()

@mohammed1146
Copy link

mohammed1146 commented Oct 15, 2018

I have the same issue, and I noticed $master->memoryUsage() is affected if your app loading many things in ServiceProviders, such as app/Console/kernel.php if you have many commands. @spwin if you disable theses things, the $master->memoryUsage() will be lower. @themsaid

@mfn
Copy link
Contributor

mfn commented Oct 16, 2018

Can anybody explain how this calculation calculating

You can see for yourself:

public function memoryUsage()
{
return memory_get_usage() / 1024 / 1024;
}

I have the same issue, and I noticed $master->memoryUsage() is affected if your app loading many things in ServiceProviders,

What does memoryUsage() report in your case?

Maybe the hardcoded value in

if ($master->memoryUsage() > 64) {
$master->terminate(12);
}
needs to be simply configurable?

@driesvints
Copy link
Member

Yeah we could maybe make this configurable.

@tomswinkels
Copy link
Contributor

I have create a pull request.

#463

@spwin
Copy link
Author

spwin commented Jan 10, 2019

It would be nice to add an error of what’s happening as it just dies silently which is not helpful at all

@driesvints
Copy link
Member

@spwin I agree. Maybe writing to a log could be useful. Can you create a separate issue and/or PR for this?

@driesvints
Copy link
Member

The PR to make this configurable was merged.

@robclancy
Copy link
Contributor

I wish the error was added... 3am last night I had to setup worker daemons because I couldn't work out why horizon was just shutting down. Then today only realizing the problem because of this issue.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants