laravel队列使用速率限制导致一堆超时的问题
有个队列业务使用了限速
class InfoPushQueue implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $tries = 2;
public $timeout = 86300;
/**
* InfoPushQueue constructor.
*/
public function __construct()
{
}
/**
* @throws \Illuminate\Contracts\Redis\LimiterTimeoutException
*/
public function handle()
{
Redis::throttle('key')->allow(2)->every(1)->then(function () {
//业务
}, function () {
return $this->release(10);
});
}
}
queue的配置是这样的
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => env('REDIS_QUEUE', 'default'),
'retry_after' => 86400,
'block_for' => null,
],
比如有2000个任务在跑
如果我不限速的话 一秒会同时处理10来个,页面加载就慢了,cpu也跑满了,虽然慢但服务器还算是有响应。
然后我想优化下,改成1秒最多处理5个,没想到页面更慢了,cpu依然是跑满,而且服务器会无响应,还不如不限速的情况。
然后我再改小1秒2个,虽然服务器不慢了,但failed_job表会有一堆的超时记录
App\Jobs\InfoPushQueue has been attempted too many times or run too long. The job may have previously timed out.
而且timeout我都设置1天的时间,依然在几分钟后报超时,不知道怎么搞的?
supervisord是这样配的
[program:api]
process_name=%(program_name)s_%(process_num)02d
command=php /home/wwwroot/artisan queue:work redis --daemon --queue=high,default,low,1,2,3,4,5,6,7,8,9 --sleep=3 --tries=2 --backoff=3
autostart=true
autorestart=true
user=root
numprocs=8
redirect_stderr=true
stdout_logfile=/home/wwwroot/storage/logs/worker.log
推荐文章: