From 4b48c0c912c472130bc69cd42109fcc43c9ab560 Mon Sep 17 00:00:00 2001 From: Andrew Hamilton Date: Wed, 9 Nov 2016 23:52:12 +0100 Subject: [PATCH] Correctly nice and ionice the worker processes. This had stopped working. Unfortunately it doesn't seem to help anyway. Ideally the responsiveness of the interface is the same, regardless of whether the workers are paused or not. Atm its much better when they are paused. --- install-dependencies | 2 +- vigil | 2 +- vigil_test.py | 8 -------- worker.py | 11 +++-------- 4 files changed, 5 insertions(+), 18 deletions(-) diff --git a/install-dependencies b/install-dependencies index 37c8802..d7afe76 100755 --- a/install-dependencies +++ b/install-dependencies @@ -6,7 +6,7 @@ set -e echo "Install the dependencies of the vigil script..." sudo apt-get --yes install python3-minimal python3-pygments python3-pyinotify \ - python3-urwid python3-psutil python3-docopt util-linux + python3-urwid python3-docopt util-linux echo echo "Install all the tools vigil may need..." ./install-tools diff --git a/vigil b/vigil index 504e22e..1316c02 100755 --- a/vigil +++ b/vigil @@ -918,7 +918,7 @@ def save_state(pickle_path, summary, screen, log): def main(root_path, loop, worker_count=None, is_sandboxed=True, editor_command=None, is_being_tested=False): if worker_count is None: - worker_count = multiprocessing.cpu_count() * 2 + worker_count = multiprocessing.cpu_count() pickle_path = os.path.join(tools.CACHE_PATH, "summary.pickle") jobs_added_event = asyncio.Event() appearance_changed_event = asyncio.Event() diff --git a/vigil_test.py b/vigil_test.py index f93c503..46ed18b 100755 --- a/vigil_test.py +++ b/vigil_test.py @@ -11,8 +11,6 @@ import shutil import tempfile import unittest -import psutil - os.environ["TERM"] = "xterm-256color" import fill3 @@ -213,17 +211,12 @@ def _tmp_total(): return len(os.listdir("/tmp")) -def _all_processes(): - return set(psutil.process_iter()) - - class MainTestCase(unittest.TestCase): def test_main_and_restart_and_no_leaks_and_is_relocatable(self): def test_run(root_path, loop): mount_total = _mount_total() # tmp_total = _tmp_total() - # processes = _all_processes() foo_path = os.path.join(root_path, "foo") open(foo_path, "w").close() vigil.manage_cache(root_path) @@ -236,7 +229,6 @@ class MainTestCase(unittest.TestCase): self.assertTrue(os.path.exists(".vigil/" + file_name)) self.assertEqual(_mount_total(), mount_total) # self.assertEqual(_tmp_total(), tmp_total) - # self.assertEqual(_all_processes(), processes) # Fix temp_dir = tempfile.mkdtemp() try: loop = asyncio.get_event_loop() diff --git a/worker.py b/worker.py index 4e7ea16..647124c 100755 --- a/worker.py +++ b/worker.py @@ -7,15 +7,11 @@ import asyncio import os import signal -import psutil - import tools -def _make_process_nicest(pid): - process = psutil.Process(pid) - process.nice(19) - process.ionice(psutil.IOPRIO_CLASS_IDLE) +def nice_command(command): + return ["nice", "-n", "19", "ionice", "-c", "3"] + command class Worker: @@ -37,7 +33,7 @@ class Worker: else: command = [__file__] create = asyncio.create_subprocess_exec( - *command, stdin=asyncio.subprocess.PIPE, + *nice_command(command), stdin=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE, preexec_fn=os.setsid) self.process = await create @@ -53,7 +49,6 @@ class Worker: async def job_runner(self, summary, log, jobs_added_event, appearance_changed_event): await self.create_process() - _make_process_nicest(self.child_pgid) while True: await jobs_added_event.wait() while True: