In my django app, I have one AJAX view that gets flooded with calls to an update method, which I'll call IncrementMagicNumber:
def IncrementMagicNumber(request) :
number = request.GET['increment']
request.session['magicnumber'] = request.session['magicnumber'] + int(number)
return HttpResponse("OK!")
This works fine for one update at a time, but when a client is calling SetMagicNumber several times in a row, things get messy. Let's say magicnumber is initially 0. The client sends out 3 successive AJAX requests to IncrementMagicNumber:
IncrementMagicNumber(2)
IncrementMagicNumber(5)
IncrementMagicNumber(4)
The client expects the value to be 11 now, but apache is processing all these requests concurrently, so only the final update gets retained. Any tips/tricks for synchronizing a Django session?
Things I'd like to avoid if at all possible:
- Client side batching (I realize this would fix it, but this is a backend problem and is best fixed there)
- Some sort of database locking; I'd rather avoid this approach if possible.