falconry / falcon

The no-magic web data plane API and microservices framework for Python developers, with a focus on reliability, correctness, and performance at scale.
https://falcon.readthedocs.io/en/stable/
Apache License 2.0
9.44k stars 925 forks source link

Expand deployment guide #462

Open kgriffs opened 9 years ago

kgriffs commented 9 years ago

Discuss deployments using some of the more popular web servers and cloud providers. This guide should only provide high-level guidance, and defer to the relevant project/vendor docs for details.

WSGI servers

Short discussion on reverse proxies, load balancers:

Cloud providers:

See also:

anekix commented 6 years ago

@kgriffs can I take this on me?

kgriffs commented 6 years ago

@anekix go for it, thanks!

kgriffs commented 6 years ago

Hi @anekix, just following up, were you still interested in taking this one?

kgriffs commented 6 years ago

OK, I'm assuming this one is fair game for anyone else who would like to pick it up. :)

nZac commented 6 years ago

I have some examples of working with uWSGI & NGINX. What would be most helpful? An example configuration file and maybe a wsgi.py file for how to attach an app to an uWSGI master?

kgriffs commented 6 years ago

Related: https://github.com/falconry/falcon/issues/899

kgriffs commented 6 years ago

@nZac I think it would be great to have a page added to the doc with sections for difference deployment scenarious and a TOC at the top. uwsgi + nginx would be a great first addition to that page.

fgimian commented 6 years ago

For Gunicorn, you can reference the official Deploying Gunicorn docs which I found very helpful recently.

I think it would be good to make a recommendation on which workers are recommended. In my testing of a little hello world app, meinheld workers performed the best with Falcon.

           falcon (req/sec)
--------- ------------------
eventlet        19.94k 
gevent          19.95k
gunicorn        13.28k
meinheld        70.62k
uwsgi           errors

I would really like to see some recommendations on uWSGI settings too as I would constantly see socket errors when smashing uWSGI with load.

Tested on the following instance:

AMI: CentOS 7 (x86_64) - with Updates HVM
Type: t2.2xlarge
vCPUs: 8
Memory (GiB): 32
Python: 3.6.5 (from IUS YUM repository)

With the following test command:

wrk --duration 10s --threads 1 --connections 200 http://wsgi:8000

And the following Gunicorn command:

gunicorn \
  --workers 17 --worker-class=meinheld.gmeinheld.MeinheldWorker \
  --bind 0.0.0.0:8000 \
  hello_falcon:app

And finally here's the Falcon code:

import falcon

class HelloResource(object):
    def on_get(self, req, resp):
        resp.body = 'Hello World!'

app = falcon.API()
app.add_route('/', HelloResource())

To be honest, in all my testing thus far, I'm just not convinced of PyPy's performance once you add the WSGI server in, hence my issue #1309 so I'm keen to see your suggestions on deploying with PyPy too 😄

Keep up the great work! Fotis

fgimian commented 6 years ago

Hope it's OK if I post another little tip I've learned here. If you are deploying with Gunicorn, it's important that you configure logging to write to Gunicorn's error logger or it won't log correctly during deployment.

To make this easy, I add the handler to the root logger like so:

# Configure the root handler log level and ensure that it is set to send logs
# to Gunicorn's error logs.
gunicorn_error_logger = logging.getLogger('gunicorn.error')
logging.root.handlers.extend(gunicorn_error_logger.handlers)
logging.root.setLevel(gunicorn_error_logger.level)

Perhaps the suggestion could then be that resources simply inherit this log level:

...
        self.logger = logging.getLogger('app.endpoint')
        self.logger.setLevel(logging.root.level)
...

Or of course, they can override it.

Hope this helps Fotis

waghanza commented 5 years ago

I find the gunicorn + meinheld deployment very easy to set-up @see https://github.com/the-benchmarker/web-frameworks/blob/master/python/falcon/Dockerfile#L12

B1gG commented 3 years ago

Hi @fgimian, did you managed to have PYPY to work with Falcon + Gunicorn?