Hi,

When working with large projects, it is sometimes the case that you run into 
problems where some edge case causes a pathologically high number of queries 
for processing a specific request. These cases are hard to debug, because it is 
not always easy to reconstruct the edge-case and even identify the exact 
request (because post-data is not always available). Django collects all the 
queries on a connection if DEBUG=True, but when it's hard to reproduce, you 
sometimes need some sort of monitoring in production, where DEBUG=True is not 
really an option.

Something that could be very helpful is just to count the queries -- a counter 
cab be incremented with no noticeable overhead in CursorWrapper, and it can be 
reset and/or examined at request start/end points (even with a Middleware, as 
long as we have them). This would enable a project to define alerts or errors 
or whatever when there are two many database queries, at a level where enough 
information can be given to help solve the problem.

Similar measures may be applicable to other resources as well, if they are 
handled by thread-local objects like the database connections. I'm not sure 
which ones apply.

Thoughts?

Thanks,
        Shai.

Reply via email to