Skip to content
Browse files

HH-38098 add nofile_soft_limit option to tornado supervisor

  • Loading branch information...
1 parent 87bfa78 commit 81a05abff93fef5dcbf73c0978e565711619e26f @alekseyrybalkin alekseyrybalkin committed Nov 11, 2013
Showing with 11 additions and 1 deletion.
  1. +11 −1 tornado_util/supervisor.py
View
12 tornado_util/supervisor.py
@@ -40,6 +40,7 @@
import re
import socket
import os
+import resource
from functools import partial
import tornado.options
@@ -49,8 +50,8 @@
tornado.options.define('workers_count', 4, int)
tornado.options.define('logfile_template', None, str)
tornado.options.define('pidfile_template', None, str)
-
tornado.options.define('supervisor_sigterm_timeout', 4, int)
+tornado.options.define('nofile_soft_limit', 4096, int)
starter_scripts = {}
@@ -217,6 +218,15 @@ def supervisor(script, config):
logging.getLogger().setLevel(logging.DEBUG)
tornado.options.enable_pretty_logging()
+ cur_soft_limit, cur_hard_limit = resource.getrlimit(resource.RLIMIT_NOFILE)
+ new_soft_limit = tornado.options.options.nofile_soft_limit
+ try:
+ resource.setrlimit(resource.RLIMIT_NOFILE, (new_soft_limit, max(new_soft_limit, cur_hard_limit)))
+ except ValueError:
+ logging.warning('We don\'t have CAP_SYS_RESOURCE, therefore soft NOFILE limit will be set to {0}'.format(
+ min(new_soft_limit, cur_hard_limit)))
+ resource.setrlimit(resource.RLIMIT_NOFILE, (min(new_soft_limit, cur_hard_limit), cur_hard_limit))
+
if cmd == 'start':
start(script, config)
sys.exit(status(expect='started'))

0 comments on commit 81a05ab

Please sign in to comment.
Something went wrong with that request. Please try again.