mirror of
https://github.com/friendica/friendica
synced 2025-04-26 19:10:11 +00:00
Pause the worker execution when the load is too high
This commit is contained in:
parent
da655f5159
commit
075638c0ae
3 changed files with 105 additions and 53 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue