Repository: trafficserver
Updated Branches:
  refs/heads/master eb183eef9 -> 22ed6d8ed


TS-2736: Add config option to set the max open files limit for the 
traffic_server
process to some percentage of the fs.file-max proc value on Linux. The default 
is 90%.


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/22ed6d8e
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/22ed6d8e
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/22ed6d8e

Branch: refs/heads/master
Commit: 22ed6d8ed1f63b87e3c9dc419f8ce58555aa6001
Parents: eb183ee
Author: Phil Sorber <[email protected]>
Authored: Thu Apr 24 11:43:25 2014 -0600
Committer: Phil Sorber <[email protected]>
Committed: Thu Apr 24 11:43:45 2014 -0600

----------------------------------------------------------------------
 CHANGES                                         |  3 +++
 .../configuration/records.config.en.rst         |  4 ++++
 lib/perl/lib/Apache/TS/AdminClient.pm           |  1 +
 mgmt/Main.cc                                    | 24 ++++++++++++++++++++
 mgmt/RecordsConfig.cc                           |  3 +++
 proxy/Main.cc                                   | 19 +++++++++++++++-
 proxy/config/records.config.default.in          |  1 +
 7 files changed, 54 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/22ed6d8e/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 9f55f55..31d869e 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,9 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache Traffic Server 5.0.0
 
+  *) [TS-2736] Add config option to set the max open files limit for the 
traffic_server
+    process to some percentage of the fs.file-max proc value on Linux. The 
default is 90%.
+
   *) [TS-2741] Add a server intercept example plugins and documentation.
 
   *) [TS-2616] Sanitize duplicate Transfer-Encoding: chunked headers.

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/22ed6d8e/doc/reference/configuration/records.config.en.rst
----------------------------------------------------------------------
diff --git a/doc/reference/configuration/records.config.en.rst 
b/doc/reference/configuration/records.config.en.rst
index 556073c..95f547b 100644
--- a/doc/reference/configuration/records.config.en.rst
+++ b/doc/reference/configuration/records.config.en.rst
@@ -257,6 +257,10 @@ Value Effect
 
    This option only has an affect when Traffic Server has been compiled with 
``--enable-hwloc``.
 
+.. ts:cv:: CONFIG proxy.config.system.file_max_pct FLOAT 0.9
+
+   Set the maximum number of file handles for the traffic_server process as a 
percentage of the the fs.file-max proc value in Linux. The default is 90%.
+
 Network
 =======
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/22ed6d8e/lib/perl/lib/Apache/TS/AdminClient.pm
----------------------------------------------------------------------
diff --git a/lib/perl/lib/Apache/TS/AdminClient.pm 
b/lib/perl/lib/Apache/TS/AdminClient.pm
index 61a0f6a..c7a6d1f 100644
--- a/lib/perl/lib/Apache/TS/AdminClient.pm
+++ b/lib/perl/lib/Apache/TS/AdminClient.pm
@@ -718,6 +718,7 @@ The Apache Traffic Server Administration Manual will 
explain what these strings
  proxy.config.stats.snap_frequency
  proxy.config.syslog_facility
  proxy.config.system.mmap_max
+ proxy.config.system.file_max_pct
  proxy.config.thread.default.stacksize
  proxy.config.udp.free_cancelled_pkts_sec
  proxy.config.udp.periodic_cleanup

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/22ed6d8e/mgmt/Main.cc
----------------------------------------------------------------------
diff --git a/mgmt/Main.cc b/mgmt/Main.cc
index ac23d21..8e7cfad 100644
--- a/mgmt/Main.cc
+++ b/mgmt/Main.cc
@@ -311,6 +311,30 @@ set_process_limits(int fds_throttle)
   ink_max_out_rlimit(RLIMIT_RSS, true, true);
 #endif
 
+#if defined(linux)
+  float file_max_pct = 0.9;
+  FILE *fd;
+
+  if ((fd = fopen("/proc/sys/fs/file-max","r"))) {
+    fscanf(fd, "%lu", &lim.rlim_max);
+    fclose(fd);
+    REC_ReadConfigFloat(file_max_pct, "proxy.config.system.file_max_pct");
+    lim.rlim_cur = lim.rlim_max = lim.rlim_max * file_max_pct;
+    if (!setrlimit(RLIMIT_NOFILE, &lim) && !getrlimit(RLIMIT_NOFILE, &lim)) {
+      fds_limit = (int) lim.rlim_cur;
+#ifdef MGMT_USE_SYSLOG
+      syslog(LOG_NOTICE, "NOTE: 
RLIMIT_NOFILE(%d):cur(%d),max(%d)",RLIMIT_NOFILE, (int)lim.rlim_cur, 
(int)lim.rlim_max);
+    } else {
+      syslog(LOG_NOTICE, "NOTE: Unable to set 
RLIMIT_NOFILE(%d):cur(%d),max(%d)", RLIMIT_NOFILE, (int)lim.rlim_cur, 
(int)lim.rlim_max);
+#endif
+    }
+#ifdef MGMT_USE_SYSLOG
+  } else {
+    syslog(LOG_NOTICE, "NOTE: Unable to open /proc/sys/fs/file-max");
+#endif
+  }
+#endif // linux
+
   if (!getrlimit(RLIMIT_NOFILE, &lim)) {
     if (fds_throttle > (int) (lim.rlim_cur + FD_THROTTLE_HEADROOM)) {
       lim.rlim_cur = (lim.rlim_max = (rlim_t) fds_throttle);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/22ed6d8e/mgmt/RecordsConfig.cc
----------------------------------------------------------------------
diff --git a/mgmt/RecordsConfig.cc b/mgmt/RecordsConfig.cc
index 7b45602..2d094b5 100644
--- a/mgmt/RecordsConfig.cc
+++ b/mgmt/RecordsConfig.cc
@@ -102,6 +102,9 @@ RecordElement RecordsConfig[] = {
   // The maximum number of chunks to allocate with mmap. Setting this to zero 
disables all use of mmap. (Unix only)
   {RECT_CONFIG, "proxy.config.system.mmap_max", RECD_INT, "2097152", 
RECU_RESTART_TS, RR_NULL, RECC_INT, NULL, RECA_READ_ONLY}
   ,
+  // The percent of the /proc/sys/fs/file-max value to set the RLIMIT_NOFILE 
cur/max to
+  {RECT_CONFIG, "proxy.config.system.file_max_pct", RECD_FLOAT, "0.9", 
RECU_RESTART_TS, RR_NULL, RECC_NULL, NULL, RECA_READ_ONLY}
+  ,
   // Traffic Server Execution threads configuration
   // By default Traffic Server set number of execution threads equal to total 
CPUs
   {RECT_CONFIG, "proxy.config.exec_thread.autoconfig", RECD_INT, "1", 
RECU_RESTART_TS, RR_NULL, RECC_INT, "[0-65535]", RECA_READ_ONLY}

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/22ed6d8e/proxy/Main.cc
----------------------------------------------------------------------
diff --git a/proxy/Main.cc b/proxy/Main.cc
index 32378fb..05affe7 100644
--- a/proxy/Main.cc
+++ b/proxy/Main.cc
@@ -796,12 +796,29 @@ adjust_sys_settings(void)
   struct rlimit lim;
   int mmap_max = -1;
   int fds_throttle = -1;
+  float file_max_pct = 0.9;
+  FILE *fd;
 
   // TODO: I think we might be able to get rid of this?
   REC_ReadConfigInteger(mmap_max, "proxy.config.system.mmap_max");
   if (mmap_max >= 0)
     ats_mallopt(ATS_MMAP_MAX, mmap_max);
 
+  if ((fd = fopen("/proc/sys/fs/file-max","r"))) {
+    fscanf(fd, "%lu", &lim.rlim_max);
+    fclose(fd);
+    REC_ReadConfigFloat(file_max_pct, "proxy.config.system.file_max_pct");
+    lim.rlim_cur = lim.rlim_max = lim.rlim_max * file_max_pct;
+    if (!setrlimit(RLIMIT_NOFILE, &lim) && !getrlimit(RLIMIT_NOFILE, &lim)) {
+      fds_limit = (int) lim.rlim_cur;
+      syslog(LOG_NOTICE, "NOTE: 
RLIMIT_NOFILE(%d):cur(%d),max(%d)",RLIMIT_NOFILE, (int)lim.rlim_cur, 
(int)lim.rlim_max);
+    } else {
+      syslog(LOG_NOTICE, "NOTE: Unable to set 
RLIMIT_NOFILE(%d):cur(%d),max(%d)", RLIMIT_NOFILE, (int)lim.rlim_cur, 
(int)lim.rlim_max);
+    }
+  } else {
+    syslog(LOG_NOTICE, "NOTE: Unable to open /proc/sys/fs/file-max");
+  }
+
   REC_ReadConfigInteger(fds_throttle, "proxy.config.net.connections_throttle");
 
   if (!getrlimit(RLIMIT_NOFILE, &lim)) {
@@ -809,7 +826,7 @@ adjust_sys_settings(void)
       lim.rlim_cur = (lim.rlim_max = (rlim_t) fds_throttle);
       if (!setrlimit(RLIMIT_NOFILE, &lim) && !getrlimit(RLIMIT_NOFILE, &lim)) {
         fds_limit = (int) lim.rlim_cur;
-       syslog(LOG_NOTICE, "NOTE: 
RLIMIT_NOFILE(%d):cur(%d),max(%d)",RLIMIT_NOFILE, (int)lim.rlim_cur, 
(int)lim.rlim_max);
+        syslog(LOG_NOTICE, "NOTE: 
RLIMIT_NOFILE(%d):cur(%d),max(%d)",RLIMIT_NOFILE, (int)lim.rlim_cur, 
(int)lim.rlim_max);
       }
     }
   }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/22ed6d8e/proxy/config/records.config.default.in
----------------------------------------------------------------------
diff --git a/proxy/config/records.config.default.in 
b/proxy/config/records.config.default.in
index 8086e09..22a2587 100644
--- a/proxy/config/records.config.default.in
+++ b/proxy/config/records.config.default.in
@@ -28,6 +28,7 @@ CONFIG proxy.config.syslog_facility STRING LOG_DAEMON
 CONFIG proxy.config.output.logfile STRING traffic.out
 CONFIG proxy.config.snapshot_dir STRING snapshots
 CONFIG proxy.config.system.mmap_max INT 2097152
+CONFIG proxy.config.system.file_max_pct FLOAT 0.9
 ##############################################################################
 #
 # Main threads configuration (worker threads). Also see configurations for

Reply via email to