]> git.mxchange.org Git - friendica.git/commitdiff
Configurable amount of maximum processes
authorMichael Vogel <icarus@dabo.de>
Sat, 4 Jun 2016 09:04:26 +0000 (11:04 +0200)
committerMichael Vogel <icarus@dabo.de>
Sat, 4 Jun 2016 09:04:26 +0000 (11:04 +0200)
include/dbm.php
include/poller.php
index.php

index 1e1c3706e0e88949f2aca0bb4939430f2d9fa0d1..d588b2f76a31946c5952de0aec817210b1e02569 100644 (file)
@@ -4,23 +4,24 @@ class dbm {
                $r = q("SHOW PROCESSLIST");
                $s = array();
 
+               $processes = 0;
                $states = array();
                foreach ($r AS $process) {
                        $state = trim($process["State"]);
-                       if (!in_array($state, array("", "init", "statistics")))
+                       if (!in_array($state, array("", "init", "statistics"))) {
                                ++$states[$state];
+                               ++$processes;
+                       }
                }
                // query end
                // Sending data
                // updating
 
                $statelist = "";
-               $processes = 0;
                foreach ($states AS $state => $usage) {
                        if ($statelist != "")
                                $statelist .= ", ";
                        $statelist .= $state.": ".$usage;
-                       ++$processes;
                }
                return(array("list" => $statelist, "amount" => $processes));
        }
index 45dc332e1774d084d953c251a9f36a454e2629fe..9e7080e64248d37fe5d7865b01f7fac59cbe0bd8 100644 (file)
@@ -29,9 +29,16 @@ function poller_run(&$argv, &$argc){
 
        $processlist = dbm::processlist();
        if ($processlist["list"] != "") {
-               logger("Processes: ".$processlist["amount"]." - Processlist: ".$processlist["list"], LOGGER_DEBUG);
-               if ($processlist["amount"] > 5)
+               logger("Processcheck: Processes: ".$processlist["amount"]." - Processlist: ".$processlist["list"], LOGGER_DEBUG);
+
+               $max_processes = get_config('system', 'max_processes_backend');
+               if (intval($max_processes) == 0)
+                       $max_processes = 5;
+
+               if ($processlist["amount"] > $max_processes) {
+                       logger("Processcheck: Maximum number of processes for backend tasks (".$max_processes.") reached.", LOGGER_DEBUG);
                        return;
+               }
        }
 
        if (poller_max_connections_reached())
@@ -70,9 +77,16 @@ function poller_run(&$argv, &$argc){
                // Log the type of database processes
                $processlist = dbm::processlist();
                if ($processlist["amount"] != "") {
-                       logger("Processes: ".$processlist["amount"]." - Processlist: ".$processlist["list"], LOGGER_DEBUG);
-                       if ($processlist["amount"] > 5)
+                       logger("Processcheck: Processes: ".$processlist["amount"]." - Processlist: ".$processlist["list"], LOGGER_DEBUG);
+
+                       $max_processes = get_config('system', 'max_processes_backend');
+                       if (intval($max_processes) == 0)
+                               $max_processes = 5;
+
+                       if ($processlist["amount"] > $max_processes) {
+                               logger("Processcheck: Maximum number of processes for backend tasks (".$max_processes.") reached.", LOGGER_DEBUG);
                                return;
+                       }
                }
 
                // Constantly check the number of available database connections to let the frontend be accessible at any time
index a25c6dc77602aa05dcfa1ad9e4f460d6d68f8137..17258fd0abd32690fb8da9e53a73548e7d3f5059 100644 (file)
--- a/index.php
+++ b/index.php
@@ -45,7 +45,7 @@ require_once("include/dbm.php");
 
 if(!$install) {
        $db = new dba($db_host, $db_user, $db_pass, $db_data, $install);
-           unset($db_host, $db_user, $db_pass, $db_data);
+           unset($db_host, $db_user, $db_pass, $db_data);
 
        /**
         * Load configs from db. Overwrite configs from .htconfig.php
@@ -56,12 +56,17 @@ if(!$install) {
 
        $processlist = dbm::processlist();
        if ($processlist["list"] != "") {
-               logger("Processes: ".$processlist["amount"]." - Processlist: ".$processlist["list"], LOGGER_DEBUG);
 
-               // More than 20 running database processes?
-               // The system is too busy, so quit.
-               if ($processlist["amount"] > 20)
-                       system_unavailable();
+               logger("Processcheck: Processes: ".$processlist["amount"]." - Processlist: ".$processlist["list"], LOGGER_DEBUG);
+
+               $max_processes = get_config('system', 'max_processes_frontend');
+               if (intval($max_processes) == 0)
+                       $max_processes = 20;
+
+               if ($processlist["amount"] > $max_processes) {
+                       logger("Processcheck: Maximum number of processes for frontend tasks (".$max_processes.") reached.", LOGGER_DEBUG);
+                       return;
+               }
        }
 
        $maxsysload_frontend = intval(get_config('system','maxloadavg_frontend'));
@@ -453,9 +458,9 @@ if($a->is_mobile || $a->is_tablet) {
                $link = 'toggle_mobile?off=1&address=' . curPageURL();
        }
        $a->page['footer'] = replace_macros(get_markup_template("toggle_mobile_footer.tpl"), array(
-                               '$toggle_link' => $link,
-                               '$toggle_text' => t('toggle mobile')
-                        ));
+                               '$toggle_link' => $link,
+                               '$toggle_text' => t('toggle mobile')
+                        ));
 }
 
 /**