You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2017/10/12 15:50:38 UTC

[trafficserver] branch 7.1.x updated: Add a metric for tracking RSS of traffic_server

This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a commit to branch 7.1.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/7.1.x by this push:
     new 6f4faf4  Add a metric for tracking RSS of traffic_server
6f4faf4 is described below

commit 6f4faf44e959656d05fe037fc0cb194f2914adb9
Author: Leif Hedstrom <zw...@apache.org>
AuthorDate: Wed Sep 13 13:01:34 2017 -0600

    Add a metric for tracking RSS of traffic_server
    
    (cherry picked from commit c1a656e372d2577fdf63d34769a898acd1ab804f)
---
 .../monitoring/statistics/core/general.en.rst      |  5 ++++
 proxy/Main.cc                                      | 34 ++++++++++++----------
 2 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/doc/admin-guide/monitoring/statistics/core/general.en.rst b/doc/admin-guide/monitoring/statistics/core/general.en.rst
index eb08eda..50468ae 100644
--- a/doc/admin-guide/monitoring/statistics/core/general.en.rst
+++ b/doc/admin-guide/monitoring/statistics/core/general.en.rst
@@ -117,3 +117,8 @@ General
    A shortened string containing the release number of the running instance of
    |TS|.
 
+.. ts:stat:: global proxy.process.traffic_server.memory.rss integer
+   :units: bytes
+
+   The resident set size (RSS) of the ``traffic_server`` process. This is
+   basically the amount of memory this process is consuming.
diff --git a/proxy/Main.cc b/proxy/Main.cc
index b6ff339..828595a 100644
--- a/proxy/Main.cc
+++ b/proxy/Main.cc
@@ -353,8 +353,11 @@ public:
   {
     memset(&_usage, 0, sizeof(_usage));
     SET_HANDLER(&MemoryLimit::periodic);
+    RecRegisterStatInt(RECT_PROCESS, "proxy.process.traffic_server.memory.rss", static_cast<RecInt>(0), RECP_NON_PERSISTENT);
   }
+
   ~MemoryLimit() override { mutex = nullptr; }
+
   int
   periodic(int event, Event *e)
   {
@@ -364,14 +367,15 @@ public:
       delete this;
       return EVENT_DONE;
     }
-    if (_memory_limit == 0) {
-      // first time it has been run
-      _memory_limit = REC_ConfigReadInteger("proxy.config.memory.max_usage");
-      _memory_limit = _memory_limit >> 10; // divide by 1024
-    }
-    if (_memory_limit > 0) {
-      if (getrusage(RUSAGE_SELF, &_usage) == 0) {
-        Debug("server", "memory usage - ru_maxrss: %ld memory limit: %" PRId64, _usage.ru_maxrss, _memory_limit);
+
+    // "reload" the setting, we don't do this often so not expensive
+    _memory_limit = REC_ConfigReadInteger("proxy.config.memory.max_usage");
+    _memory_limit = _memory_limit >> 10; // divide by 1024
+
+    if (getrusage(RUSAGE_SELF, &_usage) == 0) {
+      RecSetRecordInt("proxy.process.traffic_server.memory.rss", _usage.ru_maxrss << 10, REC_SOURCE_DEFAULT); // * 1024
+      Debug("server", "memory usage - ru_maxrss: %ld memory limit: %" PRId64, _usage.ru_maxrss, _memory_limit);
+      if (_memory_limit > 0) {
         if (_usage.ru_maxrss > _memory_limit) {
           if (net_memory_throttle == false) {
             net_memory_throttle = true;
@@ -383,13 +387,13 @@ public:
             Debug("server", "memory usage under limit - ru_maxrss: %ld memory limit: %" PRId64, _usage.ru_maxrss, _memory_limit);
           }
         }
+      } else {
+        // this feature has not been enabled
+        Debug("server", "limiting connections based on memory usage has been disabled");
+        e->cancel();
+        delete this;
+        return EVENT_DONE;
       }
-    } else {
-      // this feature has not be enabled
-      Debug("server", "limiting connections based on memory usage has been disabled");
-      e->cancel();
-      delete this;
-      return EVENT_DONE;
     }
     return EVENT_CONT;
   }
@@ -1781,7 +1785,7 @@ main(int /* argc ATS_UNUSED */, const char **argv)
 
   eventProcessor.schedule_every(new SignalContinuation, HRTIME_MSECOND * 500, ET_CALL);
   eventProcessor.schedule_every(new DiagsLogContinuation, HRTIME_SECOND, ET_TASK);
-  eventProcessor.schedule_every(new MemoryLimit, HRTIME_SECOND, ET_TASK);
+  eventProcessor.schedule_every(new MemoryLimit, HRTIME_SECOND * 10, ET_TASK);
   REC_RegisterConfigUpdateFunc("proxy.config.dump_mem_info_frequency", init_memory_tracker, nullptr);
   init_memory_tracker(nullptr, RECD_NULL, RecData(), nullptr);
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].