Laravel 查询日志中存在大量作业查询是否可以?

最近,我们的 Laravel 查询日志变得明显更大。每天约为 50-100mb,一天后增加到约 1-1.5gb。


有很多对jobs表的查询,像这样


[05.08.2020 00:00:02] select * from `jobs` where `queue` = ? and ((`reserved_at` is null and `available_at` <= ?) or (`reserved_at` <= ?)) order by `id` asc limit 1 for update [default, 1596574802, 1596571202]

[05.08.2020 00:00:05] select * from `jobs` where `queue` = ? and ((`reserved_at` is null and `available_at` <= ?) or (`reserved_at` <= ?)) order by `id` asc limit 1 for update [default, 1596574805, 1596571205]

[05.08.2020 00:00:09] select * from `jobs` where `queue` = ? and ((`reserved_at` is null and `available_at` <= ?) or (`reserved_at` <= ?)) order by `id` asc limit 1 for update [default, 1596574809, 1596571209]

[05.08.2020 00:00:12] select * from `jobs` where `queue` = ? and ((`reserved_at` is null and `available_at` <= ?) or (`reserved_at` <= ?)) order by `id` asc limit 1 for update [default, 1596574812, 1596571212]

[05.08.2020 00:00:15] select * from `jobs` where `queue` = ? and ((`reserved_at` is null and `available_at` <= ?) or (`reserved_at` <= ?)) order by `id` asc limit 1 for update [default, 1596574815, 1596571215]

[05.08.2020 00:00:18] select * from `jobs` where `queue` = ? and ((`reserved_at` is null and `available_at` <= ?) or (`reserved_at` <= ?)) order by `id` asc limit 1 for update [default, 1596574818, 1596571218]

[05.08.2020 00:00:21] select * from `jobs` where `queue` = ? and ((`reserved_at` is null and `available_at` <= ?) or (`reserved_at` <= ?)) order by `id` asc limit 1 for update [default, 1596574821, 1596571221]


他们整天都在这样询问。


我怎样才能减少这个金额?或者有那么多疑问可以吗jobs?


慕森王
浏览 47回答 1
1回答

郎朗坤

是的,如果您有积压的工作需要几秒钟才能完成,这似乎很正常。来自文档:当队列中有可用作业时,工作人员将继续处理作业,作业之间不会有任何延迟。但是,该sleep选项确定如果没有新的工作可用,工作人员将“睡眠”多长时间(以秒为单位)。睡眠期间,worker 不会处理任何新作业 - 这些作业将在worker 再次醒来后处理。https://laravel.com/docs/7.x/queues#job-expirations-and-timeouts因此,在您的示例中,队列工作线程有积压的作业需要处理,并且在每个完成的作业后立即获取下一个作业。
打开App,查看更多内容
随时随地看视频慕课网APP