fapws3 + web.py
Objective: run a web.py application with the fapws3 web server
If you are looking into fast and easy ways to run your web.py-based application, there are many exciting alternatives out there claiming to be both easier to install (easy) and faster (not so easy) than Apache+mod_wsgi. A benchmark of Python web servers summarizes all good candidates today. I decided to give them all a quick try and see what they have to offer. First in line: fapws3
Here is my HelloWorld web.py:
---hello.py--- import web class hello: def GET(self): return 'Hello world' urls = ('/', 'hello') application = web.application(urls, globals(), True).wsgifunc()
and here is the glu to run it from fapws3:
---run.py--- import hello from fapws import base import fapws._evwsgi as evwsgi if __name__=="__main__": evwsgi.start('0.0.0.0', '8080') evwsgi.set_base_module(base) evwsgi.wsgi_cb(('', hello.application)) evwsgi.run()
Start the server with python run.py and point your browser to http://localhost:8080 to see it run. Ok, now let us modify a bit our web app: say I have a URL that requires longer computation times. This is simulated here with time.sleep:
import web, time class immediate: def GET(self): return 'immediate' class delayed: def GET(self): time.sleep(10) return 'delayed' urls = ('/immediate', 'immediate', '/delayed', 'delayed') application = web.application(urls, globals(), True).wsgifunc()
Open two tabs in your browsers, point the first to /immediate and the second one to /delayed. Now reload both… and wait 10 seconds to see /immediate get refreshed. Ouch. One long-running request blocks the whole server.
- fapws3 is not threaded and never will be, according to the FAQ
- fapws3 does not support SSL
No support for multi-threading means that you will have to implement your own manager/worker mechanism for long-running requests. The fapws3 FAQ recommends using many parallel instances and pound for load-balancing and SSL support. WTF?
Now I am left wondering: what could fapws3 possibly be useful for? There are so many more WSGI-compatible web servers with excellent performances, a full thread stack and complete SSL support out of the box, why should I bother with one that lets me do all the work? I probably missed something. Oh well…