Permalink
Browse files

Bring back two files lost in outer space

  • Loading branch information...
1 parent b11be81 commit 09eb6d68f780fe429a7d40198525bf789e60a25c @priteau priteau committed Jan 20, 2012
Showing with 209 additions and 0 deletions.
  1. +113 −0 scale_scripts/concur_pingpong.py
  2. +96 −0 scale_scripts/pingpong.py
@@ -0,0 +1,113 @@
+import socket
+import sys
+from threading import Timer
+from threading import Thread
+from dashi import bootstrap
+import datetime
+import simplejson as json
+
+class DashiConcurScalePonger(object):
+
+ def __init__(self, CFG):
+ self.CFG = CFG
+ self.dashi = bootstrap.dashi_connect(CFG.test.ponger_name, CFG)
+ self.done = False
+ self.dashi.handle(self.ping, "ping")
+ self.dashi.handle(self.final_msg, "final_msg")
+
+ def ping(self, from_name=None):
+ #print "ponging to %s" % (from_name)
+ self.dashi.fire(from_name, "pong")
+
+ def final_msg(self):
+ print "received final message"
+ self.done = True
+ sys.exit(0)
+
+ def go(self):
+ while not self.done:
+ try:
+ self.dashi.consume()
+ except socket.timeout, ex:
+ pass
+
+
+class DashiConcurScalePinger(Thread):
+
+ def __init__(self, CFG, cnt):
+ Thread.__init__(self)
+ self._myname = CFG.test.pinger_name + "_" + str(cnt)
+ self.CFG = CFG
+ self.dashi = bootstrap.dashi_connect(self._myname, CFG)
+ self.done = False
+ self.end_time = None
+ self.start_time = None
+ self.message_count = 0
+ self.dashi.handle(self.pong, "pong")
+ self.timer = Timer(float(CFG.test.runtime), self.timeout)
+
+ def run(self):
+ self.go()
+
+ def go(self):
+ self.timer.start()
+ #print "sending first ping to %s" % (self.CFG.test.ponger_name)
+ self.dashi.fire(self.CFG.test.ponger_name, "ping", from_name=self._myname)
+ while not self.done:
+ try:
+ self.dashi.consume(count=1, timeout=10)
+ except socket.timeout, ex:
+ pass
+
+ def timeout(self):
+ self.end_time = datetime.datetime.now()
+ self.done = True
+
+ def pong(self):
+ #print "got pong"
+ self.message_count = self.message_count + 1
+ self.dashi.fire(self.CFG.test.ponger_name, "ping", from_name=self._myname)
+
+
+def main(argv):
+ CFG = bootstrap.configure(argv=argv)
+
+ if CFG.test.type == "ping":
+ sender_count = int(CFG.test.concur)
+ print "sender count %d" % (sender_count)
+ thrs = []
+ start_time = datetime.datetime.now()
+ for i in range(0, sender_count):
+ sender = DashiConcurScalePinger(CFG, i)
+ thrs.append(sender)
+ sender.start()
+
+ msg_count_total = 0
+ for t in thrs:
+ t.join()
+ msg_count_total = msg_count_total + t.message_count
+ end_time = datetime.datetime.now()
+
+ tm = end_time - start_time
+ preci = float(tm.microseconds) / 1000000.0
+ runtime = tm.seconds + preci
+
+ res = {}
+ res['testname'] = "concurtest"
+ res['message_count'] = msg_count_total
+ res['runtime'] = runtime
+ res['process_type'] = "pinger"
+ res['connection_count'] = len(thrs)
+ print "JSON: %s" % (json.dumps(res))
+ else:
+ print "ponger go"
+ receiver = DashiConcurScalePonger(CFG)
+ receiver.go()
+
+
+
+if __name__ == '__main__':
+ print "start"
+ rc = main(sys.argv)
+ print "exit"
+ sys.exit(rc)
View
@@ -0,0 +1,96 @@
+import socket
+import sys
+from threading import Timer
+import threading
+from dashi import bootstrap
+import datetime
+import simplejson as json
+
+class DashiScalePonger(object):
+
+ def __init__(self, CFG):
+ self.CFG = CFG
+ self.dashi = bootstrap.dashi_connect(CFG.test.ponger_name, CFG)
+ self.done = False
+ self.dashi.handle(self.ping, "ping")
+ self.dashi.handle(self.final_msg, "final_msg")
+
+ def ping(self):
+ self.dashi.fire(self.CFG.test.pinger_name, "pong")
+
+ def final_msg(self):
+ print "received final message"
+ self.done = True
+ sys.exit(0)
+
+ def go(self):
+ while not self.done:
+ try:
+ self.dashi.consume()
+ except socket.timeout, ex:
+ pass
+
+
+class DashiScalePinger(object):
+
+ def __init__(self, CFG):
+ self.CFG = CFG
+ self.dashi = bootstrap.dashi_connect(CFG.test.pinger_name, CFG)
+ self.done = False
+ self.end_time = None
+ self.start_time = None
+ self.message_count = 0
+ self.dashi.handle(self.pong, "pong")
+ self.timer = Timer(float(CFG.test.runtime), self.timeout)
+
+ def go(self):
+ self.timer.start()
+ self.start_time = datetime.datetime.now()
+ print "sending first ping"
+ self.dashi.fire(self.CFG.test.ponger_name, "ping")
+ while not self.done:
+ try:
+ self.dashi.consume(count=1, timeout=2)
+ except socket.timeout, ex:
+ pass
+ print "sending final message"
+ self.dashi.fire(self.CFG.test.ponger_name, "final_msg")
+
+ def timeout(self):
+ self.end_time = datetime.datetime.now()
+ self.done = True
+
+ def pong(self):
+ self.message_count = self.message_count + 1
+ self.dashi.fire(self.CFG.test.ponger_name, "ping")
+
+ def get_results(self):
+ tm = self.end_time - self.start_time
+ preci = float(tm.microseconds) / 1000000.0
+ tm = tm.seconds + preci
+ res = {}
+ res['testname'] = self.CFG.test.name
+ res['message_count'] = self.message_count
+ res['runtime'] = tm
+ res['process_type'] = "pinger"
+
+ return res
+
+def main(argv):
+ CFG = bootstrap.configure(argv=argv)
+
+ if CFG.test.type == "ping":
+ sender = DashiScalePinger(CFG)
+ sender.go()
+ res = sender.get_results()
+ print "JSON: %s" % (json.dumps(res))
+ else:
+ receiver = DashiScalePonger(CFG)
+ receiver.go()
+
+
+
+if __name__ == '__main__':
+ rc = main(sys.argv)
+ print "exit"
+ sys.exit(rc)

0 comments on commit 09eb6d6

Please sign in to comment.