On Thu, Apr 22, 2010 at 7:00 PM, Tim Arnold <[email protected]> wrote: > On Apr 22, 1:22 pm, Andy McKay <[email protected]> wrote: >> On 2010-04-22, at 9:52 AM, Tim Arnold wrote: >> >> > hi, >> > Until now I've been working on a single Freebsd server, hosting a >> > couple of Django apps. Now we've bought another machine to provide >> > load balancing and I'm wondering how to accomplish that. >> > I guess the django code can be shared on the same drive, but the >> > django instances running separately of course (apache/mod_python). >> >> > Is it possible to have two instances accessing the same database? How >> > do you handle load-balancing? >> >> Yes you can. There's lots of options,http://www.apsis.ch/pound/is but one. >> -- >> Andy McKay, @andymckay >> Django Consulting, Training and Support >> > > I just googled that which led to some interesting pages and notes, > thanks. > So, just to make sure I understand: > > browser -> pound --> apache1(mysqldb) +django > --> apache2(mysqldb) +django > > and it will just work? One database, two django instances and they > won't clobber each other on db write? > I guess the writes will block, correct? >
If you just want to run two instances of django against the same database, then just do so. How you hook it into your hosting mechanism depends on what mechanism you are using. Typically there would be no need for multiple apache instances or a load balancer in front. I'm not sure I understand your last statement '..they wont clobber each other on db write'. If you edit the same object at the same time on multiple django instances, it is the same as if you edited the same object at the same time on a single django instance. Django does no locking - apart from atomicity of objects - to ensure that the earlier saved object does not get updated. I just re-read that, and even I don't understand it so heres an example: User A loads a page with a form to edit object instance O User B loads a page with a form to edit object instance O User A changes O.active from True to False and saves the form User B changes O.name from '' to 'Bob' and saves the form Note that I haven't mentioned what instance of django they are running on - it is irrelevant In this scenario, after B has saved the form, O.active is True, and O.name is 'Bob'. B does not get any warning that the object instance he is editing has changed out from underneath him. If you require that sort of behaviour, you need to track the revision of the object, and implement it when anything on the model changes - that's behind the scope of this discussion ;) Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

