简体   繁体   中英

Laravel scheduler running with delay (not on time)

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. If I run artisan schedule:run from console, it runs immediately, the issue is when is fired with the cron job. I have set the cron to fire by 5 minutes instead of all minutes to see more clear.

Cron log:

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 the results are 10:52:05 up 4:29, 1 user, load average: 0,02, 0,04, 0,05 and clock is on sync.

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.

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")

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. Server load is really little, is a droplet for a private app with 15 users. Mysql queries are not slow (I have activate the slow query log)

Cron log:

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. Maybe you received ping with delay, and not call schedule.

The issue was caused by depleted entropy by PHP script.

To resolve the issue generate entropy by using haveged daemon:

  1. Enable EPEL repository:

    yum install epel-release

  2. Install daemon with the following command and enable it:

    yum install haveged chkconfig haveged on systemctl start haveged

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