[Twisted-Python] profiling live twisted application
Maarten ter Huurne
maarten at treewalker.org
Thu Nov 8 18:40:04 EST 2007
On Thursday 08 November 2007, Alec Matusis wrote:
> What is the best non-intrusive way to profile a live twisted application?
I'm not sure it's possible to do profiling in a non-intrusive way: the more
detailed measurements you want to take, the more you're going to slow down
execution. I hear quantum mechanics has similar problems ;)
> We have TCP servers with epoll reactors.
> We want to optimize them as our usage grows.
What I did for our web app is add an option to log the time it took to
handle each page fetch. By looking at the log, you can spot pages that are
always slow, pages which are slow for certain inputs and pages which vary
There are several profilers available for Python, but their overhead is
probably too much to use in a live environment. Maybe you can duplicate the
data sets and requests from the live environment in a test environment
though and profile your server there.
Here is some example code:
from time import time
from hotshot import Profile
start = time()
profile = Profile('request.prof')
end = time()
print 'Responding took %1.3f seconds' % (end - start)
HotShot profile results are binary files, read the Python library
documentation to learn how you can create human readable output from them.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20071109/ead574a0/attachment.pgp
More information about the Twisted-Python