Reputation: 851
I have a simple django page that has a counter on it. I use Apache2 with mod_wsgi to serve it.
First, when I enter this page, the counter shows 0, as it should. The second time when I enter the page the counter shows 1 - again, it is the right behavior. The problem begins now, cause when I enter this page the third time, I get 0 again.
When I refresh it goes between 0, and 1, clearly using some cache or so. If I wait for some time and then try again, it will show 2, and 3, but will be stuck with those values, till this cache or whatever it is will be flushed, and then the counter continues.
Does somebody knows how I can get it work right (the real scenario deals with getting data from the DB, but the problems with this strange cache are the same).
BTW, I don't have any caching engine set in my django settings.
Upvotes: 1
Views: 173
Reputation: 58523
Number of instances != processes * threads as suggested by other poster. Number of instances == processes only.
Read:
http://code.google.com/p/modwsgi/wiki/ProcessesAndThreading
Likely you are running embedded mode. You should instead use daemon mode.
Don't set 'processes=1' though as that is the default anyway and using the option has other side effects you may not want.
The default number of threads for daemon mode is 15 which is fine so long as your application is thread safe. Specifically, access to your global counter should be thread safe.
Also read:
http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide
which has an example of how to set up daemon mode. You need to use both WSGIDaemonProcess and WSGIProcessGroup directives, having just WSGIDaemonProcess is not enough.
Upvotes: 3
Reputation: 5136
You are running multiple instances of your Django. Apache connects randomly to one of them.
For testing purposes, try this in your apache.conf:
WSGIDaemonProcess mysite processes=1 maximum-requests=500 threads=1
(You may want more processes in production use.)
See full documentation of options.
Upvotes: 1