Minor optimizations and some fixes to the dummyrunner.
This commit is contained in:
parent
5117bd2a0a
commit
f68523cc22
3 changed files with 57 additions and 40 deletions
|
|
@ -884,9 +884,7 @@ class TypedObject(SharedMemoryModel):
|
||||||
# (we make sure to not incur a loop by not triggering the
|
# (we make sure to not incur a loop by not triggering the
|
||||||
# typeclass' __getattribute__, since that one would
|
# typeclass' __getattribute__, since that one would
|
||||||
# try to look back to this very database object.)
|
# try to look back to this very database object.)
|
||||||
typeclass = _GA(self, 'typeclass')
|
return _GA(_GA(self, 'typeclass'), propname)
|
||||||
# will raise AttributeError also if typeclass was malformed
|
|
||||||
return _GA(typeclass, propname)
|
|
||||||
|
|
||||||
#@property
|
#@property
|
||||||
_dbid_cache = None
|
_dbid_cache = None
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,9 @@ from django.conf import settings
|
||||||
from src.utils import utils
|
from src.utils import utils
|
||||||
|
|
||||||
HELPTEXT = """
|
HELPTEXT = """
|
||||||
|
|
||||||
|
Usage: dummyrunner.py [-h][-v][-V] [nclients]
|
||||||
|
|
||||||
DO NOT RUN THIS ON A PRODUCTION SERVER! USE A CLEAN/TESTING DATABASE!
|
DO NOT RUN THIS ON A PRODUCTION SERVER! USE A CLEAN/TESTING DATABASE!
|
||||||
|
|
||||||
This stand-alone program launches dummy telnet clients against a
|
This stand-alone program launches dummy telnet clients against a
|
||||||
|
|
@ -144,6 +147,9 @@ class DummyClient(telnet.StatefulTelnetProtocol):
|
||||||
self.exits = [] # exit names created
|
self.exits = [] # exit names created
|
||||||
self.objs = [] # obj names created
|
self.objs = [] # obj names created
|
||||||
|
|
||||||
|
self._report = ""
|
||||||
|
self._cmdlist = [] # already stepping in a cmd definition
|
||||||
|
self._ncmds = 0
|
||||||
self._actions = self.factory.actions
|
self._actions = self.factory.actions
|
||||||
self._echo_brief = self.factory.verbose == 1
|
self._echo_brief = self.factory.verbose == 1
|
||||||
self._echo_all = self.factory.verbose == 2
|
self._echo_all = self.factory.verbose == 2
|
||||||
|
|
@ -186,23 +192,28 @@ class DummyClient(telnet.StatefulTelnetProtocol):
|
||||||
"""
|
"""
|
||||||
if random.random() > CHANCE_OF_ACTION:
|
if random.random() > CHANCE_OF_ACTION:
|
||||||
return
|
return
|
||||||
if self.istep == 0:
|
if not self._cmdlist:
|
||||||
cfunc = self._actions[0]
|
# no cmdlist in store, get a new one
|
||||||
else: # random selection using cumulative probabilities
|
if self.istep == 0:
|
||||||
rand = random.random()
|
cfunc = self._actions[0]
|
||||||
cfunc = [func for cprob, func in self._actions[2] if cprob >= rand][0]
|
else: # random selection using cumulative probabilities
|
||||||
# launch the action (don't hide tracebacks)
|
rand = random.random()
|
||||||
cmd, report = cfunc(self)
|
cfunc = [func for cprob, func in self._actions[2] if cprob >= rand][0]
|
||||||
# handle the result
|
# assign to internal cmdlist
|
||||||
cmd = "\n".join(makeiter(cmd))
|
cmd, self._report = cfunc(self)
|
||||||
if self.istep == 0 or self._echo_brief or self._echo_all:
|
self._cmdlist = list(makeiter(cmd))
|
||||||
print "client %i %s" % (self.cid, report)
|
self._ncmds = len(self._cmdlist)
|
||||||
self.sendLine(cmd)
|
# output
|
||||||
|
if self.istep == 0 and not (self._echo_brief or self._echo_all):
|
||||||
|
print "client %i %s" % (self.cid, self._report)
|
||||||
|
elif self.istep == 0 or self._echo_brief or self._echo_all:
|
||||||
|
print "client %i %s (%i/%i)" % (self.cid, self._report, self._ncmds-(len(self._cmdlist)-1), self._ncmds)
|
||||||
|
# launch the action by popping the first element from cmdlist (don't hide tracebacks)
|
||||||
|
self.sendLine(str(self._cmdlist.pop(0)))
|
||||||
self.istep += 1 # only steps up if an action is taken
|
self.istep += 1 # only steps up if an action is taken
|
||||||
|
|
||||||
class DummyFactory(protocol.ClientFactory):
|
class DummyFactory(protocol.ClientFactory):
|
||||||
protocol = DummyClient
|
protocol = DummyClient
|
||||||
|
|
||||||
def __init__(self, actions, timestep, verbose):
|
def __init__(self, actions, timestep, verbose):
|
||||||
"Setup the factory base (shared by all clients)"
|
"Setup the factory base (shared by all clients)"
|
||||||
self.actions = actions
|
self.actions = actions
|
||||||
|
|
|
||||||
|
|
@ -59,12 +59,20 @@ TOBJ_TYPECLASS = "examples.red_button.RedButton"
|
||||||
def c_login(client):
|
def c_login(client):
|
||||||
"logins to the game"
|
"logins to the game"
|
||||||
cname = "Dummy-%s-%i" % (RUNID, client.cid)
|
cname = "Dummy-%s-%i" % (RUNID, client.cid)
|
||||||
cemail = "%s@dummy.com" % (cname.lower())
|
#cemail = "%s@dummy.com" % (cname.lower())
|
||||||
cpwd = "%s-%s" % (RUNID, client.cid)
|
cpwd = "%s-%s" % (RUNID, client.cid)
|
||||||
cmd = ('create "%s" %s %s' % (cname, cemail, cpwd),
|
# set up for digging a first room (to move to)
|
||||||
'connect %s %s' % (cemail, cpwd),
|
roomname = ROOM_TEMPLATE % client.counter()
|
||||||
|
exitname1 = EXIT_TEMPLATE % client.counter()
|
||||||
|
exitname2 = EXIT_TEMPLATE % client.counter()
|
||||||
|
client.exits.extend([exitname1, exitname2])
|
||||||
|
cmd = '@dig %s = %s, %s' % (roomname, exitname1, exitname2)
|
||||||
|
cmd = ('create %s %s' % (cname, cpwd),
|
||||||
|
'connect %s %s' % (cname, cpwd),
|
||||||
'@dig %s' % START_ROOM % client.cid,
|
'@dig %s' % START_ROOM % client.cid,
|
||||||
'@teleport %s' % START_ROOM % client.cid)
|
'@teleport %s' % START_ROOM % client.cid,
|
||||||
|
'@dig %s = %s, %s' % (roomname, exitname1, exitname2)
|
||||||
|
)
|
||||||
|
|
||||||
return cmd, "logs in as %s ..." % cname
|
return cmd, "logs in as %s ..." % cname
|
||||||
|
|
||||||
|
|
@ -143,16 +151,16 @@ def c_moves(client):
|
||||||
# otherwise the system will normalize them.
|
# otherwise the system will normalize them.
|
||||||
#
|
#
|
||||||
|
|
||||||
# heavy builder definition
|
# "heavy" builder definition
|
||||||
#ACTIONS = ( c_login,
|
ACTIONS = ( c_login,
|
||||||
# c_logout,
|
c_logout,
|
||||||
# (0.2, c_looks),
|
(0.2, c_looks),
|
||||||
# (0.1, c_examines),
|
(0.1, c_examines),
|
||||||
# (0.2, c_help),
|
(0.2, c_help),
|
||||||
# (0.1, c_digs),
|
(0.1, c_digs),
|
||||||
# (0.1, c_creates_obj),
|
(0.1, c_creates_obj),
|
||||||
# #(0.1, c_creates_button),
|
#(0.01, c_creates_button),
|
||||||
# (0.2, c_moves))
|
(0.2, c_moves))
|
||||||
# "normal builder" definition
|
# "normal builder" definition
|
||||||
#ACTIONS = ( c_login,
|
#ACTIONS = ( c_login,
|
||||||
# c_logout,
|
# c_logout,
|
||||||
|
|
@ -163,14 +171,14 @@ def c_moves(client):
|
||||||
# (0.01, c_creates_obj),
|
# (0.01, c_creates_obj),
|
||||||
# #(0.1, c_creates_button),
|
# #(0.1, c_creates_button),
|
||||||
# (0.3, c_moves))
|
# (0.3, c_moves))
|
||||||
# "normal player" definition
|
# "passive player" definition
|
||||||
ACTIONS = ( c_login,
|
#ACTIONS = ( c_login,
|
||||||
c_logout,
|
# c_logout,
|
||||||
(0.7, c_looks),
|
# (0.7, c_looks),
|
||||||
#(0.1, c_examines),
|
# #(0.1, c_examines),
|
||||||
(0.3, c_help))
|
# (0.3, c_help))
|
||||||
#(0.1, c_digs),
|
# #(0.1, c_digs),
|
||||||
#(0.1, c_creates_obj),
|
# #(0.1, c_creates_obj),
|
||||||
#(0.1, c_creates_button),
|
# #(0.1, c_creates_button),
|
||||||
#(0.4, c_moves))
|
# #(0.4, c_moves))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue