WebFaction
Community site: login faq

I am having some performance problems that leave me baffled. I am using Django with MySQL. I do the following:

1 Send data from a webpage using Ajax.

2 Receive the post data in Views.py and process it via many function calls, inserting data into MySQL. The very first thing that I do is set a Python variable timeStart. The very last thing that I do, before returning a response, is calculate the time to process the data: processTime = time.clock() - timeStart. I send a response using render-to-response where the response is processTime.

3 processTime is displayed on the webpage.

processTime comes to 1.5 seconds, but the complete time from sending the data via Ajax to receiving a response is 13 seconds. 11.5 seconds to render a simple page and to send and receive data - that's a long time. But then it gets weirder. I cut short the views.py function, almost immediately sending back a response. That cuts the processing time down from 1.5 seconds to almost 0. But it also cuts the total time down from 13 seconds to about 2 seconds. That would seem to indicate that it is, in fact, the data processing that is slow. However that does not explain how the calculated processTime only came to 1.5 seconds. I really do set startTime in the first line and calculate processTime in the last line. StartTime is not overwritten.

It's almost as though there is some kind of clean up process or something associated with finishing up and sending a response, something that is dependent on the function calls. But what? Or I am doing something stupid with my time calculation. I have set debug = False.

asked 16 Jul '12, 08:05

ttt
114
accept rate: 0%


If you profile your app, you'll see exactly where it is spending its time. Plenty of good advice here: Profiling Django

permanent link

answered 16 Jul '12, 08:43

seanf
12.2k41836
accept rate: 37%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×909
×26

question asked: 16 Jul '12, 08:05

question was seen: 2,283 times

last updated: 16 Jul '12, 08:43

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM