librelist archives

« back to archive

A question about Falcon and WSGI server

A question about Falcon and WSGI server

From:
zhiwei
Date:
2015-06-11 @ 09:34
Hi all,

In my understanding, Falcon is a framework that used to write a WSGI
app(REST app).

This WSGI app need a WSGI server to serve.

Am I right?

And I want to run Falcon app with multiple workers, does anyone know
how to implement this?

I saw there are multiple WSGI servers here:
http://wsgi.readthedocs.org/en/latest/servers.html

Could you tell me which one is better to run multiple workers and light weight?

I found werkzeug is easy to implement this, but I also found werkzeug
has the same features with Falcon, so I was confused.


Thanks.

Re: [falcon] A question about Falcon and WSGI server

From:
Oscar Carballal
Date:
2015-06-11 @ 09:46
Hi Zhiwei,

In my case I always use uWSGI as the WSGI interpreter, it's fairly
straightforward to implement (you can install it via pip) and the
configurations are easy as well.

To run an application with uWSGI you can do something like this (this is
for testing, for production you should customize it)

uwsgi --http :8080 --wsgi-file app.py --callable api

This will open your application on the port 8080 on localhost. the app.py
file is the file where you have the falcon.API() statement and the callable
is the variable name for that statement

It's a bit of self advertising, but you can take a look here to how I do
it: https://github.com/clione/sikre

Regards,
Oscar

--
Oscar Carballal Prego - Senior Software Developer
http://oscarcp.com | @pizte

On 11 June 2015 at 10:34, zhiwei <zhiweik@gmail.com> wrote:

> Hi all,
>
> In my understanding, Falcon is a framework that used to write a WSGI
> app(REST app).
>
> This WSGI app need a WSGI server to serve.
>
> Am I right?
>
> And I want to run Falcon app with multiple workers, does anyone know
> how to implement this?
>
> I saw there are multiple WSGI servers here:
> http://wsgi.readthedocs.org/en/latest/servers.html
>
> Could you tell me which one is better to run multiple workers and light
> weight?
>
> I found werkzeug is easy to implement this, but I also found werkzeug
> has the same features with Falcon, so I was confused.
>
>
> Thanks.
>

Re: [falcon] A question about Falcon and WSGI server

From:
zhiwei
Date:
2015-06-11 @ 09:56
Hi Oscar,

Thank your for your reply. It's very helpful.

Could I use uwsgi in python scripts? Just like below:

app = falcon.API()
uwsgi.run(app, host, port, workers)

And I also need to use SSL in the app, does uwsgi support SSL?

Thanks.


On Thu, Jun 11, 2015 at 5:46 PM, Oscar Carballal
<oscar.carballal@gmail.com> wrote:
> Hi Zhiwei,
>
> In my case I always use uWSGI as the WSGI interpreter, it's fairly
> straightforward to implement (you can install it via pip) and the
> configurations are easy as well.
>
> To run an application with uWSGI you can do something like this (this is for
> testing, for production you should customize it)
>
> uwsgi --http :8080 --wsgi-file app.py --callable api
>
> This will open your application on the port 8080 on localhost. the app.py
> file is the file where you have the falcon.API() statement and the callable
> is the variable name for that statement
>
> It's a bit of self advertising, but you can take a look here to how I do it:
> https://github.com/clione/sikre
>
> Regards,
> Oscar
>
> --
> Oscar Carballal Prego - Senior Software Developerhttp://oscarcp.com | @pizte
>
> On 11 June 2015 at 10:34, zhiwei <zhiweik@gmail.com> wrote:
>>
>> Hi all,
>>
>> In my understanding, Falcon is a framework that used to write a WSGI
>> app(REST app).
>>
>> This WSGI app need a WSGI server to serve.
>>
>> Am I right?
>>
>> And I want to run Falcon app with multiple workers, does anyone know
>> how to implement this?
>>
>> I saw there are multiple WSGI servers here:
>> http://wsgi.readthedocs.org/en/latest/servers.html
>>
>> Could you tell me which one is better to run multiple workers and light
>> weight?
>>
>> I found werkzeug is easy to implement this, but I also found werkzeug
>> has the same features with Falcon, so I was confused.
>>
>>
>> Thanks.
>
>

Re: [falcon] A question about Falcon and WSGI server

From:
Oscar Carballal
Date:
2015-06-11 @ 10:00
Hi Zhiwei,

Yes, you probably cna run it from a script. I usually don't take that
approach because I want to keep it as a service that I can monitor and
restart in case something happens.

The SSL layer doesn't depend on uWSGI. That will be handled by your front
server (Apache, Nginx, lighthttpd or any other) and you can also do some
customization on your falcon app. My application runs on SSL all the time
(nginx configuration plus falcon HTTPS middleware) so you will probably
find my code handy to get an example :)


Regards,
Oscar

--
Oscar Carballal Prego - Senior Software Developer
http://oscarcp.com | @pizte

On 11 June 2015 at 10:56, zhiwei <zhiweik@gmail.com> wrote:

> Hi Oscar,
>
> Thank your for your reply. It's very helpful.
>
> Could I use uwsgi in python scripts? Just like below:
>
> app = falcon.API()
> uwsgi.run(app, host, port, workers)
>
> And I also need to use SSL in the app, does uwsgi support SSL?
>
> Thanks.
>
>
> On Thu, Jun 11, 2015 at 5:46 PM, Oscar Carballal
> <oscar.carballal@gmail.com> wrote:
> > Hi Zhiwei,
> >
> > In my case I always use uWSGI as the WSGI interpreter, it's fairly
> > straightforward to implement (you can install it via pip) and the
> > configurations are easy as well.
> >
> > To run an application with uWSGI you can do something like this (this is
> for
> > testing, for production you should customize it)
> >
> > uwsgi --http :8080 --wsgi-file app.py --callable api
> >
> > This will open your application on the port 8080 on localhost. the app.py
> > file is the file where you have the falcon.API() statement and the
> callable
> > is the variable name for that statement
> >
> > It's a bit of self advertising, but you can take a look here to how I do
> it:
> > https://github.com/clione/sikre
> >
> > Regards,
> > Oscar
> >
> > --
> > Oscar Carballal Prego - Senior Software Developerhttp://oscarcp.com |
> @pizte
> >
> > On 11 June 2015 at 10:34, zhiwei <zhiweik@gmail.com> wrote:
> >>
> >> Hi all,
> >>
> >> In my understanding, Falcon is a framework that used to write a WSGI
> >> app(REST app).
> >>
> >> This WSGI app need a WSGI server to serve.
> >>
> >> Am I right?
> >>
> >> And I want to run Falcon app with multiple workers, does anyone know
> >> how to implement this?
> >>
> >> I saw there are multiple WSGI servers here:
> >> http://wsgi.readthedocs.org/en/latest/servers.html
> >>
> >> Could you tell me which one is better to run multiple workers and light
> >> weight?
> >>
> >> I found werkzeug is easy to implement this, but I also found werkzeug
> >> has the same features with Falcon, so I was confused.
> >>
> >>
> >> Thanks.
> >
> >
>

Re: [falcon] A question about Falcon and WSGI server

From:
zhiwei
Date:
2015-06-11 @ 10:03
Hi Oscar,

I see.

In my case, I don't want to use another frontend web server.

Do you know OpenStack? It's services do not use external web server.


Thanks.

On Thu, Jun 11, 2015 at 6:00 PM, Oscar Carballal
<oscar.carballal@gmail.com> wrote:
> Hi Zhiwei,
>
> Yes, you probably cna run it from a script. I usually don't take that
> approach because I want to keep it as a service that I can monitor and
> restart in case something happens.
>
> The SSL layer doesn't depend on uWSGI. That will be handled by your front
> server (Apache, Nginx, lighthttpd or any other) and you can also do some
> customization on your falcon app. My application runs on SSL all the time
> (nginx configuration plus falcon HTTPS middleware) so you will probably find
> my code handy to get an example :)
>
>
> Regards,
> Oscar
>
> --
> Oscar Carballal Prego - Senior Software Developer
> http://oscarcp.com | @pizte
>
> On 11 June 2015 at 10:56, zhiwei <zhiweik@gmail.com> wrote:
>>
>> Hi Oscar,
>>
>> Thank your for your reply. It's very helpful.
>>
>> Could I use uwsgi in python scripts? Just like below:
>>
>> app = falcon.API()
>> uwsgi.run(app, host, port, workers)
>>
>> And I also need to use SSL in the app, does uwsgi support SSL?
>>
>> Thanks.
>>
>>
>> On Thu, Jun 11, 2015 at 5:46 PM, Oscar Carballal
>> <oscar.carballal@gmail.com> wrote:
>> > Hi Zhiwei,
>> >
>> > In my case I always use uWSGI as the WSGI interpreter, it's fairly
>> > straightforward to implement (you can install it via pip) and the
>> > configurations are easy as well.
>> >
>> > To run an application with uWSGI you can do something like this (this is
>> > for
>> > testing, for production you should customize it)
>> >
>> > uwsgi --http :8080 --wsgi-file app.py --callable api
>> >
>> > This will open your application on the port 8080 on localhost. the
>> > app.py
>> > file is the file where you have the falcon.API() statement and the
>> > callable
>> > is the variable name for that statement
>> >
>> > It's a bit of self advertising, but you can take a look here to how I do
>> > it:
>> > https://github.com/clione/sikre
>> >
>> > Regards,
>> > Oscar
>> >
>> > --
>> > Oscar Carballal Prego - Senior Software Developerhttp://oscarcp.com |
>> > @pizte
>> >
>> > On 11 June 2015 at 10:34, zhiwei <zhiweik@gmail.com> wrote:
>> >>
>> >> Hi all,
>> >>
>> >> In my understanding, Falcon is a framework that used to write a WSGI
>> >> app(REST app).
>> >>
>> >> This WSGI app need a WSGI server to serve.
>> >>
>> >> Am I right?
>> >>
>> >> And I want to run Falcon app with multiple workers, does anyone know
>> >> how to implement this?
>> >>
>> >> I saw there are multiple WSGI servers here:
>> >> http://wsgi.readthedocs.org/en/latest/servers.html
>> >>
>> >> Could you tell me which one is better to run multiple workers and light
>> >> weight?
>> >>
>> >> I found werkzeug is easy to implement this, but I also found werkzeug
>> >> has the same features with Falcon, so I was confused.
>> >>
>> >>
>> >> Thanks.
>> >
>> >
>
>

Re: [falcon] A question about Falcon and WSGI server

From:
Kurt Griffiths
Date:
2015-06-11 @ 23:21
Hi Zhiwei,

The easiest way to scale a WSGI app to multiple worker threads, greenlets,
and/or processes is to use a standalone server designed for production 
use, such as HTTPD (mod_wsgi), uWSGI, Gunicorn, or Twisted 
(twisted.web.wsgi). Since instances of falcon.API() are regular WSGI 
callables AKA applications, Falcon works great with any of these servers.

Some OpenStack projects favor a self-hosting model, while others do not. 
For example, Keystone is typically hosted with HTTPD. I don't mind 
self-hosting while developing locally, but I actually prefer standalone 
web servers for production, since they tend to have better tooling, 
performance, and worker management options.

That being said, the following are some ways to self-host with multiple 
workers. They all support SSL termination, although you might get better 
performance by terminating at the load balancer or local reverse proxy 
(e.g., F5, HAProxy, Nginx, HTTPD). 

* Gunicorn - http://gunicorn-docs.readthedocs.org/en/19.3/custom.html
* gevent - http://gevent.org/servers.html
* Twisted - https://twistedmatrix.com/trac/wiki/TwistedWeb

For Twisted, you can self-host an instance of WSGIResource like so:

https://gist.github.com/kgriffs/4cca88ed635483930d21

Hope that helps!

-Kurt


On 6/11/15, 5:03 AM, "falcon@librelist.com on behalf of zhiwei" 
<falcon@librelist.com on behalf of zhiweik@gmail.com> wrote:

>Hi Oscar,
>
>I see.
>
>In my case, I don't want to use another frontend web server.
>
>Do you know OpenStack? It's services do not use external web server.
>
>
>Thanks.