]> git.mxchange.org Git - friendica.git/commitdiff
There is now a memory limit for the poller
authorMichael <heluecht@pirati.ca>
Sat, 29 Apr 2017 17:36:46 +0000 (17:36 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 29 Apr 2017 17:36:46 +0000 (17:36 +0000)
boot.php
include/poller.php
mod/admin.php
view/templates/admin_site.tpl

index d5972484bc4303d51e7ce8673c9c5ba4c38bf7be..d8b9cbf241fce7e58ba214e901e1d6f7b4cc99bb 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -1321,6 +1321,45 @@ class App {
                return false;
        }
 
+       /**
+        * @brief Checks if the minimal memory is reached
+        *
+        * @return bool Is the memory limit reached?
+        */
+       public function min_memory_reached() {
+               $min_memory = Config::get('system', 'min_memory', 0);
+               if ($min_memory == 0) {
+                       return false;
+               }
+
+               if (!is_readable("/proc/meminfo")) {
+                       return false;
+               }
+
+               $memdata = explode("\n", file_get_contents('/proc/meminfo'));
+
+               $meminfo = array();
+               foreach ($memdata as $line) {
+                       list($key, $val) = explode(":", $line);
+                       $meminfo[$key] = (int)trim(str_replace("kB", "", $val));
+                       $meminfo[$key] = (int)($meminfo[$key] / 1024);
+               }
+
+               if (!isset($meminfo['MemAvailable']) OR !isset($meminfo['MemFree'])) {
+                       return false;
+               }
+
+               $free = $meminfo['MemAvailable'] + $meminfo['MemFree'];
+
+               $reached = ($free < $min_memory);
+
+               if ($reached) {
+                       logger('Minimal memory reached: '.$free.'/'.$meminfo['MemTotal'].' - limit '.$min_memory, LOGGER_DEBUG);
+               }
+
+               return $reached;
+       }
+
        /**
         * @brief Checks if the maximum load is reached
         *
index 5560b3340e6209fc4ab82c97ecd3619bc9840afc..9641819885d0e3dc4ed786eaf44ba8ecc40a3096 100644 (file)
@@ -41,6 +41,10 @@ function poller_run($argv, $argc){
 
        $a->start_process();
 
+       if ($a->min_memory_reached()) {
+               return;
+       }
+
        if (poller_max_connections_reached()) {
                return;
        }
index 97d52f14f49365c4933f9814cf7cd9490179cc73..250ebbe2acc175d00572c3af357f6ea3ab09d1f2 100644 (file)
@@ -731,6 +731,7 @@ function admin_page_site_post(App $a) {
        $timeout                =       ((x($_POST,'timeout'))                  ? intval(trim($_POST['timeout']))               : 60);
        $maxloadavg             =       ((x($_POST,'maxloadavg'))               ? intval(trim($_POST['maxloadavg']))            : 50);
        $maxloadavg_frontend    =       ((x($_POST,'maxloadavg_frontend'))      ? intval(trim($_POST['maxloadavg_frontend']))   : 50);
+       $min_memory             =       ((x($_POST,'min_memory'))               ? intval(trim($_POST['min_memory']))            : 0);
        $optimize_max_tablesize =       ((x($_POST,'optimize_max_tablesize'))   ? intval(trim($_POST['optimize_max_tablesize'])): 100);
        $optimize_fragmentation =       ((x($_POST,'optimize_fragmentation'))   ? intval(trim($_POST['optimize_fragmentation'])): 30);
        $poco_completion        =       ((x($_POST,'poco_completion'))          ? intval(trim($_POST['poco_completion']))       : false);
@@ -816,6 +817,7 @@ function admin_page_site_post(App $a) {
        set_config('system','ssl_policy',$ssl_policy);
        set_config('system','maxloadavg',$maxloadavg);
        set_config('system','maxloadavg_frontend',$maxloadavg_frontend);
+       set_config('system','min_memory',$min_memory);
        set_config('system','optimize_max_tablesize',$optimize_max_tablesize);
        set_config('system','optimize_fragmentation',$optimize_fragmentation);
        set_config('system','poco_completion',$poco_completion);
@@ -1113,6 +1115,7 @@ function admin_page_site(App $a) {
                '$timeout'              => array('timeout', t("Network timeout"), (x(get_config('system','curl_timeout'))?get_config('system','curl_timeout'):60), t("Value is in seconds. Set to 0 for unlimited (not recommended).")),
                '$maxloadavg'           => array('maxloadavg', t("Maximum Load Average"), ((intval(get_config('system','maxloadavg')) > 0)?get_config('system','maxloadavg'):50), t("Maximum system load before delivery and poll processes are deferred - default 50.")),
                '$maxloadavg_frontend'  => array('maxloadavg_frontend', t("Maximum Load Average (Frontend)"), ((intval(get_config('system','maxloadavg_frontend')) > 0)?get_config('system','maxloadavg_frontend'):50), t("Maximum system load before the frontend quits service - default 50.")),
+               '$min_memory'           => array('min_memory', t("Minimal Memory"), ((intval(get_config('system','min_memory')) > 0)?get_config('system','min_memory'):0), t("Minimal free memory in MB for the poller. Needs access to /proc/meminfo - default 0 (deactivated).")),
                '$optimize_max_tablesize'=> array('optimize_max_tablesize', t("Maximum table size for optimization"), $optimize_max_tablesize, t("Maximum table size (in MB) for the automatic optimization - default 100 MB. Enter -1 to disable it.")),
                '$optimize_fragmentation'=> array('optimize_fragmentation', t("Minimum level of fragmentation"), ((intval(get_config('system','optimize_fragmentation')) > 0)?get_config('system','optimize_fragmentation'):30), t("Minimum fragmenation level to start the automatic optimization - default value is 30%.")),
 
index 196bc479b5c5e330c9c4527d07589f195875c88b..6a3c3fbcdda85ef8e4fe77e56ecb3d6ec19c5961 100644 (file)
        {{include file="field_input.tpl" field=$proxy}}
        {{include file="field_input.tpl" field=$proxyuser}}
        {{include file="field_input.tpl" field=$timeout}}
-       {{include file="field_input.tpl" field=$maxloadavg}}
        {{include file="field_input.tpl" field=$maxloadavg_frontend}}
        {{include file="field_input.tpl" field=$optimize_max_tablesize}}
        {{include file="field_input.tpl" field=$optimize_fragmentation}}
        <div class="submit"><input type="submit" name="page_site" value="{{$submit|escape:'html'}}" /></div>
 
        <h3>{{$worker_title}}</h3>
+       {{include file="field_input.tpl" field=$maxloadavg}}
+       {{include file="field_input.tpl" field=$min_memory}}
        {{include file="field_input.tpl" field=$worker_queues}}
        {{include file="field_checkbox.tpl" field=$worker_dont_fork}}
        {{include file="field_checkbox.tpl" field=$worker_fastlane}}