[pypy-svn] r75054 - pypy/benchmarks/own/twisted

arigo at codespeak.net arigo at codespeak.net
Thu Jun 3 17:07:57 CEST 2010


Author: arigo
Date: Thu Jun  3 17:07:55 2010
New Revision: 75054

Modified:
   pypy/benchmarks/own/twisted/accepts.py
   pypy/benchmarks/own/twisted/benchlib.py
   pypy/benchmarks/own/twisted/pb.py
   pypy/benchmarks/own/twisted/tcp.py
   pypy/benchmarks/own/twisted/web.py
Log:
Following exarkun's suggestion, avoid running out of
local ports by using 127.0.0.2, 127.0.0.3, etc.


Modified: pypy/benchmarks/own/twisted/accepts.py
==============================================================================
--- pypy/benchmarks/own/twisted/accepts.py	(original)
+++ pypy/benchmarks/own/twisted/accepts.py	Thu Jun  3 17:07:55 2010
@@ -5,12 +5,13 @@
 from twisted.internet.error import ConnectionClosed
 from twisted.internet.defer import Deferred
 
-from benchlib import Client, driver
+from benchlib import Client, driver, rotate_local_intf
 
 
 class Client(Client):
-    def __init__(self, reactor, portNumber):
+    def __init__(self, reactor, host, portNumber):
         super(Client, self).__init__(reactor)
+        self._host = host
         self._portNumber = portNumber
         self._factory = ClientFactory()
 
@@ -21,7 +22,7 @@
         factory.protocol = Protocol
         factory.clientConnectionLost = factory.clientConnectionFailed = lambda connector, reason: finished.errback(reason)
         finished.addErrback(self._filterFinished)
-        self._reactor.connectTCP('127.0.0.1', self._portNumber, factory)
+        self._reactor.connectTCP(self._host, self._portNumber, factory)
         finished.addCallback(self._continue)
         finished.addErrback(self._stop)
 
@@ -41,9 +42,10 @@
 
     factory = ServerFactory()
     factory.protocol = CloseConnection
-    port = reactor.listenTCP(0, factory)
+    port = reactor.listenTCP(0, factory,
+                             interface=rotate_local_intf())
 
-    client = Client(reactor, port.getHost().port)
+    client = Client(reactor, port.getHost().host, port.getHost().port)
     d = client.run(concurrency, duration)
     return d
 

Modified: pypy/benchmarks/own/twisted/benchlib.py
==============================================================================
--- pypy/benchmarks/own/twisted/benchlib.py	(original)
+++ pypy/benchmarks/own/twisted/benchlib.py	Thu Jun  3 17:07:55 2010
@@ -92,3 +92,9 @@
         reactor.stop()
     reactor.callWhenRunning(work)
     reactor.run()
+
+_interface = 1
+def rotate_local_intf():
+    global _interface
+    _interface = _interface % 254 + 1
+    return '127.0.0.%d' % (_interface,)

Modified: pypy/benchmarks/own/twisted/pb.py
==============================================================================
--- pypy/benchmarks/own/twisted/pb.py	(original)
+++ pypy/benchmarks/own/twisted/pb.py	Thu Jun  3 17:07:55 2010
@@ -7,7 +7,7 @@
 
 from twisted.spread.pb import PBServerFactory, PBClientFactory, Root
 
-from benchlib import Client, driver
+from benchlib import Client, driver, rotate_local_intf
 
 
 class BenchRoot(Root):
@@ -23,8 +23,9 @@
          'baz': 100,
          u'these are bytes': (1, 2, 3)}]
 
-    def __init__(self, reactor, port):
+    def __init__(self, reactor, host, port):
         super(Client, self).__init__(reactor)
+        self._host = host
         self._port = port
 
 
@@ -35,7 +36,7 @@
         client = PBClientFactory()
         d = client.getRootObject()
         d.addCallback(connected)
-        self._reactor.connectTCP('127.0.0.1', self._port, client)
+        self._reactor.connectTCP(self._host, self._port, client)
         return d
 
 
@@ -49,8 +50,9 @@
     concurrency = 15
 
     server = PBServerFactory(BenchRoot())
-    port = reactor.listenTCP(0, server)
-    client = Client(reactor, port.getHost().port)
+    port = reactor.listenTCP(0, server,
+                             interface=rotate_local_intf())
+    client = Client(reactor, port.getHost().host, port.getHost().port)
     d = client.run(concurrency, duration)
     return d
 

Modified: pypy/benchmarks/own/twisted/tcp.py
==============================================================================
--- pypy/benchmarks/own/twisted/tcp.py	(original)
+++ pypy/benchmarks/own/twisted/tcp.py	Thu Jun  3 17:07:55 2010
@@ -13,7 +13,7 @@
 from twisted.internet.protocol import ServerFactory, ClientCreator, Protocol
 from twisted.protocols.wire import Echo
 
-from benchlib import driver
+from benchlib import driver, rotate_local_intf
 
 
 class Counter(Protocol):
@@ -27,8 +27,9 @@
 class Client(object):
     _finished = None
 
-    def __init__(self, reactor, port):
+    def __init__(self, reactor, host, port):
         self._reactor = reactor
+        self._host = host
         self._port = port
 
 
@@ -37,7 +38,7 @@
         self._bytes = 'x' * chunkSize
         # Set up a connection
         cc = ClientCreator(self._reactor, Counter)
-        d = cc.connectTCP('127.0.0.1', self._port)
+        d = cc.connectTCP(self._host, self._port)
         d.addCallback(self._connected)
         return d
 
@@ -81,8 +82,10 @@
 
     server = ServerFactory()
     server.protocol = Echo
-    serverPort = reactor.listenTCP(0, server)
-    client = Client(reactor, serverPort.getHost().port)
+    serverPort = reactor.listenTCP(0, server,
+                                   interface=rotate_local_intf())
+    client = Client(reactor, serverPort.getHost().host,
+                             serverPort.getHost().port)
     d = client.run(duration, chunkSize)
     return d
 

Modified: pypy/benchmarks/own/twisted/web.py
==============================================================================
--- pypy/benchmarks/own/twisted/web.py	(original)
+++ pypy/benchmarks/own/twisted/web.py	Thu Jun  3 17:07:55 2010
@@ -20,7 +20,7 @@
 from twisted.web.resource import Resource
 from twisted.web.client import ResponseDone, Agent
 
-from benchlib import Client, driver
+from benchlib import Client, driver, rotate_local_intf
 
 
 class BodyConsumer(Protocol):
@@ -36,8 +36,8 @@
 
 
 class Client(Client):
-    def __init__(self, reactor, portNumber, agent):
-        self._requestLocation = 'http://127.0.0.1:%d/' % (portNumber,)
+    def __init__(self, reactor, host, portNumber, agent):
+        self._requestLocation = 'http://%s:%d/' % (host, portNumber)
         self._agent = agent
         super(Client, self).__init__(reactor)
 
@@ -62,9 +62,9 @@
     root = Resource()
     root.putChild('', Data("Hello, world", "text/plain"))
     port = reactor.listenTCP(
-        0, Site(root), backlog=128, interface='127.0.0.1')
+        0, Site(root), backlog=128, interface=rotate_local_intf())
     agent = Agent(reactor)
-    client = Client(reactor, port.getHost().port, agent)
+    client = Client(reactor, port.getHost().host, port.getHost().port, agent)
     d = client.run(concurrency, duration)
     return d
 



More information about the Pypy-commit mailing list