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异步队列耗时比较高

《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 1

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

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

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