Debian Codegraph @

docs/core/examples/pbbenchclient.py

raw
1 import time
2
3 from twisted.cred.credentials import UsernamePassword
4 from twisted.internet import defer, reactor
5 from twisted.spread import pb
6
7
8 class PBBenchClient:
9 hostname = "localhost"
10 portno = pb.portno
11 calledThisSecond = 0
12
13 def callLoop(self, ignored):
14 d1 = self.persp.callRemote(b"simple")
15 d2 = self.persp.callRemote(b"complexTypes")
16 defer.DeferredList([d1, d2]).addCallback(self.callLoop)
17 self.calledThisSecond += 1
18 thisSecond = int(time.time())
19 if thisSecond != self.lastSecond:
20 if thisSecond - self.lastSecond > 1:
21 print("WARNING it took more than one second")
22 print("cps:", self.calledThisSecond)
23 self.calledThisSecond = 0
24 self.lastSecond = thisSecond
25
26 def _cbPerspective(self, persp):
27 self.persp = persp
28 self.lastSecond = int(time.time())
29 self.callLoop(None)
30
31 def runTest(self):
32 factory = pb.PBClientFactory()
33 reactor.connectTCP(self.hostname, self.portno, factory)
34 factory.login(UsernamePassword(b"benchmark", b"benchmark")).addCallback(
35 self._cbPerspective
36 )
37
38
39 def main():
40 PBBenchClient().runTest()
41 from twisted.internet import reactor
42
43 reactor.run()
44
45
46 if __name__ == "__main__":
47 main()