[Twisted-Python] How to cap the buffering size of data to be sent in Protocol class
![](https://secure.gravatar.com/avatar/cba23dc9be053c3fe2a262fac1ee139c.jpg?s=120&d=mm&r=g)
Folks, I have a server program which basically use a protocol.Protocol class to send a continuous byte stream to clients on TCP connections. However, I found , for whatever reason, if a client hung up and failed to remove the data from its receiving socket buffer, then the memory usage of the server program will go up endlessly. I think it is because the TCP sendQ buffer of the svr was building up as a result of the other side does not remove the data from its recvQ buffer (this guess was verified by the output of the netstat command), which in turn results the twisted Protocol to buffer the data submitted by upper layer via transport.write() to its internal buffer. My questions is that whether there is any mechanism in Twisted which can be used to set the maximum buffering size of the Protocol; and whenever if this cap is reached, I can be informed to give a chance to know the client is experiencing problem Regards. Weikai Xie
![](https://secure.gravatar.com/avatar/426d6dbf6554a9b3fca1fd04e6b75f38.jpg?s=120&d=mm&r=g)
On 09/22/2010 08:52 AM, Weikai Xie wrote
My questions is that whether there is any mechanism in Twisted which can be used to set the maximum buffering size of the Protocol; and whenever if this cap is reached, I can be informed to give a chance to know the client is experiencing problem
You need to implement a producer/consumer interface. I'm not very familiar with them, but there have been good examples in the past. Basically your data source should be a producer and the protocol should be a consumer. When the protocol (consumer) buffer is full, it'll notify the producer to stop producing.
participants (2)
-
Phil Mayers
-
Weikai Xie