Commit d91e8cca authored by Lukáš Lalinský's avatar Lukáš Lalinský

Add uWSGI config

parent 0edd9c3e
Pipeline #20406 passed with stages
in 2 minutes and 43 seconds
......@@ -17,7 +17,7 @@ def run():
@run.command('web')
@click.option('-c', '--config', default='acoustid.conf', envvar='ACOUSTID_CONFIG')
@click.option('-w', '--workers', default=1, envvar='ACOUSTID_WEB_WORKERS')
@click.option('-w', '--workers', type=int, envvar='ACOUSTID_WEB_WORKERS')
def run_web_cmd(config, workers):
"""Run production uWSGI with the website."""
script = Script(config)
......@@ -28,7 +28,7 @@ def run_web_cmd(config, workers):
@run.command('api')
@click.option('-c', '--config', default='acoustid.conf', envvar='ACOUSTID_CONFIG')
@click.option('-w', '--workers', default=1, envvar='ACOUSTID_API_WORKERS')
@click.option('-w', '--workers', type=int, envvar='ACOUSTID_API_WORKERS')
def run_api_cmd(config, workers):
"""Run production uWSGI with the API."""
script = Script(config)
......
......@@ -196,6 +196,37 @@ class WebSiteConfig(object):
read_env_item(self, 'shutdown_delay', prefix + 'SHUTDOWN_DELAY', convert=int)
class uWSGIConfig(object):
def __init__(self):
self.harakiri = 60
self.workers = 2
self.post_buffering = 0
self.buffer_size = 10240
self.offload_threads = 1
def read(self, parser, section):
if parser.has_section(section):
return
if parser.has_option(section, 'harakiri'):
self.harakiri = parser.getint(section, 'harakiri')
if parser.has_option(section, 'workers'):
self.workers = parser.getint(section, 'workers')
if parser.has_option(section, 'post_buffering'):
self.post_buffering = parser.getint(section, 'post_buffering')
if parser.has_option(section, 'buffer_size'):
self.buffer_size = parser.getint(section, 'buffer_size')
if parser.has_option(section, 'offload_threads'):
self.offload_threads = parser.getint(section, 'offload_threads')
def read_env(self, prefix):
read_env_item(self, 'harakiri', prefix + 'UWSGI_HARAKIRI', convert=int)
read_env_item(self, 'workers', prefix + 'UWSGI_WORKERS', convert=int)
read_env_item(self, 'post_buffering', prefix + 'UWSGI_POST_BUFFERING', convert=int)
read_env_item(self, 'buffer_size', prefix + 'UWSGI_BUFFER_SIZE', convert=int)
read_env_item(self, 'offload_threads', prefix + 'UWSGI_OFFLOAD_THREADS', convert=int)
class SentryConfig(object):
def __init__(self):
......@@ -287,6 +318,7 @@ class Config(object):
self.cluster = ClusterConfig()
self.rate_limiter = RateLimiterConfig()
self.sentry = SentryConfig()
self.uwsgi = uWSGIConfig()
def read(self, path):
logger.info("Loading configuration file %s", path)
......@@ -301,6 +333,7 @@ class Config(object):
self.cluster.read(parser, 'cluster')
self.rate_limiter.read(parser, 'rate_limiter')
self.sentry.read(parser, 'sentry')
self.uwsgi.read(parser, 'uwsgi')
def read_env(self, tests=False):
if tests:
......@@ -316,3 +349,4 @@ class Config(object):
self.cluster.read_env(prefix)
self.rate_limiter.read_env(prefix)
self.sentry.read_env(prefix)
self.uwsgi.read_env(prefix)
......@@ -102,7 +102,7 @@ def run_uwsgi(config, args):
cleanup_shutdown_file(config.website.shutdown_file_path)
def common_uwsgi_args(config, workers=1):
def common_uwsgi_args(config, workers=None):
# type: (Config, int) -> List[six.text_type]
args = [
os.path.join(sys.prefix, "bin", "uwsgi"),
......@@ -112,14 +112,19 @@ def common_uwsgi_args(config, workers=1):
"--disable-logging",
"--log-date",
"--buffer-size", "10240",
"--workers", six.text_type(workers),
"--offload-threads", "1",
"--harakiri", "60",
"--harakiri-verbose",
"--post-buffering", "1",
"--workers", six.text_type(workers or config.uwsgi.workers),
"--enable-threads",
"--need-app",
]
if config.uwsgi.harakiri:
args.extend([
"--harakiri", six.text_type(config.uwsgi.harakiri),
"--harakiri-verbose",
])
if config.uwsgi.offload_threads:
args.extend(["--offload-threads", six.text_type(config.uwsgi.offload_threads)])
if config.uwsgi.post_buffering:
args.extend(["--post-buffering", six.text_type(config.uwsgi.post_buffering)])
if 'PYTHONPATH' in os.environ:
args.extend(["--python-path", os.environ['PYTHONPATH']])
if hasattr(sys, 'real_prefix'):
......@@ -127,7 +132,7 @@ def common_uwsgi_args(config, workers=1):
return args
def run_api_app(config, workers=1):
def run_api_app(config, workers=None):
# type: (Config, int) -> int
args = common_uwsgi_args(config, workers=workers) + [
"--http-socket", "0.0.0.0:3031",
......@@ -136,7 +141,7 @@ def run_api_app(config, workers=1):
return run_uwsgi(config, args)
def run_web_app(config, workers=1):
def run_web_app(config, workers=None):
# type: (Config, int) -> int
static_dir = os.path.join(os.path.dirname(__file__), 'web', 'static')
args = common_uwsgi_args(config, workers=workers) + [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment