From f8b6c774ddd81e8f3cb1fd18b1a7211aaaf0f031 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Tue, 11 Sep 2018 18:22:58 +0100 Subject: [PATCH] issue #362: cap max open files in children. --- ansible_mitogen/target.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ansible_mitogen/target.py b/ansible_mitogen/target.py index ae7990a9..347dc3c2 100644 --- a/ansible_mitogen/target.py +++ b/ansible_mitogen/target.py @@ -43,6 +43,7 @@ import operator import os import pwd import re +import resource import signal import stat import subprocess @@ -90,6 +91,15 @@ _fork_parent = None good_temp_dir = None +# subprocess.Popen(close_fds=True) aka. AnsibleModule.run_command() loops the +# entire SC_OPEN_MAX space. CentOS>5 ships with 1,048,576 FDs by default, +# resulting in huge (>500ms) runtime waste running many commands. Therefore if +# we are a child context, cap the insane FD count to something reasonable. +if subprocess.MAXFD > 512 and not mitogen.is_master: + subprocess.MAXFD = 512 + resource.setrlimit(resource.RLIMIT_NOFILE, (512, 512)) + + def get_small_file(context, path): """ Basic in-memory caching module fetcher. This generates an one roundtrip for