~cbehrens/nova/lp844160-build-works-with-zones

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/doc/core/examples/pbbenchclient.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

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