[Twisted-Python] Re: [Twisted-commits] CVS: Twisted/twisted/internet poll.py,NONE,1.1

Itamar Shtull-Trauring twisted at itamarst.org
Thu Nov 29 11:46:00 EST 2001

Glyph Lefkowitz wrote:

> Even though I am not sure I understand the problem :), perhaps the right answer
> to this question, since the common case is that all data can be written at
> once, is that the write should happen immediately, only being added to the
> select/poll loop if the write would block.  This would probably add a little
> complexity to the code but save a bunch of performance on small-write heavy
> protocols.

Well, I tried this. The result was a 25-50 percent improvement in read benchmarks

on my code. Web performance seems slightly worse in the one test I did. And it's

probably got some issues detecting closed connections... I have another 
behcmark that takes twice as long.

But as you can see there is some room for improvement, even if this patch specifically

is buggy.

Index: twisted/internet/abstract.py
RCS file: /cvs/Twisted/twisted/internet/abstract.py,v
retrieving revision 1.11
diff -c -r1.11 abstract.py
*** twisted/internet/abstract.py	2001/10/30 23:55:39	1.11
--- twisted/internet/abstract.py	2001/11/29 16:26:29
*** 106,111 ****
--- 106,117 ----
          if not self.connected:
          if data:
+             if not self.unsent:
+                 l = self.writeSomeData(data)
+                 if l == len(data) or l < 0:
+                     return
+                 else:
+                     data = data[l:]
              self.unsent = self.unsent + data
              if self.producer is not None:
                  if len(self.unsent) > self.bufferSize:

More information about the Twisted-Python mailing list