Pause the worker execution when the load is too high

This commit is contained in:
Michael 2022-09-04 13:54:32 +00:00
parent da655f5159
commit 075638c0ae
3 changed files with 105 additions and 53 deletions

View file

@ -435,6 +435,33 @@ class System
return max($load_arr[0], $load_arr[1]);
}
/**
* Fetch the load and number of processes
*
* @return array
*/
public static function getLoadAvg(): array
{
$content = file_get_contents('/proc/loadavg');
if (empty($content)) {
$content = shell_exec('cat /proc/loadavg');
}
if (empty($content)) {
return [];
}
if (!preg_match("#([.\d]+)\s([.\d]+)\s([.\d]+)\s(\d+)/(\d+)#", $content, $matches)) {
return [];
}
return [
'average1' => (float)$matches[1],
'average5' => (float)$matches[2],
'average15' => (float)$matches[3],
'runnable' => (float)$matches[4],
'scheduled' => (float)$matches[5]
];
}
/**
* Redirects to an external URL (fully qualified URL)
* If you want to route relative to the current Friendica base, use App->internalRedirect()