Tips and info for Debugging Akara

Sniffing HTTP headers

A quick&dirty way to sniff, e.g. headers sent by HTTP clients or servers is to create an echoing socket:

from socket import *
s = socket(AF_INET,SOCK_STREAM)
s.bind(("",6000))

def echo():
    s.listen(5)
    c,a = s.accept()
    data = c.recv(16384)
    return data

print echo()

Then you can go to another session or machine and direct your query to that machine on port 6000

Memory leaks

If you seem to have a runaway Akara server with regard to memory consumption, the possibilities are:

A. Akara has a memory leak, either in core libraries (Amara) or in the server framework.

B. There is no memory leak, but in your application you've created a resource allocation loop that outruns Python's ability to reclaim unused memory. To eliminate this possibility, add strategic calls to gc.collect(), tracking how many objects were reclaimed each time. See how that affects the memory profile. If the leak goes away, eliminate as many gc.collect calls as you can without restoring the leak (because those calls are quite expensive).

C. Your application, not Akara itself, has a leak. Of course, debugging depends on your particular code. Use the introspection capabilities of the gc module to get a very high level picture of your object allocation profile, and try to improve the resolution until you can narrow down to the offending code. You may need to get familiar with the weakref module.

Recycling processes

Akara does provide a tool tat can be used to work around memory leaks. You can restrict the number of requests a worker process makes before it is destroyed, forcibly reclaiming its memory. Set the MaxRequestsPerServer config var to something like 50. It's 10000 by default.

Useful resources:

Akara/Debugging (last edited 2009-12-10 18:50:19 by UcheOgbuji)