summary refs log tree commit diff
path: root/synapse/app
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2017-08-15 17:08:28 +0100
committerRichard van der Hoff <richard@matrix.org>2017-08-15 17:08:28 +0100
commit10d8b701a1fa585c5fc2d5edcea8d4d02ae360a4 (patch)
tree5c6a455a53db8c5eb91c8b648d0eb92daf05098e /synapse/app
parentFactor out common application start (diff)
downloadsynapse-10d8b701a1fa585c5fc2d5edcea8d4d02ae360a4.tar.xz
Allow configuration of CPU affinity
Make it possible to set the CPU affinity in the config file, so that we don't
need to remember to do it manually every time.
Diffstat (limited to 'synapse/app')
-rw-r--r--synapse/app/_base.py9
-rwxr-xr-xsynapse/app/homeserver.py1
2 files changed, 9 insertions, 1 deletions
diff --git a/synapse/app/_base.py b/synapse/app/_base.py
index 3889c35946..cd0e815919 100644
--- a/synapse/app/_base.py
+++ b/synapse/app/_base.py
@@ -15,6 +15,7 @@
 import gc
 import logging
 
+import affinity
 from daemonize import Daemonize
 from synapse.util import PreserveLoggingContext
 from synapse.util.rlimit import change_resource_limit
@@ -40,7 +41,8 @@ def start_worker_reactor(appname, config):
         config.gc_thresholds,
         config.worker_pid_file,
         config.worker_daemonize,
-        logger
+        config.worker_cpu_affinity,
+        logger,
     )
 
 
@@ -50,6 +52,7 @@ def start_reactor(
         gc_thresholds,
         pid_file,
         daemonize,
+        cpu_affinity,
         logger,
 ):
     """ Run the reactor in the main process
@@ -63,6 +66,7 @@ def start_reactor(
         gc_thresholds:
         pid_file (str): name of pid file to write to if daemonize is True
         daemonize (bool): true to run the reactor in a background process
+        cpu_affinity (int|None): cpu affinity mask
         logger (logging.Logger): logger instance to pass to Daemonize
     """
 
@@ -73,6 +77,9 @@ def start_reactor(
         # between the sentinel and `run` logcontexts.
         with PreserveLoggingContext():
             logger.info("Running")
+            if cpu_affinity is not None:
+                logger.info("Setting CPU affinity to %s" % cpu_affinity)
+                affinity.set_process_affinity_mask(0, cpu_affinity)
             change_resource_limit(soft_file_limit)
             if gc_thresholds:
                 gc.set_threshold(*gc_thresholds)
diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py
index 83b6c3212b..84ad8f04a0 100755
--- a/synapse/app/homeserver.py
+++ b/synapse/app/homeserver.py
@@ -442,6 +442,7 @@ def run(hs):
         hs.config.gc_thresholds,
         hs.config.pid_file,
         hs.config.daemonize,
+        hs.config.cpu_affinity,
         logger,
     )