1
# Twisted, the Framework of Your Internet
2
# Copyright (C) 2001, 2002 Matthew W. Lefkowitz
4
# This library is free software; you can redistribute it and/or
5
# modify it under the terms of version 2.1 of the GNU Lesser General Public
6
# License as published by the Free Software Foundation.
8
# This library is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
# Lesser General Public License for more details.
13
# You should have received a copy of the GNU Lesser General Public
14
# License along with this library; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Server for PB benchmark."""
19
from twisted.spread import pb
20
from twisted.internet import reactor
21
from twisted.cred.portal import IRealm
23
class PBBenchPerspective(pb.Avatar):
28
def perspective_simple(self):
29
self.callsPerSec = self.callsPerSec + 1
32
def printCallsPerSec(self):
33
print '(s) cps:', self.callsPerSec
35
reactor.callLater(1, self.printCallsPerSec)
37
def perspective_complexTypes(self):
38
return ['a', 1, 1l, 1.0, [], ()]
42
__implements__ = IRealm
44
def requestAvatar(self, avatarId, mind, *interfaces):
45
if pb.IPerspective in interfaces:
46
p = PBBenchPerspective()
48
return pb.IPerspective, p, lambda : None
50
raise NotImplementedError("no interface")
54
from twisted.cred.portal import Portal
55
from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse
56
portal = Portal(SimpleRealm())
57
checker = InMemoryUsernamePasswordDatabaseDontUse()
58
checker.addUser("benchmark", "benchmark")
59
portal.registerChecker(checker)
60
reactor.listenTCP(8787, pb.PBServerFactory(portal))
63
if __name__ == '__main__':