]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #9754 from annando/delete-sleeping-processes
authorTobias Diekershoff <tobias.diekershoff@gmx.net>
Thu, 7 Jan 2021 08:12:00 +0000 (09:12 +0100)
committerGitHub <noreply@github.com>
Thu, 7 Jan 2021 08:12:00 +0000 (09:12 +0100)
Delete sleeping database processes

src/Worker/Cron.php
static/defaults.config.php

index 1901766d3ac1d4d341f69322388c902ae8704b44..acb5132afbc51020ef8190a7261da44f414b2d5a 100644 (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);
+       }
 }
index 2bc2bea5b1a93648d3a75142317fe9d33bbf59db..893f77cbd5d44fd1217a02476a1a40690dd2003d 100644 (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,