laravel / horizon

Dashboard and code-driven configuration for Laravel queues.
https://laravel.com/docs/horizon
MIT License
3.85k stars 645 forks source link

Why Jobs gets disapear from horizon and redis? #976

Closed bilalswiftsolutions closed 3 years ago

bilalswiftsolutions commented 3 years ago

Laravel version 8.12 Horizon version 5.6

"predis/predis": "^1.1", php version ^7.3 database mysql 5 .7

I am using laravel horizon and redis for backgorund queues process. I dispatch jobs in larage qunatity . but many of them gets delete without completing and without failing . Dont know the reason

Should i need to make changings in horizon.php ?

<?php

return [

    'waits' => [
        'redis:default,redis:invoice' => 10000,

    ],

    'trim' => [
        'recent' => 600,
        'completed' => 10,
        'recent_failed' => 10080,
        'failed' => 10080,
        'monitored' => 10080,
    ],

    'fast_termination' => false,

    'memory_limit' => 64,

Steps to re create is i dispatched almost thousand jobs many of them are just removed. redis size is 550MB

graemlourens commented 3 years ago

@bilalswiftsolutions this is the second ticket you're opening concerning the same reason, and furthermore you're not creating tickets here the way that it is required with the information needed for others to reproduce.

Please create a ticket filling out the required structure, and giving a way to reproduce the issue exactly. Please also tell us your redis memory size as this could be an issue.

I suspect that your ticket will be automatically closed shortly by one of the laravel staff due to the fact that the ticket does not comply with the requirements. Please adhere to the rules, they are there in place for a reason.

bilalswiftsolutions commented 3 years ago

Where i will find the the requirements? And y redis memory side is 550MB

bilalswiftsolutions commented 3 years ago

I have updated my question please check it and let me know if you need anything else

graemlourens commented 3 years ago

my first suggestion would be to use phpredis (pecl library) instead of predis (php implementation) and see if this still happens. phpredis is far more efficient when it comes to dealing with large amount of jobs, but there is still no reason for predis not to handle the amount you specified. It's worth a try however.

Furthermore, reduce in horizon config all 'trim' values down to '1' (second) and see if that makes a difference. However 550 MB redis memory is plenty enough to keep an estimated 50-100k jobs in memory, but it also depends on your job size.

are you maybe serialising a huge amount of data into the job when dispatching? The more properties you set before dispatching the job, the more gets serialised and put into redis.

bilalswiftsolutions commented 3 years ago

I am passing 4 to 5 parameter to job and then calling function inside the job that function is responsibile for making queries in database. do you think is there any thing wrong.

here is example

<?php

namespace App\Jobs\Invoice;

use App\Http\Controllers\Admin\Misc\InvoiceController;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Webfox\Xero\OauthCredentialManager;

class CalculateSingleConsignment implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    protected $consignment;
    protected $total_consignments ;
    protected $current_iteration;
    protected $user_id;
    protected $notify;
    public function __construct($consignment,$total_consignments,$current_iteration,$user_id,$notify)
    {
        $this->consignment = $consignment;
        $this->total_consignments = $total_consignments;
        $this->current_iteration = $current_iteration;
        $this->user_id = $user_id;
        $this->notify = $notify;

    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $invoice_controller = new InvoiceController();
        $invoice_controller->calculateConsignmentOneByOne($this->consignment,$this->total_consignments,$this->current_iteration,$this->user_id,$this->notify);
    }
}
bilalswiftsolutions commented 3 years ago

And I am also storing eloquent cache in redis

driesvints commented 3 years ago

Hi there,

Thanks for reporting but it looks like this is a question which can be asked on a support channel. Please only use this issue tracker for reporting bugs with the library itself. If you have a question on how to use functionality provided by this repo you can try one of the following channels:

However, this issue will not be locked and everyone is still free to discuss solutions to your problem!

Thanks.