I'm currently trying to optimize my website, which is run on the Google App Engine. It's not an easy task, because I'm not using any powerful tool.
Does anyone have experience in optimizing Python code for this purpose? Have you find a good Python profiler?
The python site listed 3 profilers to choose from: http://docs.python.org/library/profile.html
App Engine Mini Profiler is a new, drop-in app engine performance tool that gives both API call perf information (via Appstats) and standard profiling data for all function calls (via cProfiler)
https://github.com/kamens/gae_mini_profiler
For profiling the API calls, Guido van Rossum released a library called Appstats that will record and display a lot of good stuff about your app.
You can get the library here: https://sites.google.com/site/appengineappstats/
I wrote an article about it on my blog (with some screenshots): http://blog.dantup.com/2010/01/profiling-google-app-engine-with-appstats
Appstats http://blog.dantup.com/pi/appstats_4_thumb.png
I have found Gprof2Dot extremely useful. The output of the profiling modules I've tried as pretty unintuitive to interpret.
Gprof2Dot turns the cProfile output into a pretty looking graph, with the slowest chain(?) highlighted, and a bit of information on each function (function name, percentage of time spend on this function, and number of calls).
An example graph (1429x1896px)
I've not done much with the App Engine, but when profiling non-webapp scripts, I tend to profile the script that runs all the unittests, which may not be very accurate to real-world situations
One (better?) method would be to have a script that does a fake WSGI request, then profile that.
WSGI is really simple protocol, it's basically a function that takes two arguments, one with request info and the second with a callback function (which is used for setting headers, among other things). Perhaps something like the following (which is possible-working pseudo code)...
Actually, the App Engine documentation explains a better way of profiling your application:
From http://code.google.com/appengine/kb/commontasks.html#profiling: