Make gunicorn worker count scale automatically and be configurable

Fixes https://jira.coreos.com/browse/QS-117
This commit is contained in:
Joseph Schorr 2018-01-12 16:19:37 -05:00
parent 18f1ccf80b
commit 4cd3d110db
5 changed files with 43 additions and 5 deletions

View file

@ -2,13 +2,16 @@ import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), "../"))
import multiprocessing
import logging
from Crypto import Random
from util.log import logfile_path
logconfig = logfile_path(debug=True)
bind = '0.0.0.0:5000'
workers = 2
workers = max(int(os.getenv("WORKER_COUNT_LOCAL", multiprocessing.cpu_count())), 2)
worker_class = 'gevent'
daemon = False
pythonpath = '.'
@ -18,3 +21,7 @@ def post_fork(server, worker):
# Reset the Random library to ensure it won't raise the "PID check failed." error after
# gunicorn forks.
Random.atfork()
def when_ready(server):
logger = logging.getLogger(__name__)
logger.debug('Starting local gunicorn with %s workers and %s worker class', workers, worker_class)

View file

@ -2,13 +2,16 @@ import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), "../"))
import multiprocessing
import logging
from Crypto import Random
from util.log import logfile_path
logconfig = logfile_path(debug=False)
bind = 'unix:/tmp/gunicorn_registry.sock'
workers = 8
workers = max(int(os.getenv("WORKER_COUNT_REGISTRY", multiprocessing.cpu_count() * 4)), 8)
worker_class = 'gevent'
pythonpath = '.'
preload_app = True
@ -18,3 +21,8 @@ def post_fork(server, worker):
# Reset the Random library to ensure it won't raise the "PID check failed." error after
# gunicorn forks.
Random.atfork()
def when_ready(server):
logger = logging.getLogger(__name__)
logger.debug('Starting registry gunicorn with %s workers and %s worker class', workers,
worker_class)

View file

@ -2,13 +2,16 @@ import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), "../"))
import multiprocessing
import logging
from Crypto import Random
from util.log import logfile_path
logconfig = logfile_path(debug=False)
bind = 'unix:/tmp/gunicorn_secscan.sock'
workers = 2
workers = max(int(os.getenv("WORKER_COUNT_SECSCAN", multiprocessing.cpu_count())), 2)
worker_class = 'gevent'
pythonpath = '.'
preload_app = True
@ -18,3 +21,8 @@ def post_fork(server, worker):
# Reset the Random library to ensure it won't raise the "PID check failed." error after
# gunicorn forks.
Random.atfork()
def when_ready(server):
logger = logging.getLogger(__name__)
logger.debug('Starting secscan gunicorn with %s workers and %s worker class', workers,
worker_class)

View file

@ -2,13 +2,16 @@ import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), "../"))
import multiprocessing
import logging
from Crypto import Random
from util.log import logfile_path
logconfig = logfile_path(debug=False)
bind = 'unix:/tmp/gunicorn_verbs.sock'
workers = 4
workers = max(int(os.getenv("WORKER_COUNT_VERBS", multiprocessing.cpu_count())), 2)
pythonpath = '.'
preload_app = True
timeout = 2000 # Because sync workers
@ -18,3 +21,7 @@ def post_fork(server, worker):
# Reset the Random library to ensure it won't raise the "PID check failed." error after
# gunicorn forks.
Random.atfork()
def when_ready(server):
logger = logging.getLogger(__name__)
logger.debug('Starting verbs gunicorn with %s workers and sync worker class', workers)

View file

@ -2,6 +2,9 @@ import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), "../"))
import multiprocessing
import logging
from Crypto import Random
from util.log import logfile_path
@ -9,7 +12,7 @@ from util.log import logfile_path
logconfig = logfile_path(debug=False)
bind = 'unix:/tmp/gunicorn_web.sock'
workers = 2
workers = max(int(os.getenv("WORKER_COUNT_WEB", multiprocessing.cpu_count())), 2)
worker_class = 'gevent'
pythonpath = '.'
preload_app = True
@ -18,3 +21,8 @@ def post_fork(server, worker):
# Reset the Random library to ensure it won't raise the "PID check failed." error after
# gunicorn forks.
Random.atfork()
def when_ready(server):
logger = logging.getLogger(__name__)
logger.debug('Starting web gunicorn with %s workers and %s worker class', workers,
worker_class)