Hello,
In our company we make news portals for a pretty big number of local
newspapers (currently 13, going to 30 next month and more in the
future), each with 2k to 100k page views/day. Since we are evolving
from a situation where each site was heavily customized to one where
each difference is a matter of configuration or custom template, our
software is already pretty much the same for all sites. Right now our
deployment strategy is one gunicorn instance for each site (with 1-17
workers each, depending on the site traffic), on a 16-core server and
12GB RAM. The problem with this setup is that each worker (regular pre-
forked gunicorn) takes 110MB, whether its being used or not. Now with
the new sites we would need to add more RAM to serve not that much
many requests, so basically it doesn't scale. Also, since we are
moving from this model where each site is independent, each site has
its own database and I quite like it that way, especially since we are
using relational databases (mysql, but migrating to pgsql), so its
much easier to shard this way.

I'm doing some research and experimenting with running all sites on
one gunicorn instance, so I could use the servers fully and add more
servers behind a load balancer when it came to it. The problem is that
django assumes in a lot of places that only one site is running per
process, so for what I've thought of so far I'd have to implement:
- A middleware that takes the HTTP_HOST from the request and places an
identifier on a threadlocal variable.
- A template loader that used that variable to load custom templates
accordingly.
- Monkey patch django.db.model.Model, probably adding a metaclass (not
even sure that's possible, but I think I would need it because of the
custom managers we sometimes need to use) that would overwrite the
managers for one that would first call db_manager(identifier) on the
original manager and then call the intended method. I would also need
to overwrite the save and delete methods to always include the
using=identifier parameter.
- I guess I would need to stop using inclusion_tag decorators, not a
big problem, but I need to think of other cases like this.
- Heavy and ugly patching of urlresolvers if I need custom or extra
urls for each site. I don't need them now, but probably will at some
point.

And this is just is what I came up with without even implementing it
and seeing where it breaks, I'm sure I'd need many more changes for it
to work. So I really don't want to do it, especially with the extra
maintenance effort I'll need, but I don't see any alternatives and
would love to learn that someone already solved this in a better way.
Of course I could also stop using django altogether (I already have
many reasons to do so) but that would mean a major rewrite and having
two maintain two incompatible branches of the software until the new
one reached feature parity with the django version, so to me it seems
even worse than all the ugly hacks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to