[Twisted-Python] Twisted Memory Leaks & Epoll

Alec Matusis matusis at matusis.com
Tue May 1 23:40:08 EDT 2007


Our empirical experience with leaks is the following:
Python 2.4 never releases memory, but you can get very good results with
Twisted 2.2 when the servers are at high-load all the time. We have servers
that run at 70%+ CPU for more than a month without restarting.
When a server starts, it exhibits a memory increase from say 60MB in the
first hour to 70MB after the first 24 hours. The memory increase slows down,
asymptotically approaching some fixed value (which is possibly set by the
highest usage). Then it can run literally for months, never exceeding 80MB.

When there's a memory leak due to bad code, the best thing to do is to set
up a manhole, and inspect all objects. 
Also, manually decrementing reference counts like so:

def stat_collect():
    gc.collect()
    twisted.internet.reactor.callLater(config.gc_collect_interval,
stat_collect)

stat_collect()

helped us in one case.

With Twisted 2.5, we saw memory leaks for poll reactor for the same code
that was non-leaking on 2.2. 



> -----Original Message-----
> From: twisted-python-bounces at twistedmatrix.com [mailto:twisted-python-
> bounces at twistedmatrix.com] On Behalf Of Matthew Glubb
> Sent: Tuesday, May 01, 2007 6:07 AM
> To: Twisted general discussion
> Subject: [Twisted-Python] Twisted Memory Leaks & Epoll
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Dear All,
> 
> I have been benchmarking my twistd application (twisted.web.server)
> and I am seeing increasing memory usage that is never freed. Before I
> delve into GC and valgrind, I am interested in learning whether there
> are any fundamental no-nos under twisted that might result in a leak.
> I am relatively new to twisted and its entirely possible that I am
> doing something wrong.
> 
> I am also interested in learning what the stability of the epoll
> reactor is. I have come across a few (old) posts that pointed to it
> being incomplete. Would the epoll reactor be a possible cause of a
> memory leak? Leak aside, I have benchmarked my app up to 5000
> simultaneous connections with no obvious drop in performance.
> Switching to poll produces *terrible* results.
> 
> For the purposes of diagnosing the cause of the leak (C extension,
> python, twisted, or my code) I have removed external library
> dependencies and I have also swapped out reactors. The leak persists.
> 
> Does anyone have any good tips for diagnosing leaks under twisted?
> For what its worth, I am conducting my tests under an AMD 64bit
> architecture.
> 
> Regards,
> 
> 
> Matt
> 
> 
> m a t t h e w   g l u b b
> 
> _______________________________________________________________________
> _
> Z Group PLC
> 
> Tel: +44 (0) 8700 111 173
> Fax: +44 (0) 8707 051 393
> Txt: +44 (0) 7800 140 877
> Web: <http://www.zgroupplc.com/>
> 
> This  email  and  any  files  transmitted  with it are  confidential
> and
> intended solely for the use of the individual or entity to whom they
> are
> addressed.  The opinions  expressed in this mail are those of the
> author
> and do not necessarily  represent the views of the company.  If you
> have
> received this email in error please notify <service at zgroupplc.com>
> 
> 
> 
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.1 (Darwin)
> 
> iD8DBQFGNztmyI6MkdKPngkRAnW5AJ9D8Lx2BN3Ds8BL33TL1TS1QnK1pgCgk2X5
> 2HVOxP93ZJCWWLQ7Tver3wE=
> =1nnG
> -----END PGP SIGNATURE-----
> 
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python





More information about the Twisted-Python mailing list