简体   繁体   English

Laravel Scheduler延迟运行(不准时)

[英]Laravel scheduler running with delay (not on time)

Laravel 5.5 PHP 7.1 Laravel 5.5 PHP 7.1

I have a strange issue on production server that delays the scheduler so tasks are not fired on time. 我在生产服务器上遇到一个奇怪的问题,该问题延迟了调度程序,因此无法按时触发任务。 It seems that for some reason the command artisan schedule:run sometimes takes time to load. 似乎由于某种原因, artisan schedule:run命令有时需要一些时间来加载。 If I run artisan schedule:run from console, it runs immediately, the issue is when is fired with the cron job. 如果我从控制台运行artisan schedule:run ,它将立即运行,问题是cron作业何时触发。 I have set the cron to fire by 5 minutes instead of all minutes to see more clear. 我已将cron设置为5分钟而不是所有分钟,以查看更多清晰信息。

Cron log: Cron日志:

Sep 29 10:05:01 localhost CROND[17311]
Sep 29 10:10:01 localhost CROND[17846]
Sep 29 10:15:01 localhost CROND[18165]

Scheduler log: 计划程序日志:

Received ping at Saturday, 29-Sep-2018 10:06:11 EDT 
Received ping at Saturday, 29-Sep-2018 10:10:01 EDT 
Received ping at Saturday, 29-Sep-2018 10:18:55 EDT

The only task the scheduler has is a simple closure to measure time, no complex tasks. 调度程序唯一的任务是关闭时间以测量时间,没有复杂的任务。

$schedule->call(function () {
        return true;
    })
    ->everyMinute()
    ->pingBefore('...')

Somebody told me this could be a server load issue or clock sync, after running uptime; sar -q; etc 有人告诉我,这可能是服务器在uptime; sar -q; etc运行uptime; sar -q; etc后出现负载问题或时钟同步uptime; sar -q; etc uptime; sar -q; etc uptime; sar -q; etc the results are 10:52:05 up 4:29, 1 user, load average: 0,02, 0,04, 0,05 and clock is on sync. uptime; sar -q; etc结果是10:52:05 up 4:29, 1 user, load average: 0,02, 0,04, 0,05并且时钟处于同步状态。

The real issue is that if I have a task set to run eg at 10:05, it never runs, because the scheduler is loaded at 10:06. 真正的问题是,如果我有一个任务要在例如10:05运行,则它永远不会运行,因为计划程序是在10:06加载的。

Any ideas? 有任何想法吗?

Updated results: ---------------- 更新结果:----------------

I have discovered that if I execute any artisan command during the "hang up" it takes forever. 我发现,如果我在“挂断”期间执行任何工匠命令,则将花费很多时间。 Lets say you run any artisan command at 16:24 this command is not resolved until 16:27:31 (when the system is "locked out") 假设您在16:24运行任何artisan命令,直到16:27:31(当系统“锁定”时),该命令才会解析

I have no more ideas... Have looked in logs and all that but NO CLUE. 我没有更多的想法了……看了日志等等,但是没有线索。 I think is not Laravel, maybe is a server issue. 我认为不是Laravel,也许是服务器问题。 Server load is really little, is a droplet for a private app with 15 users. 服务器负载确实很小,对于拥有15个用户的私有应用程序而言,这是一笔微不足道的事情。 Mysql queries are not slow (I have activate the slow query log) MySQL查询并不慢(我已经激活了慢查询日志)

Cron log: Cron日志:

Sep 30 16:20:01 localhost CROND[28616]
Sep 30 16:21:01 localhost CROND[854]
Sep 30 16:22:02 localhost CROND[988]
Sep 30 16:23:01 localhost CROND[1062]
Sep 30 16:24:01 localhost CROND[1132]
Sep 30 16:25:01 localhost CROND[1199]
Sep 30 16:26:01 localhost CROND[1255]
Sep 30 16:27:01 localhost CROND[1315]
Sep 30 16:28:01 localhost CROND[1411]
Sep 30 16:29:01 localhost CROND[1508]
Sep 30 16:30:01 localhost CROND[1599]
Sep 30 16:31:01 localhost CROND[1670]
Sep 30 16:32:01 localhost CROND[1742]
Sep 30 16:33:01 localhost CROND[1807]
Sep 30 16:34:01 localhost CROND[1874]
Sep 30 16:35:01 localhost CROND[1936]
Sep 30 16:36:01 localhost CROND[1995]
Sep 30 16:37:01 localhost CROND[2062]

Scheduler log: 计划程序日志:

[2018-09-30 16:20:12] production.INFO: schedule call  
[2018-09-30 16:21:01] production.INFO: schedule call  
[2018-09-30 16:22:02] production.INFO: schedule call  
[2018-09-30 16:23:01] production.INFO: schedule call  
[2018-09-30 16:27:31] production.INFO: schedule call  
[2018-09-30 16:27:31] production.INFO: schedule call  
[2018-09-30 16:27:31] production.INFO: schedule call  
[2018-09-30 16:27:31] production.INFO: schedule call  
[2018-09-30 16:28:01] production.INFO: schedule call  
[2018-09-30 16:29:01] production.INFO: schedule call
[2018-09-30 16:30:01] production.INFO: schedule call
[2018-09-30 16:31:01] production.INFO: schedule call
[2018-09-30 16:32:02] production.INFO: schedule call
[2018-09-30 16:33:01] production.INFO: schedule call
[2018-09-30 16:37:53] production.INFO: schedule call
[2018-09-30 16:37:53] production.INFO: schedule call
[2018-09-30 16:37:53] production.INFO: schedule call
[2018-09-30 16:37:53] production.INFO: schedule call

maybe you need write call log , but not ping received log. 也许您需要写呼叫日志,但不ping接收到的日志。 Maybe you received ping with delay, and not call schedule. 也许您延迟收到ping,而不是通话时间表。

The issue was caused by depleted entropy by PHP script. 该问题是由PHP脚本的熵耗尽引起的。

To resolve the issue generate entropy by using haveged daemon: 要解决此问题,请使用Haveged守护程序生成熵:

  1. Enable EPEL repository: 启用EPEL存储库:

    yum install epel-release

  2. Install daemon with the following command and enable it: 使用以下命令安装守护程序并启用它:

    yum install haveged chkconfig haveged on systemctl start haveged

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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