3 ms·
I've been building a web backend for an iPhone app with it in the past two months. It's ideal for serving simple JSON requests that depend on other I/O stuff (l
by bitanarch 16y ago
I've been building a web backend for an iPhone app with it in the past two months. It's ideal for serving simple JSON requests that depend on other I/O stuff (like, contacting Facebook) - but it's got plenty of problems:
1. The callback architecture. I simply freakin' hate the IOLoop. If you have just one asynchronous I/O operation, it's nice and easy. If you have one that depends on another, you have to wrap and curry a callback inside another one. Three? More wrapping and currying. I understand it's pretty much the same in many other platforms like client side AJAX these days. But man, this is Python and we DO have far better alternatives like gevent! You want the epoll() and kqueue() for performance? Fine. But it's Python and you can do it with coroutines without all that asynchronous event handling mess. And minus all those function wrapping and curry, I'm sure it can be much faster, all the while being easier to program with.
2. The Facebook API in auth.py sucks. Just read its source code - it performs all requests by GET - WTF?! It can't even upload files unless you hack it (I've got a branch at http://github.com/martinkou/tornado-upload http://github.com/martinkou/tornado-upload for that). And look at that _signature function under the FacebookMixin class - it doesn't even use session secrets? I'm not sure if I'm doing anything wrong, and Facebook API's docs don't mention that.. but in my testing, if I just use the application secret key all the way for the signature, Facebook gives me 104 errors. I had to hack it again to make it use session secrets in signing requests.
I don't really care about databases. But last time I checked, psycopg2 has a page telling you how to do async requests with gevent or libevent style coroutines. Tornado? Good luck integrating that with IOLoop and currying your callbacks. Sure you can still make it work, but it's unnecessarily complicated.
- bitanarch 16y agobtw, it's possible to run Tornado on $NUM_CPU forked processes, have them listen to one port and so you wouldn't need nginx load balancing. Just read httpserver.py and you'll find a fork() there. The downside? Assuming you're still running your Tornado in your console and haven't daemonized it somehow - you press Ctrl-C, it exits (the console part, I mean) - and the $NUM_CPU children are still running. It's still not fixed today, and that doesn't really speak of quality.
- gxti 16y agotxpostgres implements psycopg's async interface for Twisted, which uses a similar eventloop/callback model: http://git.wulczer.org/?p=txpostgres.git http://git.wulczer.org/?p=txpostgres.git Not that "unnecessarily complicated", but Twisted is a lot more mature with respect to coding patterns and has formalized callbacks into a Deferred object that makes it much easier to understand.