[Twisted-Python] Results of stress testing the reactor

Keith.Gunderson at act.org Keith.Gunderson at act.org
Wed Nov 30 11:36:20 EST 2005


I'm getting settled in with an experimental project using twisted.  I
posting some of my preliminary results in this message.  Please let me know
if this information is interesting or helpful.

I plan on using twisted as a part of my performance testing simulations.  I
use the Mercury Interactive tools for the 'heavy lifting' of my work.  I'll
use my twisted designs to provide advanced simulation logic and timing
features.   That is, I'll create many virtual users that will talk HTTP to
non-twisted web apps while measuring the results (i.e. performance
testing).  But, these virtual users will sometimes talk HTTP to my twisted
web app to get whatever data I want them to have.

So, I've got the following little app which takes three seconds to respond
to any request.  I'm trying test the Mercury tools on how they deal with
concurrent requests.   I'm not doing much here, just kicking in the tires a
little.

I'm using the latest twisted release on Win2000.

import time,sys
from twisted.internet import protocol, reactor

def defFn( protObject):
    protObject.transport.write('Hello. Deferred:\n')
    sys.stdout.write('The time is %s\n' % time.time())
    protObject.transport.loseConnection()

class TimeProtocol(protocol.Protocol):

    def dataReceived(self, data):
        self.transport.write('Hello. Data received: \n' )
        reactor.callLater(3, defFn,  self )


class TimeFactory(protocol.ServerFactory):
    protocol = TimeProtocol

reactor.listenTCP(9100, TimeFactory())
reactor.run()



Everything works as expected until I get about 300 virtual users hitting
the site somewhat simultaneously.  (Approx. 200 hits per second.)  At which
point the reactor kind of explodes.  The following traceback races from the
console (probably in an infinite loop.)  This may not be unexpected or
significant, but I found it interesting.

Is there anything I can do to prevent this, other than refraining from
trying to overload things on purpose?  Are there other tests that you gurus
might find interesting?

  File "tw09.py", line 25, in ?
    reactor.run()
  File "C:\progs\python24\Lib\site-packages\twisted\internet\posixbase.py",
line
 199, in run
    self.mainLoop()
  File "C:\progs\python24\Lib\site-packages\twisted\internet\posixbase.py",
line
 210, in mainLoop
    self.doIteration(t)
--- <exception caught here> ---
  File "C:
\progs\python24\Lib\site-packages\twisted\internet\selectreactor.py",
line 97, in doSelect
    [], timeout)
  File "C:
\progs\python24\Lib\site-packages\twisted\internet\selectreactor.py",
line 49, in win32select
    r, w, e = select.select(r, w, w, timeout)
exceptions.ValueError: too many file descriptors in select()
Traceback (most recent call last):
  File "tw09.py", line 25, in ?
    reactor.run()
  File "C:\progs\python24\Lib\site-packages\twisted\internet\posixbase.py",
line
 199, in run
    self.mainLoop()
  File "C:\progs\python24\Lib\site-packages\twisted\internet\posixbase.py",
line
 210, in mainLoop
    self.doIteration(t)
--- <exception caught here> ---
  File "C:
\progs\python24\Lib\site-packages\twisted\internet\selectreactor.py",
line 97, in doSelect
    [], timeout)
  File "C:
\progs\python24\Lib\site-packages\twisted\internet\selectreactor.py",
line 49, in win32select
    r, w, e = select.select(r, w, w, timeout)
exceptions.ValueError: too many file descriptors in select()



Keith Gunderson
Performance Test Analyst







More information about the Twisted-Python mailing list