1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
#!/usr/bin/env python
# **********************************************************************
#
# Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved.
#
# This copy of Ice is licensed to you under the terms described in the
# ICE_LICENSE file included in this distribution.
#
# **********************************************************************
import sys, time, traceback, Ice
Ice.loadSlice('Throughput.ice')
import Demo
def menu():
print("""
usage:
toggle type of data to send:
1: sequence of bytes (default)
2: sequence of strings (\"hello\")
3: sequence of structs with a string (\"hello\") and a double
4: sequence of structs with two ints and a double
select test to run:
t: Send sequence as twoway
o: Send sequence as oneway
r: Receive sequence
e: Echo (send and receive) sequence
other commands:
s: shutdown server
x: exit
?: help
""")
class Client(Ice.Application):
def run(self, args):
if len(args) > 1:
print(self.appName() + ": too many arguments")
return 1
throughput = Demo.ThroughputPrx.checkedCast(self.communicator().propertyToProxy('Throughput.Proxy'))
if not throughput:
print(args[0] + ": invalid proxy")
return 1
throughputOneway = Demo.ThroughputPrx.uncheckedCast(throughput.ice_oneway())
byteSeq = bytearray(Demo.ByteSeqSize)
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
#
# To allow cross-language tests we may need to "warm up" the
# server. The warm up is to ensure that any JIT compiler will
# have converted any hotspots to native code. This ensures an
# accurate throughput measurement.
#
if throughput.needsWarmup():
throughput.startWarmup()
emptyBytes = [ '\x00' ]
emptyBytes = ''.join(emptyBytes)
emptyStrings = [ "" ]
emptyStructs = [ Demo.StringDouble() ]
emptyFixed = [ Demo.Fixed() ]
print("warming up the server...",)
sys.stdout.flush()
for i in range(0, 10000):
throughput.sendByteSeq(emptyBytes)
throughput.sendStringSeq(emptyStrings)
throughput.sendStructSeq(emptyStructs)
throughput.sendFixedSeq(emptyFixed)
throughput.recvByteSeq()
throughput.recvStringSeq()
throughput.recvStructSeq()
throughput.recvFixedSeq()
throughput.echoByteSeq(emptyBytes)
throughput.echoStringSeq(emptyStrings)
throughput.echoStructSeq(emptyStructs)
throughput.echoFixedSeq(emptyFixed)
throughput.endWarmup()
print("ok")
else:
throughput.ice_ping() # Initial ping to setup the connection.
menu()
currentType = '1'
seqSize = Demo.ByteSeqSize
c = None
while c != 'x':
try:
sys.stdout.write("==> ")
sys.stdout.flush()
c = sys.stdin.readline().strip()
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':
sys.stdout.write("sending ")
elif c == 'r':
sys.stdout.write("receiving ")
elif c == 'e':
sys.stdout.write("sending and receiving ")
sys.stdout.write(str(repetitions) + " ")
if currentType == '1':
sys.stdout.write("byte ")
elif currentType == '2':
sys.stdout.write("string ")
elif currentType == '3':
sys.stdout.write("variable-length struct ")
elif currentType == '4':
sys.stdout.write("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: %.3fMbps" % 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
except KeyboardInterrupt:
break
return 0
app = Client()
sys.exit(app.main(sys.argv, "config.client"))
|