Hello,

I'm developing a site that need to display ads. The ad to display on a page is 
selected by a function based on the value of a global state - an application 
state that need to be maintained across requests and different users. In other 
words, the state is a "website singleton".

This state is read and changed on every request. One trivial way to achive this 
is to store the state in the database, but I'm afraid that changing the value 
in the database with every request might create a performance bottleneck (I'm 
using MySql, don't know if it matters).

I thought about having a global (plain python) variable to store the state. 
However, there are some points to think about, especially since I'm not sure 
how FastCGI works:
1. Is there single process that handles all the requests? (so it can keep state)
2. If so, are different requests handles by separate threads? If this is true, 
then I probably need to make this state variable thread-safe.
3. How long does the FastCGI process (or the relevant application process) 
lives? I don't mind reseting the state from time to time, but not too often.

The ad selection mechanism is somewhat probabilstic - ads should be displayed 
more or less randomly (with some uniform or weighted distribution), so another 
option I'm thinking of is using python's random() function to select an ad. 
That way I won't have to maintian state explicitly,  although a state would be 
maintained by python for the random number generator. This also raises some 
questions: again, to make this work well there need to be a single server 
process, the random number generator (or its state) need to be global.

I hope this is not too long, and clear enough. I would appreciate any ideas.

Thanks,

Amit Ramon



--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to