Reputation: 19450
I have an Apache2 + mod_python setup which has begun responding impossibly slow since some days - two seconds of processor time for any request of my app. Some interesting points:
Any idea of where can I look?
Upvotes: 3
Views: 5504
Reputation: 955
Profiling the app is a good start point (https://code.djangoproject.com/wiki/ProfilingDjango).
Before looking into the profile statistics, make sure you know what's the request/response cycle of django (or whatever framework you are using).
Most of the cases, things got messed up in the view, for other cases, it might be in middleware layers. Watch for which layer you are profiling, functional wise or everything involved in the request/response.
Other tricks like compare performance between dev/prod mode might be useful too. Try use django development server to make sure apache/mod_python is not the culprit.
Upvotes: 0
Reputation: 40679
Suppose it had an infinite loop. How would you find it?
I imagine you would just pause it in the debugger and look at the code at the various levels of the stack, because you know the loop is somewhere on the stack. Right?
Suppose the loop isn't infinite, merely taking a long time. Is that much different?
No matter what the problem is, if it is costing you some percent of time, like 90%, or 50%, or 20%, that's the probability you will catch it in the act when you pause it. So if you pause it several times, you're going to see it. The worse it is, the fewer times you have to pause it and look. It will be obvious.
So forget about timing. Just find out what it's doing.
In response to question, here is some mod_python doc:
5.4.1 PythonEnablePdb Syntax:
PythonEnablePdb {On, Off}
Default: PythonEnablePdb Off
Context: server config, virtual host, directory, htaccess Override: not None Module: mod python.c When On, mod python will execute the handler functions within the Python debugger pdb using the pdb.runcall() function. Because pdb is an interactive tool, start httpd from the command line with the -DONE PROCESS option when using this directive. As soon as your handler code is entered, you will see a Pdb prompt allowing you to step through the code and examine variables.5.4.2 PythonDebug Syntax:
PythonDebug {On, Off} Default: PythonDebug Off Context: server config, virtual host, directory, htaccess Override: not None Module: mod python.c Normally, the traceback output resulting from uncaught Python errors is sent to the error log. With PythonDebug On directive specified, the output will be sent to the client (as well as the log), except when the error is IOError while writing, in which case it will go to the error log. This directive is very useful during the development process. It is recommended that you do not use it production environment as it may reveal to the client unintended, possibly sensitive security information.
Upvotes: 1