mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
Merge pull request #83 from matrix-org/nofile_limit_config
Add config option to set the soft fd limit on start
This commit is contained in:
commit
3fce185c77
@ -53,6 +53,7 @@ import synapse
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import resource
|
||||||
import subprocess
|
import subprocess
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import syweb
|
import syweb
|
||||||
@ -146,8 +147,8 @@ class SynapseHomeServer(HomeServer):
|
|||||||
# instead, we'll store a copy of this mapping so we can actually add
|
# instead, we'll store a copy of this mapping so we can actually add
|
||||||
# extra resources to existing nodes. See self._resource_id for the key.
|
# extra resources to existing nodes. See self._resource_id for the key.
|
||||||
resource_mappings = {}
|
resource_mappings = {}
|
||||||
for (full_path, resource) in desired_tree:
|
for full_path, res in desired_tree:
|
||||||
logger.info("Attaching %s to path %s", resource, full_path)
|
logger.info("Attaching %s to path %s", res, full_path)
|
||||||
last_resource = self.root_resource
|
last_resource = self.root_resource
|
||||||
for path_seg in full_path.split('/')[1:-1]:
|
for path_seg in full_path.split('/')[1:-1]:
|
||||||
if path_seg not in last_resource.listNames():
|
if path_seg not in last_resource.listNames():
|
||||||
@ -178,12 +179,12 @@ class SynapseHomeServer(HomeServer):
|
|||||||
child_name)
|
child_name)
|
||||||
child_resource = resource_mappings[child_res_id]
|
child_resource = resource_mappings[child_res_id]
|
||||||
# steal the children
|
# steal the children
|
||||||
resource.putChild(child_name, child_resource)
|
res.putChild(child_name, child_resource)
|
||||||
|
|
||||||
# finally, insert the desired resource in the right place
|
# finally, insert the desired resource in the right place
|
||||||
last_resource.putChild(last_path_seg, resource)
|
last_resource.putChild(last_path_seg, res)
|
||||||
res_id = self._resource_id(last_resource, last_path_seg)
|
res_id = self._resource_id(last_resource, last_path_seg)
|
||||||
resource_mappings[res_id] = resource
|
resource_mappings[res_id] = res
|
||||||
|
|
||||||
return self.root_resource
|
return self.root_resource
|
||||||
|
|
||||||
@ -275,6 +276,20 @@ def get_version_string():
|
|||||||
return ("Synapse/%s" % (synapse.__version__,)).encode("ascii")
|
return ("Synapse/%s" % (synapse.__version__,)).encode("ascii")
|
||||||
|
|
||||||
|
|
||||||
|
def change_resource_limit(soft_file_no):
|
||||||
|
try:
|
||||||
|
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))
|
||||||
|
|
||||||
|
logger.info("Set file limit to: %d", soft_file_no)
|
||||||
|
except (ValueError, resource.error) as e:
|
||||||
|
logger.warn("Failed to set file limit: %s", e)
|
||||||
|
|
||||||
|
|
||||||
def setup():
|
def setup():
|
||||||
config = HomeServerConfig.load_config(
|
config = HomeServerConfig.load_config(
|
||||||
"Synapse Homeserver",
|
"Synapse Homeserver",
|
||||||
@ -351,10 +366,11 @@ def setup():
|
|||||||
|
|
||||||
if config.daemonize:
|
if config.daemonize:
|
||||||
print config.pid_file
|
print config.pid_file
|
||||||
|
|
||||||
daemon = Daemonize(
|
daemon = Daemonize(
|
||||||
app="synapse-homeserver",
|
app="synapse-homeserver",
|
||||||
pid=config.pid_file,
|
pid=config.pid_file,
|
||||||
action=run,
|
action=lambda: run(config),
|
||||||
auto_close_fds=False,
|
auto_close_fds=False,
|
||||||
verbose=True,
|
verbose=True,
|
||||||
logger=logger,
|
logger=logger,
|
||||||
@ -362,11 +378,13 @@ def setup():
|
|||||||
|
|
||||||
daemon.start()
|
daemon.start()
|
||||||
else:
|
else:
|
||||||
reactor.run()
|
run(config)
|
||||||
|
|
||||||
|
|
||||||
def run():
|
def run(config):
|
||||||
with LoggingContext("run"):
|
with LoggingContext("run"):
|
||||||
|
change_resource_limit(config.soft_file_limit)
|
||||||
|
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ class ServerConfig(Config):
|
|||||||
self.webclient = True
|
self.webclient = True
|
||||||
self.manhole = args.manhole
|
self.manhole = args.manhole
|
||||||
self.no_tls = args.no_tls
|
self.no_tls = args.no_tls
|
||||||
|
self.soft_file_limit = args.soft_file_limit
|
||||||
|
|
||||||
if not args.content_addr:
|
if not args.content_addr:
|
||||||
host = args.server_name
|
host = args.server_name
|
||||||
@ -77,6 +78,12 @@ class ServerConfig(Config):
|
|||||||
"content repository")
|
"content repository")
|
||||||
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,
|
||||||
|
help="Set the soft limit on the number of "
|
||||||
|
"file descriptors synapse can use. "
|
||||||
|
"Zero is used to indicate synapse "
|
||||||
|
"should set the soft limit to the hard"
|
||||||
|
"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")
|
||||||
|
Loading…
Reference in New Issue
Block a user