How do I debug mod_wsgi/django/apache/wget timeout - django

I have a web service running through django/apache/mod_wsgi that I am trying to debug -- it takes a long time to run server-side, but with certain parameters it just times out. I've tried doing a straight up wget on the URI, and using urllib2. I get the following error from wget:
Read error (Connection timed out) in headers
Meanwhile, urllib2 returns nothing at all -- it seems to be erroring silently. I've tried increasing the Timeout directive in my apache config, but that doesn't seem to help. The service runs fine with different parameters. How should I debug this? Where is the timeout coming from if not apache?

Chances are the problem is in you services code. Make sure your services code completes executing and returns to apache before trying to debug apache.
I would suggest that you trace through the services code adding output statements. Be sure to add a ouput statement just before your code returns to mod_wsgi (the last line of the function that mod_wsgi calls.) Chances are what you will see is the code hanging in a particular spot. That is all the debug statements prior to that spot in the code will appear, none of the output statements after that spot will appear.
If you don't want to add debug statement try using a debugger to step through the code.
Another option is to use the django development server and see if the timeout occurs when running without apache. However, since the development server is single threaded your code won't hang if the problem your dealing with is a concurrency related bug.

Related

Does django project has time delay if i modify some codes?

I was wondering that i always got the wrong message when i corrected my code, but not for long, it would return the right result of my program. Is that normal?
Sounds like you are not restarting the built-in django development server manually after making the changes:
The development server automatically reloads Python code for each
request, as needed. You don’t need to restart the server for code
changes to take effect. However, some actions like adding files don’t
trigger a restart, so you’ll have to restart the server in these
cases.
As documentation says, sometimes in order to see the changes, you need to restart the server manually.
Also, sometimes Django dev server reloader doesn't see the changes right away and it takes some time for the server to notice changes and trigger restart. If you see this often, restart the server manually.
Also note that in Django 1.7 kernel signals are used to autoreload the server on linux - this should make it pick up the changes and restart faster:
Changed in Django 1.7:
If you are using Linux and install pyinotify, kernel signals will be
used to autoreload the server (rather than polling file modification
timestamps each second). This offers better scaling to large projects,
reduction in response time to code modification, more robust change
detection, and battery usage reduction.

NACL Isn't Loading Modules?

I'm wanting to start developing with NaCl / Pepper and I've gotten my build environment working great, but I can't seem to use any of the examples in my browser.
I've enabled Native Client, debugging, etc. But none of the modules seem to trigger the 'loaded' event, so I have no idea what is going on. This goes for .pexe and .nexe
I have the git here, and I honestly have no idea if there's a problem with my build process, my browser configuration, or what. Has anybody got a clue what's going on here?
This is the closest I've gotten to an error message, and apparently this is a chrome runtime flag, but running chrome with this flag has no effect, and now instead of working, no messages are output.
Try disabling debugging. Enabling debugging means that the NaCl loader will start the Native Client module, and then immediately suspend it and wait for the debugger to connect (then you can resume it with the debugger). So if you don't connect a debugger it will just wait forever. Also if you want to use the debugger on Windows, you need to disable Chrome's sandbox to allow the local TCP connection (for the record, the error message that gets cut off in the screen shot links to the following chrome bug)

How to debug production setup for java?

I am currently working on a web-app. Basically deployed as .war file on production enviornment. The server is tomcat7.
Since the code is written in java. There are ocassional log statements on server side.
If I am given an issue to resolve, I do not have a duplicate data-set / subset of data , as like production. So the problem that I face, is replicating the scenario , in case of testing.
Since this is production enviornment, attaching a remote debugger , would mean that the functionality would halt/ when I am stepping through break points, So I am not able to debug remotely.
so, currently, the only visiblity I have with regards to the behavior of the system is, The code base, and the log statements in code.
How Do you suggest I debug the server side code without restarting the application.
Any insight in this matter would be appreciated.
Thank you.
As you cannot attach a remote debugger in production there is no other way to debug your code other than the logs and matching the line number in your code.
1) You could ask for the sample scenarios which caused the issue and try to reproduce it in your development environment with debugger attached.
2) You could fine tune the log level to DEBUG mode to catch more useful logs.
3) Check various logs like application log, server log, access log, etc
3) You could ask for the test data which has caused the issue and try the same in dev environment.
Ideally you need a mock production environment with minimum mock data so that you could attach your debugger and step into the code.
Otherwise it would be time consuming and impossible to reproduce the production issues.

Django Reloading on every request

I wanted to load some data and keep it in memory as in application scope. Basing on this and other posts in stackoverflow, I've put the required code snippet in settings.py, urls.py, models.py. I also put print statements to see when it gets executed. I see all the print statements in the server log with every request.
The following are the version details:
Linux 2.6.32-358.el6.x86_64
Apache/2.2.15 (Unix)
Django 1.4
Python 2.7.4
Looks like django is re-loading for every request. I also looked into this and confirmed with the admin that MaxRequestsPerChild is NOT 1.
If you are running in mod_wsgi embedded mode, you will have a multi process configuration, thus can take a while to warm up all processes with your code. Also, Apache will kill off idle processes and so you will see process churn. So what you may be seeing is the result of that.
Add to your debug code the printing out of the process ID to confirm this.
The easiest thing to do is use mod_wsgi daemon mode and restrict yourself to a small fixed number of persistent processes.
Also go watch my PyCon talk about this sort of stuff at:
http://lanyrd.com/2013/pycon/scdyzk/

How can I configure Apache2/mod_python/Django to abort request processing after N seconds?

I recently spent a long while debugging something that turned out to be an infinite loop bug in my own code. Since I can't guarantee I'll never make that sort of mistake again, how can I configure my web server to terminate any apache2 subprocess that remains waiting for my python app to return a response for over N seconds?
In this case, I didn't even notice the bug until the site started feeling slow, at which point one apache2 process had been running inside an infinite loop for hours. If there were a timeout (even a long one, like 10min) that could have caught this and emailed me, I'd have known about the problem sooner, and it wouldn't have impacted site performance for as many users.
Googling, I've found some suggestions of similar things in a mod_wsgi configuration, but if there's a way to do this under my current setup I'd prefer that. Thanks!
The short answer is no, there is no builtin ability within mod_python to have timeouts on individual requests.
Hmmm.
I wonder if you can use mod_cgi to run your Python script for development. And then go back to mod_python for deployment.
Then you can use the Apache core TimeOut directive to limit how long Apache waits for the mod_cgi response. N.B. Apache 2.2 that is, this extension to the TimeOut directive only came with the 2.2 release.
HTH