File: pbbenchclient.py

package info (click to toggle)
twisted 25.5.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,560 kB
  • sloc: python: 203,171; makefile: 200; sh: 92; javascript: 36; xml: 31
file content (47 lines) | stat: -rw-r--r-- 1,319 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import time

from twisted.cred.credentials import UsernamePassword
from twisted.internet import defer, reactor
from twisted.spread import pb


class PBBenchClient:
    hostname = "localhost"
    portno = pb.portno
    calledThisSecond = 0

    def callLoop(self, ignored):
        d1 = self.persp.callRemote(b"simple")
        d2 = self.persp.callRemote(b"complexTypes")
        defer.DeferredList([d1, d2]).addCallback(self.callLoop)
        self.calledThisSecond += 1
        thisSecond = int(time.time())
        if thisSecond != self.lastSecond:
            if thisSecond - self.lastSecond > 1:
                print("WARNING it took more than one second")
            print("cps:", self.calledThisSecond)
            self.calledThisSecond = 0
            self.lastSecond = thisSecond

    def _cbPerspective(self, persp):
        self.persp = persp
        self.lastSecond = int(time.time())
        self.callLoop(None)

    def runTest(self):
        factory = pb.PBClientFactory()
        reactor.connectTCP(self.hostname, self.portno, factory)
        factory.login(UsernamePassword(b"benchmark", b"benchmark")).addCallback(
            self._cbPerspective
        )


def main():
    PBBenchClient().runTest()
    from twisted.internet import reactor

    reactor.run()


if __name__ == "__main__":
    main()