diff options
author | Amber Brown <hawkowl@atleastfornow.net> | 2018-10-13 00:14:08 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-13 00:14:08 +1100 |
commit | 381d2cfdf0f02935b743f4b6dc1b5133d7ed27b7 (patch) | |
tree | ff35333a1bd6658ff25ad6465ccc0ed6f27d4e76 /synapse/app/_base.py | |
parent | Comments on get_all_new_events_stream (diff) | |
download | synapse-381d2cfdf0f02935b743f4b6dc1b5133d7ed27b7.tar.xz |
Make workers work on Py3 (#4027)
Diffstat (limited to 'synapse/app/_base.py')
-rw-r--r-- | synapse/app/_base.py | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/synapse/app/_base.py b/synapse/app/_base.py index 7c866e246a..18584226e9 100644 --- a/synapse/app/_base.py +++ b/synapse/app/_base.py @@ -17,6 +17,7 @@ import gc import logging import sys +import psutil from daemonize import Daemonize from twisted.internet import error, reactor @@ -24,12 +25,6 @@ from twisted.internet import error, reactor from synapse.util import PreserveLoggingContext from synapse.util.rlimit import change_resource_limit -try: - import affinity -except Exception: - affinity = None - - logger = logging.getLogger(__name__) @@ -89,15 +84,20 @@ def start_reactor( with PreserveLoggingContext(): logger.info("Running") if cpu_affinity is not None: - if not affinity: - quit_with_error( - "Missing package 'affinity' required for cpu_affinity\n" - "option\n\n" - "Install by running:\n\n" - " pip install affinity\n\n" - ) - logger.info("Setting CPU affinity to %s" % cpu_affinity) - affinity.set_process_affinity_mask(0, cpu_affinity) + # Turn the bitmask into bits, reverse it so we go from 0 up + mask_to_bits = bin(cpu_affinity)[2:][::-1] + + cpus = [] + cpu_num = 0 + + for i in mask_to_bits: + if i == "1": + cpus.append(cpu_num) + cpu_num += 1 + + p = psutil.Process() + p.cpu_affinity(cpus) + change_resource_limit(soft_file_limit) if gc_thresholds: gc.set_threshold(*gc_thresholds) |