B
B
Bjornie2018-07-09 14:07:15
Django
Bjornie, 2018-07-09 14:07:15

Why is the view waiting for a long time before giving a file for download?

There is a view that produces excel with a graph. The only problem that has always been present: a long wait for an offer to download the generated file.
Today the request started to go to 504, so I made a simple measurement using time. From the request to the return response itself , only 14 seconds pass. After that, you have to wait the same amount for the browser to give the file.
After searching for similar topics on SOF, it turned out that you can solve the problem by increasing the time-out value in the Apache configuration.
However, the main question remains: why is there such a long wait BEFORE uploading the file (queries to the database, graph generation, etc. are fast). And how can it be accelerated?
Here's a code example:

response = HttpResponse(content_type='application/vnd.ms-excel')
response['Content-Disposition'] = 'attachment; filename=%s.xlsx' % date.today()
response.write(output.getvalue())
end = time.clock()
print(10, "%.2gs" % (end-start)) # 14 секунд с запроса -- ОК
return response # после чего долгое ожидание, с сегодняшнего дня приводящее к ошибке 504.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
neol, 2018-07-09
@neol

If possible, the best option is to write the output to a file on disk and serve it to nginx using the X-Accel-Redirect header, IMHO. So apache will not be involved in the file transfer process at all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question