1

I am developing Django app, which will be used by 100 of users to post comments. For each comment I can't do Model.save() which commits database and not scalable. I want to commit database periodically using celery. Is there any way to do this?

I checked transaction management in django, but I didn't get any pointers. Please help me.

I want to commit manually after saving many models and this should be restricted only for few models. For user creation, I want to save and commit immediately. Only for posts I want to commit periodically.

ram edara
  • 11
  • 1
  • 1
    I would disagree that saving each comment is not scalable. Disqus.com uses django and (as of last year) handled 170 million comments (peaking at 25,000 requests per second) from 500 million users. There is some good info about django's scalability [here](http://stackoverflow.com/questions/886221/does-django-scale). – dgel Aug 19 '12 at 10:34

1 Answers1

4

Your requirements are nonsense. To start with, saving and committing are two different things - model instances can be (and are) saved to the database individually, while committing is to do with transactions and can involve one or multiple db rows. Calling save() doesn't itself do a commit - by default, a transaction is based on a request/response cycle, where the transaction is opened at the start of the request and committed at the end of the response.

Secondly, it's completely impossible for a separate process to take care of committing. The whole point of transaction management is that what's inside a transaction is only visible to the connection dealing with the transaction itself. Outside of that transaction, it's as if the db hasn't changed at all.

As for scalability, see dgel's comments. There's no need to outsource your committing to a separate process, especially if you're only dealing with "hundreds" of users. That's a tiny amount that any database will be able to manage with no effort at all.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895