[Twisted-Python] Memory leak//problem in twisted write procedures
josh at chatgris.com
Thu Sep 16 20:03:38 EDT 2004
I believe I have identified a memory problem in twisted.
A quick background..
I've been developing a program that has to use mssql for reasons beyond my control.
Due to the chaotic nature of mssql tds implementations, I created a program to pipe queries through to a windows box.
In the beginning, I was using asyn* for my communications, however asyn* was very inefficient when writing large amounts of data as after each write the
string would be spliced to remove the data written.
I then moved to twisted to use it's far more efficient buffer implementation, and the performance problems went away.
However, I have since been hit with an apparent memory leak. After reading through the twisted source (specifically the write routines in twisted/internet/abstract.py)
I believe I have come across the problem.
the write implementation continually increases it's write databuffer, only freeing up memory when the data buffer is all sent
However, successive write operations append data to the data buffer.. So if a program is able to keep the data buffer from ever completely emptying (which mine is)
then the data buffer will forever grow, resulting in a memory problem.
I have added some output to print out the length of the data buffer and the offset, and after only 10 minutes of running the numbers are already
offset == 76906496
dataBuffer len == 120768384
Now, reading through the source to fix this problem, the fastest solution (requiring the least change to the existing code) would be to splice//reduce the size of the
dataBuffer after offset exceeds a certain number.
However, I'm not too intimate with the source.. I will try that above solution to see if it does any good.. otherwise, i think that this is a fairly serious bug that should be addressed
by someone more intimate with the source.
Thanks, Joshua Moore-Oliva
More information about the Twisted-Python