Archive for January 21st, 2008

Multi-Process TurboGears deployments

Cliff Wells wrote a blog posting a while back about load balancing a TG 1 app using nginx. This deployment senario has worked out really well for me.

Apache is everywhere, but nginx is much less memo2ry and CPU intensiveparticularly under very high loads.
I think both Mod-WSGI and nginx deployment scenarios are both vitally important to the future of TurboGears (for different reasons) and we ought to have good recipes for both on the TurboGears Docs wiki, but that’s a blog post for another day.

There was a bit of confusing FUD about TurboGears out there on the mailing lists last week. The author of this FUD once again seems to have gotten confused, and was telling people that TurboGears multi-threaded deployment model was inherently limiting as opposed to a single-threaded multi-process server model.

Here’s my basic response: Just because you can have more than one thread per process doesn’t mean you can’t also have more than one process.. And that’s exactly what high-volume turbogears sites do they run multiple instances behind a load-balancing proxy server.

In general threads are hard to to get right, but in the context of a web server with a thread-per-request model, things aren’t actually that hard. And threads are nice because they don’t block the whole process during network or database IO, and they take up a lot less memory than a new process. So, if you have 50 processes with 20 threads each you can handle 1000 concurrent requests with a lot less memory than if you ran a separate process for each of those 1000 requests.

As for how many processes to use on your production server, that all depends on your app, but I have noticed a pattern in several in several different load tests on several different TurboGears apps, written by several different clients. In general about 4 processes per CPU seems to be the sweet spot.

But the nice thing is that the CherryPy web server is fast enough that a lot of sites just don’t need to run multiple processes to handle their traffic.

TurboGears 2 tutorial at Pycon

PyCon Registration is now open, and I’d like to take this oportunity to mention that
Ben Bangert and I will be doing a set of joint Pylons/TurboGears 2 tutorials at Pycon this year.

Classroom

The tutorial materials have been designed not just to help people use these web application stacks, but to understand how they work, and what happens “under the hood” so to speak.

We’ll be covering everything from WSGI to automatic CRUD tools, and will introduce you to all kinds of new stuff. Pylons and TurboGears are designed to scale down to very simple application’s, and up to the point where you can easily have multiple databases, application servers, and huge numbers of daily page views.

And, of course we’ll give you the low down on how the two frameworks are the same (they share huge swatch of code) and how they are different. It should be a rip-roaring good time.