Laravel5.8 的 Redis 异步队列耗时比较高

环境

centos7
php7.2.21
redis3.2.10

代码

控制器

public function setLoginLog($userInfo, $header, $ip, $appId)
    {
        try {
            LoginLog::dispatch($userInfo, $header, $ip, $appId);
        } catch (\Exception $e) {
            Log::error('登录日志队列异常', [$e->getLine(), $e->getFile(), $e->getMessage()]);
        }
    }

Jobs

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

    protected $data;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($userInfo, $header, $ip, $appId)
    {
        $this->data = [
            'app_id'     => $appId,
            'user_agent' => $header,
            'account_id' => $userInfo['account_id'],
            'workcode'   => $userInfo['workcode'] ?? $userInfo['user']['workcode'],
            'login_ip'   => $ip,
            'login_time' => date("Y-m-d H:i:s")
        ];
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $loginLogResponse = ir('log.login.add', $this->data);
        if (!$loginLogResponse->ok()) {
            Log::error('sso登录日志消费异常', [$this->data, $loginLogResponse->raw()]);
        }
    }
}

性能分析

基本上每个请求入队列都会消耗在大约20%左右,是不是有点太高了,本来想着用redis异步队列可以提高一些性能,这里还有优化空间吗?
跟redis服务器的通信是内网通信,网络延迟也不高。

laravel5.8的redis异步队列耗时比较高

laravel5.8的redis异步队列耗时比较高

《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
讨论数量: 1

不用把对象丢进去,另外你这个有外部网络请求

5年前 评论
gedongdong2010 (楼主) 5年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!