예제 #1
0
    concurrency = 50

    factory = ServerFactory()
    factory.protocol = CloseConnection

    interface = '127.0.0.%d' % (int(time()) % 254 + 1, )
    interface = '127.0.0.1'
    port = reactor.listenTCP(0, factory, interface=interface)

    client = Client(
        reactor,
        TCP4ClientEndpoint(reactor,
                           port.getHost().host,
                           port.getHost().port,
                           bindAddress=(interface, 0)))
    d = client.run(concurrency, duration)

    def cleanup(passthrough):
        d = port.stopListening()
        d.addCallback(lambda ignored: passthrough)
        return d

    d.addCallback(cleanup)
    return d


if __name__ == '__main__':
    import sys
    import tcp_connect
    driver(tcp_connect.main, sys.argv)
예제 #2
0
        def cbRaiseErr(result):
            raise Exception('boom!')

        d.addCallback(cbRaiseErr)

        def ebHandleErr(failure):
            failure.trap(Exception)
            raise Exception('lesser boom!')

        d.addErrback(ebHandleErr)

        def swallowErr(failure):
            return None

        d.addBoth(swallowErr)
        self._reactor.callLater(0.0, self._continue, None)


def main(reactor, duration):
    concurrency = 10

    client = Client(reactor)
    d = client.run(concurrency, duration)
    return d


if __name__ == '__main__':
    import sys
    import deferred_callback_chains
    driver(deferred_callback_chains.main, sys.argv)
        return tags.div(u'foo', attr=u'value')

    @renderer
    def r3(self, req, tag):
        return tag.fillSlots(meep=(u'slotvalue', u'42', b'bar',
                                   tags.div(u'meep', attr=u'value')))


def render():
    child = Elem()
    for _ in xrange(20):
        child = Elem([child])
    root = TagLoader([child] * 10).load()
    out = BytesIO()
    flatten(None, root, out.write)


def main(reactor, duration):
    start = time()
    count = 0
    while time() - start < duration:
        render()
        count += 1
    return succeed(count)


if __name__ == '__main__':
    import sys
    import web_template
    driver(web_template.main, sys.argv)
예제 #4
0
        self.cleanup()

    def connectionLost(self, reason):
        self._finish(reason)


def main(reactor, duration):
    chunkSize = 16384

    server = ServerFactory()
    server.protocol = Echo
    port = reactor.listenTCP(0, server)
    client = Client(
        reactor, TCP4ClientEndpoint(reactor, '127.0.0.1',
                                    port.getHost().port))
    d = client.run(duration, chunkSize)

    def cleanup(passthrough):
        d = port.stopListening()
        d.addCallback(lambda ignored: passthrough)
        return d

    d.addCallback(cleanup)
    return d


if __name__ == '__main__':
    import sys
    import tcp_throughput
    driver(tcp_throughput.main, sys.argv)
예제 #5
0
from twisted.protocols.basic import LineReceiver
from _protocol import makeMain


class LineReceiver(LineReceiver):
    def lineReceived(self, line):
        pass

main = makeMain(LineReceiver,
                (("a" * 50) + "\r\n") * 1000)
main.__module__ = "lines"


if __name__ == '__main__':
    import sys
    import linereceiver
    from benchlib import driver
    driver(linereceiver.main, sys.argv)

from twisted.internet.interfaces import IReactorTime, IReactorSSL
from twisted.protocols.tls import TLSMemoryBIOFactory
from twisted.python.components import proxyForInterface
from benchlib import driver

from ssl_connect import main as _main


@implementer(IReactorSSL)
class SSLBIOReactor(proxyForInterface(IReactorTime, '_reactor')):
    def listenSSL(self, port, factory, contextFactory, *args, **kw):
        return self._reactor.listenTCP(
            port, TLSMemoryBIOFactory(contextFactory, False, factory), *args,
            **kw)

    def connectSSL(self, host, port, factory, contextFactory, *args, **kw):
        return self._reactor.connectTCP(
            host, port, TLSMemoryBIOFactory(contextFactory, True, factory),
            *args, **kw)


def main(reactor, duration):
    return _main(SSLBIOReactor(reactor), duration)


if __name__ == '__main__':
    import sys
    import sslbio_connect
    driver(sslbio_connect.main, sys.argv)
    checker = InMemoryUsernamePasswordDatabaseDontUse()
    checker.users = {b"username": b"password"}

    server.portal.registerChecker(checker)

    port = reactor.listenTCP(0, server)
    tcpServer = TCP4ClientEndpoint(reactor, '127.0.0.1', port.getHost().port)
    sshServer = SSHCommandClientEndpoint(
        b'chargen', tcpServer,
        lambda command: SSHPasswordUserAuth(b'username', b'password', command))

    client = Client(reactor, sshServer)
    d = client.run(duration, chunkSize)

    def cleanup(passthrough):
        d = port.stopListening()
        d.addCallback(lambda ignored: passthrough)
        return d

    d.addCallback(cleanup)
    return d


if __name__ == '__main__':
    import sys
    import ssh_throughput
    # from twisted.python.log import startLogging
    # startLogging(sys.stderr, False)
    driver(ssh_throughput.main, sys.argv)
from twisted.internet import defer, task

from time import time
from benchlib import driver


def _run():
    for x in range(1000):
        yield from defer.succeed(x)


def main(reactor, duration):
    start = time()
    count = 0
    while time() - start < duration:
        defer.ensureDeferred(_run())
        count += 1
    return defer.succeed(count)


if __name__ == '__main__':
    import sys
    import deferred_yieldfrom
    driver(deferred_yieldfrom.main, sys.argv)
예제 #9
0

interface = 0
def main(reactor, duration):
    global interface
    concurrency = 10

    root = Resource()
    root.putChild(b'', Data(b"Hello, world", "text/plain"))

    interface += 1
    interface %= 255
    port = reactor.listenTCP(
        0, Site(root), backlog=128, interface='127.0.0.%d' % (interface,))
    agent = Agent(reactor)
    client = Client(reactor, port.getHost().host, port.getHost().port, agent)
    d = client.run(concurrency, duration)
    def cleanup(passthrough):
        d = port.stopListening()
        d.addCallback(lambda ignored: passthrough)
        return d
    d.addBoth(cleanup)
    return d



if __name__ == '__main__':
    import sys
    import web
    driver(web.main, sys.argv)
예제 #10
0
from twisted.protocols.basic import LineOnlyReceiver
from twisted.test.proto_helpers import StringTransport

from _protocol import makeMain


class LineOnlyReceiver(LineOnlyReceiver):
    transport = StringTransport()

    def lineReceived(self, line):
        pass

main = makeMain(LineOnlyReceiver,
                (("a" * 50) + "\r\n") * 1000)
main.__module__ = "only-lines"

if __name__ == '__main__':
    import sys
    import lineonlyreceiver
    from benchlib import driver
    driver(lineonlyreceiver.main, sys.argv)

예제 #11
0
from twisted.internet.threads import deferToThread

from benchlib import Client, driver


class Client(Client):
    def _request(self):
        d = deferToThread(lambda: None)
        d.addCallback(self._continue)
        d.addErrback(self._stop)


def main(reactor, duration):
    concurrency = 10

    client = Client(reactor)
    d = client.run(concurrency, duration)
    return d


if __name__ == '__main__':
    import sys
    import threads
    driver(threads.main, sys.argv)
예제 #12
0
from twisted.internet.threads import deferToThread

from benchlib import Client, driver


class Client(Client):
    def _request(self):
        d = deferToThread(lambda: None)
        d.addCallback(self._continue)
        d.addErrback(self._stop)



def main(reactor, duration):
    concurrency = 10

    client = Client(reactor)
    d = client.run(concurrency, duration)
    return d



if __name__ == '__main__':
    import sys
    import threads
    driver(threads.main, sys.argv)
예제 #13
0
        d = self._proto.callRemote(Benchmark,
                                   foo=self._string,
                                   bar=self._integer,
                                   baz=self._list)
        d.addCallback(self._continue)
        d.addErrback(self._stop)


def main(reactor, duration):
    concurrency = 15

    server = ServerFactory()
    server.protocol = lambda: AMP(locator=BenchmarkLocator())
    port = reactor.listenTCP(0, server)
    client = Client(reactor, port.getHost().port)
    d = client.run(concurrency, duration)

    def cleanup(passthrough):
        d = port.stopListening()
        d.addCallback(lambda ignored: passthrough)
        return d

    d.addCallback(cleanup)
    return d


if __name__ == '__main__':
    import sys
    import amp
    driver(amp.main, sys.argv)
import struct
from twisted.protocols.basic import Int16StringReceiver
from _protocol import makeMain


class Int16StringReceiver(Int16StringReceiver):
    def stringReceived(self, s):
        pass


main = makeMain(Int16StringReceiver,
                (struct.pack("!H", 50) + b"a" * 50) * 1000)
main.__module__ = "int16strings"

if __name__ == '__main__':
    import sys
    import int16receiver
    from benchlib import driver
    driver(int16receiver.main, sys.argv)
예제 #15
0


def main(reactor, duration):
    concurrency = 50

    factory = ServerFactory()
    factory.protocol = CloseConnection

    interface = '127.0.0.%d' % (int(time()) % 254 + 1,)
    port = reactor.listenTCP(0, factory, interface=interface)

    client = Client(
        reactor, TCP4ClientEndpoint(
            reactor, port.getHost().host, port.getHost().port,
            bindAddress=(interface, 0)))
    d = client.run(concurrency, duration)
    def cleanup(passthrough):
        d = port.stopListening()
        d.addCallback(lambda ignored: passthrough)
        return d
    d.addCallback(cleanup)
    return d



if __name__ == '__main__':
    import sys
    import tcp_connect
    driver(tcp_connect.main, sys.argv)
예제 #16
0
from twisted.protocols.basic import LineReceiver
from _protocol import makeMain


class LineReceiver(LineReceiver):
    def lineReceived(self, line):
        pass

main = makeMain(LineReceiver,
                ((b"a" * 50) + b"\r\n") * 1000)
main.__module__ = "lines"


if __name__ == '__main__':
    import sys
    import linereceiver
    from benchlib import driver
    driver(linereceiver.main, sys.argv)
예제 #17
0
from benchlib import Client, driver


class Client(Client):
    def _request(self):
        self._reactor.callLater(0.0, self._continue, None)



def main(reactor, duration):
    concurrency = 10

    client = Client(reactor)
    d = client.run(concurrency, duration)
    return d



if __name__ == '__main__':
    import sys
    import iteration
    driver(iteration.main, sys.argv)
예제 #18
0

    def _request(self):
        d = self._proto.callRemote(
            Benchmark, foo=self._string, bar=self._integer, baz=self._list)
        d.addCallback(self._continue)
        d.addErrback(self._stop)



def main(reactor, duration):
    concurrency = 15

    server = ServerFactory()
    server.protocol = lambda: AMP(locator=BenchmarkLocator())
    port = reactor.listenTCP(0, server)
    client = Client(reactor, port.getHost().port)
    d = client.run(concurrency, duration)
    def cleanup(passthrough):
        d = port.stopListening()
        d.addCallback(lambda ignored: passthrough)
        return d
    d.addCallback(cleanup)
    return d


if __name__ == '__main__':
    import sys
    import amp
    driver(amp.main, sys.argv)
예제 #19
0
    def _request(self):
        d = self._resolver.lookupAddress(
            'localhost', timeout=(self._timeout,))
        d.addCallback(self._continue)
        d.addErrback(self._stop)




def main(reactor, duration):
    concurrency = 10

    controller = DNSServerFactory([hosts.Resolver()])
    port = reactor.listenUDP(0, DNSDatagramProtocol(controller))
    # Have queries time out no sooner than the duration of this benchmark so
    # we don't have to deal with retries or timeout errors.
    client = Client(reactor, port.getHost().port, duration)
    d = client.run(concurrency, duration)
    def cleanup(passthrough):
        d = port.stopListening()
        d.addCallback(lambda ign: passthrough)
        return d
    d.addBoth(cleanup)
    return d


if __name__ == '__main__':
    import sys
    import names
    driver(names.main, sys.argv)
예제 #20
0
    def _request(self):
        d = self._resolver.lookupAddress('localhost',
                                         timeout=(self._timeout, ))
        d.addCallback(self._continue)
        d.addErrback(self._stop)


def main(reactor, duration):
    concurrency = 10

    controller = DNSServerFactory([hosts.Resolver()])
    port = reactor.listenUDP(0, DNSDatagramProtocol(controller))
    # Have queries time out no sooner than the duration of this benchmark so
    # we don't have to deal with retries or timeout errors.
    client = Client(reactor, port.getHost().port, duration)
    d = client.run(concurrency, duration)

    def cleanup(passthrough):
        d = port.stopListening()
        d.addCallback(lambda ign: passthrough)
        return d

    d.addBoth(cleanup)
    return d


if __name__ == '__main__':
    import sys
    import names
    driver(names.main, sys.argv)
예제 #21
0
    def cleanup(self):
        self._reference.broker.transport.loseConnection()


    def _request(self):
        d = self._reference.callRemote('discard', self._structure)
        d.addCallback(self._continue)
        d.addErrback(self._stop)



def main(reactor, duration):
    concurrency = 15

    server = PBServerFactory(BenchRoot())
    port = reactor.listenTCP(0, server)
    client = Client(reactor, port.getHost().port)
    d = client.run(concurrency, duration)
    def cleanup(passthrough):
        d = port.stopListening()
        d.addCallback(lambda ignored: passthrough)
        return d
    d.addCallback(cleanup)
    return d


if __name__ == '__main__':
    import sys
    import pb
    driver(pb.main, sys.argv)
from twisted.internet import defer, task

from time import time
from benchlib import driver


async def _run():
    for x in range(1000):
        await defer.succeed(x)


def main(reactor, duration):
    start = time()
    count = 0
    while time() - start < duration:
        defer.ensureDeferred(_run())
        count += 1
    return defer.succeed(count)


if __name__ == '__main__':
    import sys
    import deferred_await
    driver(deferred_await.main, sys.argv)

class Client(Client):
    def _request(self):
        d = succeed('result')
        def cbRaiseErr(result):
            raise Exception('boom!')
        d.addCallback(cbRaiseErr)
        def ebHandleErr(failure):
            failure.trap(Exception)
            raise Exception('lesser boom!')
        d.addErrback(ebHandleErr)
        def swallowErr(failure):
            return None
        d.addBoth(swallowErr)
        self._reactor.callLater(0.0, self._continue, None)


def main(reactor, duration):
    concurrency = 10

    client = Client(reactor)
    d = client.run(concurrency, duration)
    return d


if __name__ == '__main__':
    import sys
    import deferred_callback_chains
    driver(deferred_callback_chains.main, sys.argv)
예제 #24
0
    server = BenchmarkSSHFactory()
    server.portal = Portal(BenchmarkRealm())
    server.portal.registerChecker(
        InMemoryUsernamePasswordDatabaseDontUse(username='******'))

    port = reactor.listenTCP(0, server)
    tcpServer = TCP4ClientEndpoint(reactor, '127.0.0.1', port.getHost().port)
    sshServer = SSHCommandClientEndpoint(
        'chargen', tcpServer,
        lambda command:
            SSHPasswordUserAuth('username', 'password', command))

    client = Client(reactor, sshServer)
    d = client.run(duration, chunkSize)
    def cleanup(passthrough):
        d = port.stopListening()
        d.addCallback(lambda ignored: passthrough)
        return d
    d.addCallback(cleanup)
    return d



if __name__ == '__main__':
    import sys
    import ssh_throughput
    # from twisted.python.log import startLogging
    # startLogging(sys.stderr, False)
    driver(ssh_throughput.main, sys.argv)
예제 #25
0

    def connectionLost(self, reason):
        self._finish(reason)



def main(reactor, duration):
    chunkSize = 16384

    server = ServerFactory()
    server.protocol = Echo
    port = reactor.listenTCP(0, server)
    client = Client(
        reactor,
        TCP4ClientEndpoint(
            reactor, '127.0.0.1', port.getHost().port))
    d = client.run(duration, chunkSize)
    def cleanup(passthrough):
        d = port.stopListening()
        d.addCallback(lambda ignored: passthrough)
        return d
    d.addCallback(cleanup)
    return d


if __name__ == '__main__':
    import sys
    import tcp_throughput
    driver(tcp_throughput.main, sys.argv)
        return tags.div(u"foo", attr=u"value")

    @renderer
    def r3(self, req, tag):
        return tag.fillSlots(meep=(u"slotvalue", u"42", b"bar", tags.div(u"meep", attr=u"value")))


def render():
    child = Elem()
    for _ in xrange(20):
        child = Elem([child])
    root = TagLoader([child] * 10).load()
    out = BytesIO()
    flatten(None, root, out.write)


def main(reactor, duration):
    start = time()
    count = 0
    while time() - start < duration:
        render()
        count += 1
    return succeed(count)


if __name__ == "__main__":
    import sys
    import web_template

    driver(web_template.main, sys.argv)
예제 #27
0
class BenchmarkSSHFactory(SSHFactory):
    publicKeys = {
        b'ssh-rsa': Key.fromString(data=PUBLIC_KEY),
    }
    privateKeys = {
        b'ssh-rsa': Key.fromString(data=PRIVATE_KEY),
    }


def main(reactor, duration):
    server = BenchmarkSSHFactory()
    port = reactor.listenTCP(0, server)
    client = Client(
        reactor, TCP4ClientEndpoint(reactor, '127.0.0.1',
                                    port.getHost().port))
    d = client.run(1, duration)

    def cleanup(passthrough):
        d = port.stopListening()
        d.addCallback(lambda ignored: passthrough)
        return d

    d.addCallback(cleanup)
    return d


if __name__ == '__main__':
    import sys
    import ssh_connect
    driver(ssh_connect.main, sys.argv)
예제 #28
0
from benchlib import driver

from ssl_throughput import main as _main
from sslbio_connect import SSLBIOReactor


def main(reactor, duration):
    return _main(SSLBIOReactor(reactor), duration)



if __name__ == '__main__':
    import sys
    import sslbio_throughput
    driver(sslbio_throughput.main, sys.argv)
from benchlib import driver

from ssl_throughput import main as _main
from sslbio_connect import SSLBIOReactor


def main(reactor, duration):
    return _main(SSLBIOReactor(reactor), duration)


if __name__ == '__main__':
    import sys
    import sslbio_throughput
    driver(sslbio_throughput.main, sys.argv)
from twisted.protocols.basic import LineOnlyReceiver
from twisted.test.proto_helpers import StringTransport

from _protocol import makeMain


class LineOnlyReceiver(LineOnlyReceiver):
    transport = StringTransport()

    def lineReceived(self, line):
        pass


main = makeMain(LineOnlyReceiver, ((b"a" * 50) + b"\r\n") * 1000)
main.__module__ = "only-lines"

if __name__ == '__main__':
    import sys
    import lineonlyreceiver
    from benchlib import driver
    driver(lineonlyreceiver.main, sys.argv)
예제 #31
0

interface = 0
def main(reactor, duration):
    global interface
    concurrency = 10

    root = Resource()
    root.putChild('', Data("Hello, world", "text/plain"))

    interface += 1
    interface %= 255
    port = reactor.listenTCP(
        0, Site(root), backlog=128, interface='127.0.0.%d' % (interface,))
    agent = Agent(reactor)
    client = Client(reactor, port.getHost().host, port.getHost().port, agent)
    d = client.run(concurrency, duration)
    def cleanup(passthrough):
        d = port.stopListening()
        d.addCallback(lambda ignored: passthrough)
        return d
    d.addBoth(cleanup)
    return d



if __name__ == '__main__':
    import sys
    import web
    driver(web.main, sys.argv)
예제 #32
0
    interface = '127.0.0.%d' % (int(time()) % 254 + 1,)

    contextFactory = cert.options()
    factory = Factory()
    factory.protocol = CloseConnection
    serverEndpoint = SSL4ServerEndpoint(
        reactor, 0, contextFactory, interface=interface)

    listen = serverEndpoint.listen(factory)
    def cbListening(port):
        client = Client(
            reactor, SSL4ClientEndpoint(
                reactor, interface, port.getHost().port,
                contextFactory, bindAddress=(interface, 0)))
        d = client.run(concurrency, duration)
        def cleanup(passthrough):
            d = port.stopListening()
            d.addCallback(lambda ignored: passthrough)
            return d
        d.addCallback(cleanup)
        return d
    listen.addCallback(cbListening)
    return listen


if __name__ == '__main__':
    import sys
    import ssl_connect
    driver(ssl_connect.main, sys.argv)
예제 #33
0
    def cleanup(self):
        self._reference.broker.transport.loseConnection()


    def _request(self):
        d = self._reference.callRemote('discard', self._structure)
        d.addCallback(self._continue)
        d.addErrback(self._stop)



def main(reactor, duration):
    concurrency = 15

    server = PBServerFactory(BenchRoot())
    port = reactor.listenTCP(0, server)
    client = Client(reactor, port.getHost().port)
    d = client.run(concurrency, duration)
    def cleanup(passthrough):
        d = port.stopListening()
        d.addCallback(lambda ignored: passthrough)
        return d
    d.addCallback(cleanup)
    return d


if __name__ == '__main__':
    import sys
    import pb
    driver(pb.main, sys.argv)