By default set soft limit to hard limit

This commit is contained in:
Erik Johnston 2015-02-20 16:09:44 +00:00
parent 939273c4b0
commit 7c56210f20
2 changed files with 11 additions and 7 deletions

View File

@ -273,7 +273,12 @@ def get_version_string():
def change_resource_limit(soft_file_no): def change_resource_limit(soft_file_no):
try: try:
soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE) soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE)
if not soft_file_no:
soft_file_no = hard
resource.setrlimit(resource.RLIMIT_NOFILE, (soft_file_no, hard)) resource.setrlimit(resource.RLIMIT_NOFILE, (soft_file_no, hard))
logger.info("Set file limit to: %d", soft_file_no) logger.info("Set file limit to: %d", soft_file_no)
except (ValueError, resource.error) as e: except (ValueError, resource.error) as e:
logger.warn("Failed to set file limit: %s", e) logger.warn("Failed to set file limit: %s", e)
@ -372,7 +377,6 @@ def setup():
def run(config): def run(config):
with LoggingContext("run"): with LoggingContext("run"):
if config.soft_file_limit:
change_resource_limit(config.soft_file_limit) change_resource_limit(config.soft_file_limit)
reactor.run() reactor.run()

View File

@ -79,11 +79,11 @@ class ServerConfig(Config):
server_group.add_argument("--no-tls", action='store_true', server_group.add_argument("--no-tls", action='store_true',
help="Don't bind to the https port.") help="Don't bind to the https port.")
server_group.add_argument("--soft-file-limit", type=int, default=0, server_group.add_argument("--soft-file-limit", type=int, default=0,
help="Set the limit on the number of file " help="Set the soft limit on the number of "
"descriptors synapse can use. Zero " "file descriptors synapse can use. "
"is used to indicate synapse should " "Zero is used to indicate synapse "
"not change the limit from system " "should set the soft limit to the hard"
"default.") "limit.")
def read_signing_key(self, signing_key_path): def read_signing_key(self, signing_key_path):
signing_keys = self.read_file(signing_key_path, "signing_key") signing_keys = self.read_file(signing_key_path, "signing_key")