]> git.mxchange.org Git - friendica.git/commitdiff
Poller: Check the number of used database connections
authorMichael Vogel <icarus@dabo.de>
Tue, 9 Feb 2016 05:42:00 +0000 (06:42 +0100)
committerMichael Vogel <icarus@dabo.de>
Tue, 9 Feb 2016 05:42:00 +0000 (06:42 +0100)
include/items.php
include/poller.php

index 798ee569589efa966f3a27688f6b4bcf6a2fb134..90c39a98897ad5cf1227b0bc0c230781074447d2 100644 (file)
@@ -509,6 +509,16 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
        $arr['inform']        = ((x($arr,'inform'))        ? trim($arr['inform'])                : '');
        $arr['file']          = ((x($arr,'file'))          ? trim($arr['file'])                  : '');
 
+
+       if (($arr['author-link'] == "") AND ($arr['owner-link'] == "")) {
+               $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 5);
+               foreach ($trace AS $func)
+                       $function[] = $func["function"];
+
+               $function = implode(", ", $function);
+               logger("Both author-link and owner-link are empty. Called by: ".$function, LOGGER_DEBUG);
+       }
+
        if ($arr['plink'] == "") {
                $a = get_app();
                $arr['plink'] = $a->get_baseurl().'/display/'.urlencode($arr['guid']);
index 190f3fb1ad50f2985ed583cc8ef8588ada309814..712f6d5788da8b1f7272b0c9e2c62c1387a8d9b0 100644 (file)
@@ -26,6 +26,9 @@ function poller_run(&$argv, &$argc){
                unset($db_host, $db_user, $db_pass, $db_data);
        };
 
+       if (poller_max_connections_reached())
+               return;
+
        $load = current_load();
        if($load) {
                $maxsysload = intval(get_config('system','maxloadavg'));
@@ -117,6 +120,40 @@ function poller_run(&$argv, &$argc){
 
 }
 
+/**
+ * @brief Checks if the number of database connections has reached a critical limit.
+ *
+ * @return bool Are more than 3/4 of the maximum connections used?
+ */
+function poller_max_connections_reached() {
+       $r = q("SHOW VARIABLES WHERE `variable_name` = 'max_connections'");
+       if (!$r)
+               return false;
+
+       $max = intval($r[0]["Value"]);
+       if ($max == 0)
+               return false;
+
+       $r = q("SHOW STATUS WHERE `variable_name` = 'Threads_connected'");
+       if (!$r)
+               return false;
+
+       $connected = intval($r[0]["Value"]);
+       if ($connected == 0)
+               return false;
+
+       $level = $connected / $max;
+
+       logger("Connection usage: ".$connected."/".$max, LOGGER_DEBUG);
+
+       if ($level < (3/4))
+               return false;
+
+       logger("Maximum level (3/4) of connections reached: ".$connected."/".$max);
+       return true;
+
+}
+
 /**
  * @brief fix the queue entry if the worker process died
  *