简体   繁体   中英

Laravel queues are very long time

I'm using database and local machine for using queues in Laravel. The first two queue elements are executed very quickly. After that, it's like something gets clogged up and it becomes endless. This may be due to a large number of database requests. I tried to optimize using transactions, but nothing came out. What should I do?

public function handle()
{
    $this->DBtrans($this->arr);
}

public function DBtrans($prices){
    $count = 0;
    foreach ($prices as $price) {
        if ($count==0) DB::beginTransaction();
        $count++;

        DB::table('products')
            ->where('article','LIKE', $price[0])
            ->limit(1)
            ->update(['price'=>$price[1], 'presence'=>$price[2]]);

        if($count>=200) DB::commit();
    }
}

If you have more than 200 prices, only the first 200 will be in a transaction. After 200, you commit the transaction, but you don't reset the count, nor do you create a new transaction.

The LIKE query is known to be hard on terms of speed, unless you have correctly setup indexes and are only queueing the beginning of a string. I don't really know what you'd 6 trying to do with this LIKE query though. Only check for the first character? That would result in many updates. Could also be the reason why things are slowing down.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM