diff options
author | Joas Schilling <coding@schilljs.com> | 2023-12-20 10:58:08 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2023-12-20 10:58:08 +0100 |
commit | 28b55bba55cb0124d3ad00e5c48a9afe70cd52d3 (patch) | |
tree | c38733253f72cc9277f77036bacdd395b2f99989 /cron.php | |
parent | 66b2fd95d133611edec66a3f37d0555f482cf7ea (diff) | |
download | nextcloud-server-28b55bba55cb0124d3ad00e5c48a9afe70cd52d3.tar.gz nextcloud-server-28b55bba55cb0124d3ad00e5c48a9afe70cd52d3.zip |
feat(cron): Warn on excessive memory consumption in background jobs
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'cron.php')
-rw-r--r-- | cron.php | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -149,8 +149,22 @@ try { } $logger->debug('CLI cron call has selected job with ID ' . strval($job->getId()), ['app' => 'cron']); + + $memoryBefore = memory_get_usage(); + $memoryPeakBefore = memory_get_peak_usage(); + $job->execute($jobList, $logger); + $memoryAfter = memory_get_usage(); + $memoryPeakAfter = memory_get_peak_usage(); + + if ($memoryAfter - $memoryBefore > 10_000_000) { + $logger->warning('Used memory grew by more than 10 MB when executing job ' . get_class($job) . ' : ' . \OCP\Util::humanFileSize($memoryAfter). ' (before: ' . \OCP\Util::humanFileSize($memoryBefore) . ')', ['app' => 'cron']); + } + if ($memoryPeakAfter > 300_000_000) { + $logger->warning('Cron job used more than 300 MB of ram after executing job ' . get_class($job) . ': ' . \OCP\Util::humanFileSize($memoryPeakAfter) . ' (before: ' . \OCP\Util::humanFileSize($memoryPeakBefore) . ')', ['app' => 'cron']); + } + // clean up after unclean jobs \OC_Util::tearDownFS(); $tempManager->clean(); |