【问题标题】:Laravel horizon long queue timeLaravel Horizo​​n 长排队时间
【发布时间】:2020-09-27 04:13:44
【问题描述】:

我在 Laravel Horizo​​n 中遇到排队时间问题..

案例:我有一个考试监考软件,它每 30 秒从大约 1500 名学生的网络摄像头拍摄照片。然后我把它放在队列中,通过 websocket 向老师广播最新的图像。

我的服务器有 32 个 CPU 和 192GB 内存。

这是我的地平线配置:

我从系统收到了一些类似的电子邮件。像这样从 1000 秒到 >30k 秒不等。

即使我设置了 100k maxProcesses,队列处理也感觉很慢..

有人可以帮我解决这个问题吗?提前谢谢..

编辑: 为了使问题更清楚,这里是摘要:

  • 我的服务器有 32 个 CPU 和 192GB RAM (Ubuntu 18.04)。

  • 我在 Horizo​​n 配置中分配了 100k 最大进程(我昨天什至将其更改为 1.000.000 最大进程)

  • 但是队列处理没有我想象的那么快。其中一个队列甚至有 30k+ 秒的等待时间。

  • 如何让队列处理更快?我错过了任何地平线/服务器配置吗?一些限制配置可能在 PHP 限制/Redis 限制/任何限制?

【问题讨论】:

    标签: laravel queue ubuntu-18.04 laravel-horizon


    【解决方案1】:

    以下方法来自horizo​​n repository

    /**
     * Handle the event.
     *
     * @param  \Laravel\Horizon\Events\SupervisorLooped  $event
     * @return void
     */
    public function handle(SupervisorLooped $event)
    {
        if (! $this->dueToMonitor()) {
            return;
        }
    
        // Here we will calculate the wait time in seconds for each of the queues that
        // the application is working. Then, we will filter the results to find the
        // queues with the longest wait times and raise events for each of these.
        $results = app(WaitTimeCalculator::class)->calculate();
    
        $long = collect($results)->filter(function ($wait, $queue) {
            return $wait > (config("horizon.waits.{$queue}") ?? 60);
        });
    
        // Once we have determined which queues have long wait times we will raise the
        // events for each of the queues. We'll need to separate the connection and
        // queue names into their own strings before we will fire off the events.
        $long->each(function ($wait, $queue) {
            [$connection, $queue] = explode(':', $queue, 2);
    
            event(new LongWaitDetected($connection, $queue, $wait));
        });
    }
    

    LongWaitDetected 事件触发电子邮件。 “31941 秒”是您的webcam 队列的等待时间。每当supervisor 开始循环时,它就会触发MonitorWaitTimes 并且上面的代码有效。

    如果您不想收到此电子邮件,请将您的队列名称添加到您的 Horizo​​n 配置中的 waits 数组中,并带有一个大数字。

    'waits' => [
        'redis:default' => 60,
        'redis:webcam' => 1514124141
    ],
    

    但请记住;这可能表明某些流程/作业无法正常工作。 30K 秒可能是一个指标。

    【讨论】:

    • 感谢您的回答!但我的问题不是配置等待时间。我试图弄清楚如何在更快的时间内处理 >100k 队列。缓慢的处理时间会导致更长的等待时间。我将编辑问题以使其更清楚。 .
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-29
    • 2019-07-05
    • 1970-01-01
    • 2022-10-20
    • 1970-01-01
    • 2019-12-27
    • 1970-01-01
    相关资源
    最近更新 更多