Browse Source

Can now set the number of CPUs for tor to use

Each node can set the number of CPUs with the 'num_cpus' argument.
If this isn't present or is set to None, then tor will use its
default number of CPUs.
Steven Engler 4 years ago
parent
commit
ed698b0cf7
2 changed files with 11 additions and 0 deletions
  1. 8 0
      lib/chutney/TorNet.py
  2. 3 0
      torrc_templates/common.i

+ 8 - 0
lib/chutney/TorNet.py

@@ -1073,6 +1073,7 @@ DEFAULTS = {
     # defaults to 1 on Linux, and 0 otherwise
     'sandbox': int(getenv_bool('CHUTNEY_TOR_SANDBOX',
                                platform.system() == 'Linux')),
+    'num_cpus': None,
 }
 
 
@@ -1186,6 +1187,13 @@ class TorEnviron(chutney.Templating.Environ):
                       (my['nick'], e.errno, e.strerror, hs_hostname_file))
         return my['hs-hostname']
 
+    def _get_num_cpus_line(self, my):
+        num_cpus = my['num_cpus']
+        num_cpus_line = 'NumCPUs {}'.format(num_cpus)
+        if num_cpus is None:
+            num_cpus_line = '#' + num_cpus_line
+        return num_cpus_line
+
     def _get_owning_controller_process(self, my):
         cpid = my['controlling_pid']
         ocp_line = ('__OwningControllerProcess %d' % (cpid))

+ 3 - 0
torrc_templates/common.i

@@ -14,6 +14,9 @@ TestingDirAuthVoteExit *
 TestingDirAuthVoteHSDir *
 V3AuthNIntervalsValid 2
 
+# This line will be commented out if 'num_cpus' is None
+${num_cpus_line}
+
 ## Always On Testing Options ##
 # We enable TestingDirAuthVoteGuard to avoid Guard stability requirements
 TestingDirAuthVoteGuard *