laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.52k stars 11.02k forks source link

Discrepancies in the calculation of queue sizes #38113

Closed Damian89 closed 3 years ago

Damian89 commented 3 years ago

Description:

While working with Redis as our default queue driver, we noticed some discrepancies in the calculation of queue sizes.

Steps To Reproduce:

Check: Queue::size("queue-name") vs llen vs zrange+count()

I made a simple command to dig deeper:

    public function handle()
    {

        $d2 = Redis::connection('default')->zrange("queues:".$this->option("queue").":reserved", -9999, 9999);

        $this->info("via zrange+count(): " . count($d2));
        $this->info("via llen: ".Redis::connection('default')->llen("queues:".$this->option("queue")));
        $this->info("via queue:size(): ".Queue::size($this->option("queue")));

        foreach ($d2 as $job) {
            $data = json_decode($job);
            $this->line("$data->displayName: ");
        }

    }

Returns:

root@v35933:/var/www/html/ptm# php artisan tests:queue --queue=http-and-dns
via zrange+count(): 6
via llen: 2656
via queue:size(): 2662
App\Jobs\UpdateBasicHostdata: 
App\Jobs\UpdateBasicHostdata: 
App\Jobs\UpdateBasicHostdata: 
App\Jobs\UpdateBasicHostdata: 
App\Jobs\UpdateBasicHostdata: 
App\Jobs\UpdateBasicHostdata:

It looks like there are only 6 real jobs in the queue but queue:size shows 2662 and llen shows 2656 (obviosuly its the difference between 2662 and 6).

I don't know what the problem is - just noticed that Queue::size() calculates the queue size using a LuaScript class.

Any ideas? This looks like a bug to me.

Or do I miss something?

Best,

Damian

driesvints commented 3 years ago

Hey there,

Can you first please try one of the support channels below? If you can actually identify this as a bug, feel free to open up a new issue with a link to the original one and we'll gladly help you out.

Thanks!