Merge pull request #9754 from annando/delete-sleeping-processes

Delete sleeping database processes
This commit is contained in:
Tobias Diekershoff 2021-01-07 09:12:00 +01:00 committed by GitHub
commit f246c3fd28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View file

@ -24,6 +24,7 @@ namespace Friendica\Worker;
use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Tag;
@ -54,6 +55,10 @@ class Cron
copy($basepath . '/.htaccess-dist', $basepath . '/.htaccess');
}
if (DI::config()->get('system', 'delete_sleeping_processes')) {
self::deleteSleepingProcesses();
}
// Fork the cron jobs in separate parts to avoid problems when one of them is crashing
Hook::fork(PRIORITY_MEDIUM, 'cron');
@ -137,4 +142,25 @@ class Cron
DI::config()->set('system', 'last_cron', time());
}
/**
* Kill sleeping database processes
*
* @return void
*/
private static function deleteSleepingProcesses()
{
Logger::info('Looking for sleeping processes');
$processes = DBA::p("SHOW FULL PROCESSLIST");
while ($process = DBA::fetch($processes)) {
if (($process['Command'] != 'Sleep') || ($process['Time'] < 300) || ($process['db'] != DBA::databaseName())) {
continue;
}
DBA::e("KILL ?", $process['Id']);
Logger::notice('Killed sleeping process', ['id' => $process['Id']]);
}
DBA::close($processes);
}
}

View file

@ -194,6 +194,10 @@ return [
// If it is not running and hadn't been terminated normally, it will be started automatically.
'daemon_watchdog' => false,
// delete_sleeping_processes (Boolean)
// Periodically delete waiting database processes.
'delete_sleeping_processes' => false,
// diaspora_test (Boolean)
// For development only. Disables the message transfer.
'diaspora_test' => false,