Created
November 19, 2015 20:07
-
-
Save brandonlogan/8dd5f8ab98636263f9be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import multiprocessing | |
import sys | |
from octavia.api import app as api_app | |
from octavia.common import service as octavia_service | |
from octavia.i18n import _LI | |
from octavia import version | |
from gunicorn.app import base as gbase | |
from oslo_config import cfg | |
from oslo_log import log as logging | |
from oslo_reports import guru_meditation_report as gmr | |
import six | |
LOG = logging.getLogger(__name__) | |
def number_of_workers(): | |
return (multiprocessing.cpu_count() * 2) + 1 | |
class GunicornServer(gbase.BaseApplication): | |
def __init__(self, app, options=None): | |
self.options = options or {} | |
self.application = app | |
super(GunicornServer, self).__init__() | |
def load_config(self): | |
config = dict([ | |
(key, value) for key, value in six.iteritems(self.options) | |
if key in self.cfg.settings and value is not None | |
]) | |
for key, value in six.iteritems(config): | |
self.cfg.set(key.lower(), value) | |
def load(self): | |
return self.application | |
if __name__ == '__main__': | |
octavia_service.prepare_service(sys.argv) | |
gmr.TextGuruMeditation.setup_autorun(version) | |
app = api_app.setup_app() | |
host, port = cfg.CONF.bind_host, cfg.CONF.bind_port | |
options = { | |
'bind': '{host}:{port}'.format(host=host, port=port), | |
# NOTE(blogan): might want to make this configurable in the future | |
# but this will only apply for gunicorn at the moment | |
# so a discussion needs to be had about something | |
# like this | |
'workers': number_of_workers() | |
} | |
LOG.info(_LI("Starting API server on %(host)s:%(port)s"), | |
{"host": host, "port": port}) | |
GunicornServer(app, options=options).run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment