1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
5 """Server for PB benchmark."""
7 from zope.interface import implements
9 from twisted.spread import pb
10 from twisted.internet import reactor
11 from twisted.cred.portal import IRealm
13 class PBBenchPerspective(pb.Avatar):
18 def perspective_simple(self):
19 self.callsPerSec = self.callsPerSec + 1
22 def printCallsPerSec(self):
23 print '(s) cps:', self.callsPerSec
25 reactor.callLater(1, self.printCallsPerSec)
27 def perspective_complexTypes(self):
28 return ['a', 1, 1l, 1.0, [], ()]
34 def requestAvatar(self, avatarId, mind, *interfaces):
35 if pb.IPerspective in interfaces:
36 p = PBBenchPerspective()
38 return pb.IPerspective, p, lambda : None
40 raise NotImplementedError("no interface")
44 from twisted.cred.portal import Portal
45 from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse
46 portal = Portal(SimpleRealm())
47 checker = InMemoryUsernamePasswordDatabaseDontUse()
48 checker.addUser("benchmark", "benchmark")
49 portal.registerChecker(checker)
50 reactor.listenTCP(8787, pb.PBServerFactory(portal))
53 if __name__ == '__main__':