On Mon, Dec 17, 2012 at 7:34 PM, Szabo, Patrick (LNG-VIE) <
patrick.sz...@lexisnexis.at> wrote:

> Hi,
>
> I have an operation that takes about 10 minutes to befinished. It takes
> that long because our DB is pretty big.
> This produces a timeout.
>
> I have tried so set the timeout in apache higher but it seems that apache
> is not taking this directive....just keeps timing out after 300 seconds.
>
> Is there anything I can to to overcome this within my app ?
>
> Yes. Stop doing long lived operations in a web request.

Seriously, stop. :-)

HTTP is designed to be a large number of short lived operations, not long
lived operations. At the moment, you're hitting a resource limit at the
HTTP server, but I'd be deeply surprised if that's the only problem you
hit. HTTP just isn't designed to work in the way you've described.

If you need to perform a long lived operation, you need to structure your
workflow differently. Instead of a single request that takes 10 minutes to
create a response, you:

 1) Issue a request that creates a record in the database with all the
details necessary to start the "job"
 2) Return to the user a success message that indicates work has started.
 3) In the background, in a *completely separate process*, process the job.
 4) When the job is finished, insert the results into the database, and
mark the job as finished
 5) If the user hits the page representing the job, they can view the
results.

The important detail here is that you get the heavy lifting *out* of the
request-response cycle. How you achieve that is up to you. On the very
simple end, you just have a job status page that the user manually reloads,
and a cron task in the background to do the heavy lifting. On the complex
end, you could use long polling or web sockets to provide the status
update, and something like Celery to handle the task management.

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to