summaryrefslogtreecommitdiff
path: root/py/demo/Ice/throughput/Client.py
diff options
context:
space:
mode:
authorMatthew Newhook <matthew@zeroc.com>2005-09-14 06:26:31 +0000
committerMatthew Newhook <matthew@zeroc.com>2005-09-14 06:26:31 +0000
commit502335f0e2d6d407b8c93690bd01d35c33e1f0cf (patch)
tree38f5b655a2a2411537b9361153d0b81f7f672325 /py/demo/Ice/throughput/Client.py
parentBug 454. (diff)
downloadice-502335f0e2d6d407b8c93690bd01d35c33e1f0cf.tar.bz2
ice-502335f0e2d6d407b8c93690bd01d35c33e1f0cf.tar.xz
ice-502335f0e2d6d407b8c93690bd01d35c33e1f0cf.zip
http://bugzilla.zeroc.com/bugzilla/show_bug.cgi?id=335
Diffstat (limited to 'py/demo/Ice/throughput/Client.py')
-rw-r--r--py/demo/Ice/throughput/Client.py336
1 files changed, 160 insertions, 176 deletions
diff --git a/py/demo/Ice/throughput/Client.py b/py/demo/Ice/throughput/Client.py
index 9001b3c4d64..3cf2fa6596b 100644
--- a/py/demo/Ice/throughput/Client.py
+++ b/py/demo/Ice/throughput/Client.py
@@ -35,183 +35,167 @@ s: shutdown server
"?: help
"""
-def run(args, communicator):
- properties = communicator.getProperties()
- proxyProperty = 'Throughput.Throughput'
- proxy = properties.getProperty(proxyProperty)
- if len(proxy) == 0:
- print args[0] + ": property `" + proxyProperty + "' not set"
- return False
-
- base = communicator.stringToProxy(proxy)
- throughput = Demo.ThroughputPrx.checkedCast(base)
- if not throughput:
- print args[0] + ": invalid proxy"
- return False
- throughputOneway = Demo.ThroughputPrx.uncheckedCast(throughput.ice_oneway())
-
- byteSeq = []
- byteSeq[0:Demo.ByteSeqSize] = range(0, Demo.ByteSeqSize)
- byteSeq = [0 for x in byteSeq]
-
- stringSeq = []
- stringSeq[0:Demo.StringSeqSize] = range(0, Demo.StringSeqSize)
- stringSeq = ["hello" for x in stringSeq]
-
- structSeq = []
- structSeq[0:Demo.StringDoubleSeqSize] = range(0, Demo.StringDoubleSeqSize)
- for i in range(0, Demo.StringDoubleSeqSize):
- structSeq[i] = Demo.StringDouble()
- structSeq[i].s = "hello"
- structSeq[i].d = 3.14
-
- fixedSeq = []
- fixedSeq[0:Demo.FixedSeqSize] = range(0, Demo.FixedSeqSize)
- for i in range(0, Demo.FixedSeqSize):
- fixedSeq[i] = Demo.Fixed()
- fixedSeq[i].i = 0
- fixedSeq[i].j = 0
- fixedSeq[i].d = 0.0
-
- menu()
-
- throughput.ice_ping() # Initial ping to setup the connection.
-
- currentType = '1'
- seqSize = Demo.ByteSeqSize
-
- c = None
- while c != 'x':
- try:
- c = raw_input("==> ")
-
- repetitions = 100
-
- if c == '1' or c == '2' or c == '3' or c == '4':
- currentType = c
- if c == '1':
- print "using byte sequences"
- seqSize = Demo.ByteSeqSize
- elif c == '2':
- print "using string sequences"
- seqSize = Demo.StringSeqSize
- elif c == '3':
- print "using variable-length struct sequences"
- seqSize = Demo.StringDoubleSeqSize
- elif c == '4':
- print "using fixed-length struct sequences"
- seqSize = Demo.FixedSeqSize
- elif c == 't' or c == 'o' or c == 'r' or c == 'e':
- if c == 't' or c == 'o':
- print "sending",
- elif c == 'r':
- print "receiving",
- elif c == 'e':
- print "sending and receiving",
-
- print repetitions,
- if currentType == '1':
- print "byte",
- elif currentType == '2':
- print "string",
- elif currentType == '3':
- print "variable-length struct",
- elif currentType == '4':
- print "fixed-length struct",
-
-
- if c == 'o':
- print "sequences of size %d as oneway..." % seqSize
- else:
- print "sequences of size %d..." % seqSize
-
- tsec = time.time()
-
- for i in range(0, repetitions):
+class Client(Ice.Application):
+ def run(self, args):
+ properties = self.communicator().getProperties()
+ proxyProperty = 'Throughput.Throughput'
+ proxy = properties.getProperty(proxyProperty)
+ if len(proxy) == 0:
+ print args[0] + ": property `" + proxyProperty + "' not set"
+ return False
+
+ throughput = Demo.ThroughputPrx.checkedCast(self.communicator().stringToProxy(proxy))
+ if not throughput:
+ print args[0] + ": invalid proxy"
+ return False
+ throughputOneway = Demo.ThroughputPrx.uncheckedCast(throughput.ice_oneway())
+
+ byteSeq = []
+ byteSeq[0:Demo.ByteSeqSize] = range(0, Demo.ByteSeqSize)
+ byteSeq = [0 for x in byteSeq]
+
+ stringSeq = []
+ stringSeq[0:Demo.StringSeqSize] = range(0, Demo.StringSeqSize)
+ stringSeq = ["hello" for x in stringSeq]
+
+ structSeq = []
+ structSeq[0:Demo.StringDoubleSeqSize] = range(0, Demo.StringDoubleSeqSize)
+ for i in range(0, Demo.StringDoubleSeqSize):
+ structSeq[i] = Demo.StringDouble()
+ structSeq[i].s = "hello"
+ structSeq[i].d = 3.14
+
+ fixedSeq = []
+ fixedSeq[0:Demo.FixedSeqSize] = range(0, Demo.FixedSeqSize)
+ for i in range(0, Demo.FixedSeqSize):
+ fixedSeq[i] = Demo.Fixed()
+ fixedSeq[i].i = 0
+ fixedSeq[i].j = 0
+ fixedSeq[i].d = 0.0
+
+ menu()
+
+ throughput.ice_ping() # Initial ping to setup the connection.
+
+ currentType = '1'
+ seqSize = Demo.ByteSeqSize
+
+ c = None
+ while c != 'x':
+ try:
+ c = raw_input("==> ")
+
+ repetitions = 100
+
+ if c == '1' or c == '2' or c == '3' or c == '4':
+ currentType = c
+ if c == '1':
+ print "using byte sequences"
+ seqSize = Demo.ByteSeqSize
+ elif c == '2':
+ print "using string sequences"
+ seqSize = Demo.StringSeqSize
+ elif c == '3':
+ print "using variable-length struct sequences"
+ seqSize = Demo.StringDoubleSeqSize
+ elif c == '4':
+ print "using fixed-length struct sequences"
+ seqSize = Demo.FixedSeqSize
+ elif c == 't' or c == 'o' or c == 'r' or c == 'e':
+ if c == 't' or c == 'o':
+ print "sending",
+ elif c == 'r':
+ print "receiving",
+ elif c == 'e':
+ print "sending and receiving",
+
+ print repetitions,
if currentType == '1':
- if c == 't':
- throughput.sendByteSeq(byteSeq)
- elif c == 'o':
- throughputOneway.sendByteSeq(byteSeq)
- elif c == 'r':
- throughput.recvByteSeq()
- elif c == 'e':
- throughput.echoByteSeq(byteSeq)
+ print "byte",
elif currentType == '2':
- if c == 't':
- throughput.sendStringSeq(stringSeq)
- elif c == 'o':
- throughputOneway.sendStringSeq(stringSeq)
- elif c == 'r':
- throughput.recvStringSeq()
- elif c == 'e':
- throughput.echoStringSeq(stringSeq)
+ print "string",
elif currentType == '3':
- if c == 't':
- throughput.sendStructSeq(structSeq)
- elif c == 'o':
- throughputOneway.sendStructSeq(structSeq)
- elif c == 'r':
- throughput.recvStructSeq()
- elif c == 'e':
- throughput.echoStructSeq(structSeq)
+ print "variable-length struct",
elif currentType == '4':
- if c == 't':
- throughput.sendFixedSeq(fixedSeq)
- elif c == 'o':
- throughputOneway.sendFixedSeq(fixedSeq)
- elif c == 'r':
- throughput.recvFixedSeq()
- elif c == 'e':
- throughput.echoFixedSeq(fixedSeq)
-
- tsec = time.time() - tsec
- tmsec = tsec * 1000.0
- print "time for %d sequences: %.3fms" % (repetitions, tmsec)
- print "time per sequence: %.3fms" % (tmsec / repetitions)
- wireSize = 0
- if currentType == '1':
- wireSize = 1
- elif currentType == '2':
- wireSize = len(stringSeq[0])
- elif currentType == '3':
- wireSize = len(structSeq[0].s)
- wireSize += 8
- elif currentType == '4':
- wireSize = 16
- mbit = repetitions * seqSize * wireSize * 8.0 / tsec / 1000000.0
- if c == 'e':
- mbit = mbit * 2
- print "throughput: %.3f MBit/s" % mbit
- elif c == 's':
- throughput.shutdown()
- elif c == 'x':
- pass # Nothing to do
- elif c == '?':
- menu()
- else:
- print "unknown command `" + c + "'"
- menu()
- except EOFError:
- break
-
- return True
-
-communicator = None
-try:
- properties = Ice.createProperties()
- properties.load("config")
- communicator = Ice.initializeWithProperties(sys.argv, properties)
- status = run(sys.argv, communicator)
-except:
- traceback.print_exc()
- status = False
-
-if communicator:
- try:
- communicator.destroy()
- except:
- traceback.print_exc()
- status = False
-
-sys.exit(not status)
+ print "fixed-length struct",
+
+
+ if c == 'o':
+ print "sequences of size %d as oneway..." % seqSize
+ else:
+ print "sequences of size %d..." % seqSize
+
+ tsec = time.time()
+
+ for i in range(0, repetitions):
+ if currentType == '1':
+ if c == 't':
+ throughput.sendByteSeq(byteSeq)
+ elif c == 'o':
+ throughputOneway.sendByteSeq(byteSeq)
+ elif c == 'r':
+ throughput.recvByteSeq()
+ elif c == 'e':
+ throughput.echoByteSeq(byteSeq)
+ elif currentType == '2':
+ if c == 't':
+ throughput.sendStringSeq(stringSeq)
+ elif c == 'o':
+ throughputOneway.sendStringSeq(stringSeq)
+ elif c == 'r':
+ throughput.recvStringSeq()
+ elif c == 'e':
+ throughput.echoStringSeq(stringSeq)
+ elif currentType == '3':
+ if c == 't':
+ throughput.sendStructSeq(structSeq)
+ elif c == 'o':
+ throughputOneway.sendStructSeq(structSeq)
+ elif c == 'r':
+ throughput.recvStructSeq()
+ elif c == 'e':
+ throughput.echoStructSeq(structSeq)
+ elif currentType == '4':
+ if c == 't':
+ throughput.sendFixedSeq(fixedSeq)
+ elif c == 'o':
+ throughputOneway.sendFixedSeq(fixedSeq)
+ elif c == 'r':
+ throughput.recvFixedSeq()
+ elif c == 'e':
+ throughput.echoFixedSeq(fixedSeq)
+
+ tsec = time.time() - tsec
+ tmsec = tsec * 1000.0
+ print "time for %d sequences: %.3fms" % (repetitions, tmsec)
+ print "time per sequence: %.3fms" % (tmsec / repetitions)
+ wireSize = 0
+ if currentType == '1':
+ wireSize = 1
+ elif currentType == '2':
+ wireSize = len(stringSeq[0])
+ elif currentType == '3':
+ wireSize = len(structSeq[0].s)
+ wireSize += 8
+ elif currentType == '4':
+ wireSize = 16
+ mbit = repetitions * seqSize * wireSize * 8.0 / tsec / 1000000.0
+ if c == 'e':
+ mbit = mbit * 2
+ print "throughput: %.3f MBit/s" % mbit
+ elif c == 's':
+ throughput.shutdown()
+ elif c == 'x':
+ pass # Nothing to do
+ elif c == '?':
+ menu()
+ else:
+ print "unknown command `" + c + "'"
+ menu()
+ except EOFError:
+ break
+
+ return True
+
+app = Client()
+sys.exit(app.main(sys.argv, "config"))