mysql - Django querysets in a distributed application -
i have 4 ec2 servers running django 1.3.2 application uwsgi. share mysql server on amazon rds. i'm experiencing behavior if new objects created through admin , try:
get_object_or_404(class, pk=new_object.pk) sometimes find object, other times return 404.
what going on?
this how i'm using get_object_or_404:
# module level variables if settings.debug: articles = news.objects.filter(status='live') else: articles = news.objects.all() dev view(request, slug): article = get_object_or_404(articles, slug=slug) .... if restart uwsgi processes, problem goes away.
questions , things i've tried:
- are module level variables problem? i've tried debug since querysets lazy doesn't seem problem.
- is cache issue? i've restarted memcache , cleared nginx's cache issue remains.
- is rds issue? haven't found answer this.
- is queryset cache issue? haven't found answer this, , don't know how.
everything works expected on single server, have multiple servers, start experience behavior.
module level variables problem - querysets "lazy" long not used (iteration, evalution, whatever), start retrieving records populate cache (hint: django open-source, can readthecode(tm) when doc not enough).
you might have troubles transaction isolation level if use innodb tables (cf django's doc on last point).
Comments
Post a Comment