Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

redis 队列四万条数据,while循环跑阿里接口,512M内存溢出

// 这是定时任务入口
public function start(){
    $redis = Cache::handler();
    // ... 这里省略了写入队列的过程,监控的时候发现这个过程都是正常的。
    //就是在 sendPush 大概2万条数据左右就溢出了!!!
    $this->sendPush($redis,'ali_redis_key')
}
//$redis 是
protected function sendPush($redis,$redis_key){
    $c0 = 0;  // 请求成功计数器
    $c1 = [];  // 请求失败
    $c2 = 0;  // 队列数据无效计数器
    $c3 = 0;  // form_id 不存在计数器
    // 这里是设置支付宝接口参数的,用的是最新的alipay easy
    Factory::setOptions($this->getCertAccount());
    $msgClient = Factory::marketing()->templateMessage();
    $cache_name = 'qcj.alifrom:fromid_';
    while(!empty($va = $redis->lPop($redis_key))) {
        $sendData = explode(',',$va);
        if(count($sendData) === 3){
            $from_id = Cache::get($cache_name.$sendData[2]);
            if( $from_id ) {
                $res = $this->marketingTemplateMessage($msgClient, $sendData[0] , $from_id ,'每日签到' ,'您今天可以签到获取幸运星了哦' , '您已连续签到'.$sendData[1].'天');
                if( $res['code'] == 0 ) {
                    $c0++;
                }else{
                    // 推送异常,删除此 form_id
                    Cache::rm($cache_name.$sendData[2]);
                    $c1[] = $sendData[2];
                }
            }else{
                $c3++;
            }
        }else{
            $c2++;
        }
    }
    Log::warning("执行完毕 , 成功 : $c0 , 失败 : " . join(',',$c1) . "   队列跳过 : $c2 , form_id无效 : $c3");
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

c1 一直存在,没有释放, 可以看看一下c1


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...