Allow setting of gc.set_thresholds

This commit is contained in:
Erik Johnston 2016-06-07 15:45:56 +01:00
parent 188f8d63e2
commit dded389ac1
4 changed files with 38 additions and 6 deletions

View File

@ -16,6 +16,7 @@
import synapse import synapse
import gc
import logging import logging
import os import os
import sys import sys
@ -351,6 +352,8 @@ class SynapseService(service.Service):
def startService(self): def startService(self):
hs = setup(self.config) hs = setup(self.config)
change_resource_limit(hs.config.soft_file_limit) change_resource_limit(hs.config.soft_file_limit)
if hs.config.gc_thresholds:
gc.set_threshold(*hs.config.gc_thresholds)
def stopService(self): def stopService(self):
return self._port.stopListening() return self._port.stopListening()
@ -422,6 +425,8 @@ def run(hs):
# sys.settrace(logcontext_tracer) # sys.settrace(logcontext_tracer)
with LoggingContext("run"): with LoggingContext("run"):
change_resource_limit(hs.config.soft_file_limit) change_resource_limit(hs.config.soft_file_limit)
if hs.config.gc_thresholds:
gc.set_threshold(*hs.config.gc_thresholds)
reactor.run() reactor.run()
if hs.config.daemonize: if hs.config.daemonize:

View File

@ -43,6 +43,7 @@ from twisted.web.resource import Resource
from daemonize import Daemonize from daemonize import Daemonize
import gc
import sys import sys
import logging import logging
@ -342,6 +343,8 @@ def setup(config_options):
ps.start_listening() ps.start_listening()
change_resource_limit(ps.config.soft_file_limit) change_resource_limit(ps.config.soft_file_limit)
if ps.config.gc_thresholds:
gc.set_threshold(*ps.config.gc_thresholds)
def start(): def start():
ps.replicate() ps.replicate()
@ -361,6 +364,8 @@ if __name__ == '__main__':
def run(): def run():
with LoggingContext("run"): with LoggingContext("run"):
change_resource_limit(ps.config.soft_file_limit) change_resource_limit(ps.config.soft_file_limit)
if ps.config.gc_thresholds:
gc.set_threshold(*ps.config.gc_thresholds)
reactor.run() reactor.run()
daemon = Daemonize( daemon = Daemonize(

View File

@ -57,6 +57,7 @@ from daemonize import Daemonize
import sys import sys
import logging import logging
import contextlib import contextlib
import gc
import ujson as json import ujson as json
logger = logging.getLogger("synapse.app.synchrotron") logger = logging.getLogger("synapse.app.synchrotron")
@ -484,6 +485,8 @@ def setup(config_options):
ss.start_listening() ss.start_listening()
change_resource_limit(ss.config.soft_file_limit) change_resource_limit(ss.config.soft_file_limit)
if ss.config.gc_thresholds:
ss.set_threshold(*ss.config.gc_thresholds)
def start(): def start():
ss.get_datastore().start_profiling() ss.get_datastore().start_profiling()
@ -496,17 +499,19 @@ def setup(config_options):
if __name__ == '__main__': if __name__ == '__main__':
with LoggingContext("main"): with LoggingContext("main"):
ps = setup(sys.argv[1:]) ss = setup(sys.argv[1:])
if ps.config.daemonize: if ss.config.daemonize:
def run(): def run():
with LoggingContext("run"): with LoggingContext("run"):
change_resource_limit(ps.config.soft_file_limit) change_resource_limit(ss.config.soft_file_limit)
if ss.config.gc_thresholds:
gc.set_threshold(*ss.config.gc_thresholds)
reactor.run() reactor.run()
daemon = Daemonize( daemon = Daemonize(
app="synapse-pusher", app="synapse-synchrotron",
pid=ps.config.pid_file, pid=ss.config.pid_file,
action=run, action=run,
auto_close_fds=False, auto_close_fds=False,
verbose=True, verbose=True,

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from ._base import Config from ._base import Config, ConfigError
class ServerConfig(Config): class ServerConfig(Config):
@ -38,6 +38,20 @@ class ServerConfig(Config):
self.listeners = config.get("listeners", []) self.listeners = config.get("listeners", [])
thresholds = config.get("gc_thresholds", None)
if thresholds is not None:
try:
assert len(thresholds) == 3
self.gc_thresholds = (
int(thresholds[0]), int(thresholds[1]), int(thresholds[2]),
)
except:
raise ConfigError(
"Value of `gc_threshold` must be a list of three integers if set"
)
else:
self.gc_thresholds = None
bind_port = config.get("bind_port") bind_port = config.get("bind_port")
if bind_port: if bind_port:
self.listeners = [] self.listeners = []
@ -157,6 +171,9 @@ class ServerConfig(Config):
# hard limit. # hard limit.
soft_file_limit: 0 soft_file_limit: 0
# The GC threshold parameters to pass to `gc.set_threshold`, if defined
# gc_thresholds: [700, 10, 10]
# A list of other Home Servers to fetch the public room directory from # A list of other Home Servers to fetch the public room directory from
# and include in the public room directory of this home server # and include in the public room directory of this home server
# This is a temporary stopgap solution to populate new server with a # This is a temporary stopgap solution to populate new server with a