summaryrefslogtreecommitdiff
path: root/cs/demo/Ice/throughput/Client.cs
diff options
context:
space:
mode:
Diffstat (limited to 'cs/demo/Ice/throughput/Client.cs')
-rw-r--r--cs/demo/Ice/throughput/Client.cs693
1 files changed, 351 insertions, 342 deletions
diff --git a/cs/demo/Ice/throughput/Client.cs b/cs/demo/Ice/throughput/Client.cs
index ca763c874fa..32c8fd7bbde 100644
--- a/cs/demo/Ice/throughput/Client.cs
+++ b/cs/demo/Ice/throughput/Client.cs
@@ -7,425 +7,434 @@
//
// **********************************************************************
-using System;
using Demo;
+using System;
+using System.Reflection;
+
+[assembly: CLSCompliant(true)]
-public class Client : Ice.Application
+[assembly: AssemblyTitle("IceThroughputClient")]
+[assembly: AssemblyDescription("Ice throughput demo client")]
+[assembly: AssemblyCompany("ZeroC, Inc.")]
+
+public class Client
{
- private static void menu()
- {
- Console.WriteLine("usage:\n"
- + "\n"
- + "toggle type of data to send:\n"
- + "1: sequence of bytes (default)\n"
- + "2: sequence of strings (\"hello\")\n"
- + "3: sequence of structs with a string (\"hello\") and a double\n"
- + "4: sequence of structs with two ints and a double\n"
- + "\n"
- + "select test to run:\n"
- + "t: Send sequence as twoway\n"
- + "o: Send sequence as oneway\n"
- + "r: Receive sequence\n"
- + "e: Echo (send and receive) sequence\n"
- + "\n"
- + "other commands\n"
- + "s: shutdown server\n"
- + "x: exit\n"
- + "?: help\n");
- }
-
- public override int
- run(string[] args)
+ public class App : Ice.Application
{
- if(args.Length > 0)
+ private static void menu()
{
- Console.Error.WriteLine(appName() + ": too many arguments");
- return 1;
+ Console.WriteLine("usage:\n"
+ + "\n"
+ + "toggle type of data to send:\n"
+ + "1: sequence of bytes (default)\n"
+ + "2: sequence of strings (\"hello\")\n"
+ + "3: sequence of structs with a string (\"hello\") and a double\n"
+ + "4: sequence of structs with two ints and a double\n"
+ + "\n"
+ + "select test to run:\n"
+ + "t: Send sequence as twoway\n"
+ + "o: Send sequence as oneway\n"
+ + "r: Receive sequence\n"
+ + "e: Echo (send and receive) sequence\n"
+ + "\n"
+ + "other commands\n"
+ + "s: shutdown server\n"
+ + "x: exit\n"
+ + "?: help\n");
}
-
- Ice.ObjectPrx b = communicator().propertyToProxy("Throughput.Throughput");
- ThroughputPrx throughput = ThroughputPrxHelper.checkedCast(b);
- if(throughput == null)
+
+ public override int run(string[] args)
{
- Console.Error.WriteLine("invalid proxy");
- return 1;
- }
- ThroughputPrx throughputOneway = ThroughputPrxHelper.uncheckedCast(throughput.ice_oneway());
-
- byte[] byteSeq = new byte[ByteSeqSize.value];
+ if(args.Length > 0)
+ {
+ Console.Error.WriteLine(appName() + ": too many arguments");
+ return 1;
+ }
- string[] stringSeq = new string[StringSeqSize.value];
- for(int i = 0; i < StringSeqSize.value; ++i)
- {
- stringSeq[i] = "hello";
- }
+ Ice.ObjectPrx b = communicator().propertyToProxy("Throughput.Throughput");
+ ThroughputPrx throughput = ThroughputPrxHelper.checkedCast(b);
+ if(throughput == null)
+ {
+ Console.Error.WriteLine("invalid proxy");
+ return 1;
+ }
+ ThroughputPrx throughputOneway = ThroughputPrxHelper.uncheckedCast(throughput.ice_oneway());
- StringDouble[] structSeq = new StringDouble[StringDoubleSeqSize.value];
- for(int i = 0; i < StringDoubleSeqSize.value; ++i)
- {
- structSeq[i] = new StringDouble();
- structSeq[i].s = "hello";
- structSeq[i].d = 3.14;
- }
+ byte[] byteSeq = new byte[ByteSeqSize.value];
- Fixed[] fixedSeq = new Fixed[FixedSeqSize.value];
- for(int i = 0; i < FixedSeqSize.value; ++i)
- {
- fixedSeq[i].i = 0;
- fixedSeq[i].j = 0;
- fixedSeq[i].d = 0;
- }
+ string[] stringSeq = new string[StringSeqSize.value];
+ for(int i = 0; i < StringSeqSize.value; ++i)
+ {
+ stringSeq[i] = "hello";
+ }
- //
- // A method needs to be invoked thousands of times before the
- // JIT compiler will convert it to native code. To ensure an
- // accurate throughput measurement, we need to "warm up" the
- // JIT compiler.
- //
- {
- byte[] emptyBytes = new byte[1];
- string[] emptyStrings = new string[1];
- StringDouble[] emptyStructs = new StringDouble[1];
- emptyStructs[0] = new StringDouble();
- Fixed[] emptyFixed = new Fixed[1];
+ StringDouble[] structSeq = new StringDouble[StringDoubleSeqSize.value];
+ for(int i = 0; i < StringDoubleSeqSize.value; ++i)
+ {
+ structSeq[i] = new StringDouble();
+ structSeq[i].s = "hello";
+ structSeq[i].d = 3.14;
+ }
- throughput.startWarmup();
+ Fixed[] fixedSeq = new Fixed[FixedSeqSize.value];
+ for(int i = 0; i < FixedSeqSize.value; ++i)
+ {
+ fixedSeq[i].i = 0;
+ fixedSeq[i].j = 0;
+ fixedSeq[i].d = 0;
+ }
- Console.Error.Write("warming up the client/server...");
- Console.Error.Flush();
- for(int i = 0; i < 10000; i++)
+ //
+ // A method needs to be invoked thousands of times before the
+ // JIT compiler will convert it to native code. To ensure an
+ // accurate throughput measurement, we need to "warm up" the
+ // JIT compiler.
+ //
{
- throughput.sendByteSeq(emptyBytes);
- throughput.sendStringSeq(emptyStrings);
- throughput.sendStructSeq(emptyStructs);
- throughput.sendFixedSeq(emptyFixed);
+ byte[] emptyBytes = new byte[1];
+ string[] emptyStrings = new string[1];
+ StringDouble[] emptyStructs = new StringDouble[1];
+ emptyStructs[0] = new StringDouble();
+ Fixed[] emptyFixed = new Fixed[1];
- throughput.recvByteSeq();
- throughput.recvStringSeq();
- throughput.recvStructSeq();
- throughput.recvFixedSeq();
+ throughput.startWarmup();
- throughput.echoByteSeq(emptyBytes);
- throughput.echoStringSeq(emptyStrings);
- throughput.echoStructSeq(emptyStructs);
- throughput.echoFixedSeq(emptyFixed);
- }
- throughput.endWarmup();
+ Console.Error.Write("warming up the client/server...");
+ Console.Error.Flush();
+ for(int i = 0; i < 10000; i++)
+ {
+ throughput.sendByteSeq(emptyBytes);
+ throughput.sendStringSeq(emptyStrings);
+ throughput.sendStructSeq(emptyStructs);
+ throughput.sendFixedSeq(emptyFixed);
- Console.Error.WriteLine("ok");
- }
-
- menu();
-
- //
- // By default use byte sequence.
- //
- char currentType = '1';
- int seqSize = ByteSeqSize.value;
+ throughput.recvByteSeq();
+ throughput.recvStringSeq();
+ throughput.recvStructSeq();
+ throughput.recvFixedSeq();
- string line = null;
- do
- {
- try
- {
- Console.Write("==> ");
- Console.Out.Flush();
- line = Console.In.ReadLine();
- if(line == null)
- {
- break;
+ throughput.echoByteSeq(emptyBytes);
+ throughput.echoStringSeq(emptyStrings);
+ throughput.echoStructSeq(emptyStructs);
+ throughput.echoFixedSeq(emptyFixed);
}
+ throughput.endWarmup();
- long tmsec = System.DateTime.Now.Ticks / 10000;
- const int repetitions = 100;
+ Console.Error.WriteLine("ok");
+ }
+
+ menu();
+
+ //
+ // By default use byte sequence.
+ //
+ char currentType = '1';
+ int seqSize = ByteSeqSize.value;
- if(line.Equals("1") || line.Equals("2") || line.Equals("3") || line.Equals("4"))
+ string line = null;
+ do
+ {
+ try
{
- currentType = line[0];
- switch(currentType)
+ Console.Write("==> ");
+ Console.Out.Flush();
+ line = Console.In.ReadLine();
+ if(line == null)
{
- case '1':
- {
- Console.WriteLine("using byte sequences");
- seqSize = ByteSeqSize.value;
- break;
- }
- case '2':
- {
- Console.WriteLine("using string sequences");
- seqSize = StringSeqSize.value;
- break;
- }
- case '3':
- {
- Console.WriteLine("using variable-length struct sequences");
- seqSize = StringDoubleSeqSize.value;
- break;
- }
- case '4':
- {
- Console.WriteLine("using fixed-length struct sequences");
- seqSize = FixedSeqSize.value;
- break;
- }
- }
- }
- else if(line.Equals("t") || line.Equals("o") || line.Equals("r") || line.Equals("e"))
- {
- char c = line[0];
- switch (c)
- {
- case 't':
- {
- Console.Write("sending");
- break;
- }
- case 'o':
- {
- Console.Write("sending");
- break;
- }
- case 'r':
- {
- Console.Write("receiving");
- break;
- }
- case 'e':
- {
- Console.Write("sending and receiving");
- break;
- }
+ break;
}
-
- Console.Write(" " + repetitions);
- switch(currentType)
+
+ long tmsec = System.DateTime.Now.Ticks / 10000;
+ const int repetitions = 100;
+
+ if(line.Equals("1") || line.Equals("2") || line.Equals("3") || line.Equals("4"))
{
- case '1':
- {
- Console.Write(" byte");
- break;
- }
- case '2':
+ currentType = line[0];
+ switch(currentType)
{
- Console.Write(" string");
- break;
+ case '1':
+ {
+ Console.WriteLine("using byte sequences");
+ seqSize = ByteSeqSize.value;
+ break;
+ }
+ case '2':
+ {
+ Console.WriteLine("using string sequences");
+ seqSize = StringSeqSize.value;
+ break;
+ }
+ case '3':
+ {
+ Console.WriteLine("using variable-length struct sequences");
+ seqSize = StringDoubleSeqSize.value;
+ break;
+ }
+ case '4':
+ {
+ Console.WriteLine("using fixed-length struct sequences");
+ seqSize = FixedSeqSize.value;
+ break;
+ }
+ }
+ }
+ else if(line.Equals("t") || line.Equals("o") || line.Equals("r") || line.Equals("e"))
+ {
+ char c = line[0];
+ switch (c)
+ {
+ case 't':
+ {
+ Console.Write("sending");
+ break;
+ }
+ case 'o':
+ {
+ Console.Write("sending");
+ break;
+ }
+ case 'r':
+ {
+ Console.Write("receiving");
+ break;
+ }
+ case 'e':
+ {
+ Console.Write("sending and receiving");
+ break;
+ }
}
- case '3':
+
+ Console.Write(" " + repetitions);
+ switch(currentType)
{
- Console.Write(" variable-length struct");
- break;
+ case '1':
+ {
+ Console.Write(" byte");
+ break;
+ }
+ case '2':
+ {
+ Console.Write(" string");
+ break;
+ }
+ case '3':
+ {
+ Console.Write(" variable-length struct");
+ break;
+ }
+ case '4':
+ {
+ Console.Write(" fixed-length struct");
+ break;
+ }
}
- case '4':
+ Console.Write(" sequences of size " + seqSize);
+
+ if(c == 'o')
{
- Console.Write(" fixed-length struct");
- break;
+ Console.Write(" as oneway");
}
- }
- Console.Write(" sequences of size " + seqSize);
-
- if(c == 'o')
- {
- Console.Write(" as oneway");
- }
-
- Console.WriteLine("...");
-
- for (int i = 0; i < repetitions; ++i)
- {
- switch(currentType)
+
+ Console.WriteLine("...");
+
+ for (int i = 0; i < repetitions; ++i)
{
- case '1':
+ switch(currentType)
{
- switch(c)
+ case '1':
{
- case 't':
+ switch(c)
{
- throughput.sendByteSeq(byteSeq);
- break;
- }
+ case 't':
+ {
+ throughput.sendByteSeq(byteSeq);
+ break;
+ }
- case 'o':
- {
- throughputOneway.sendByteSeq(byteSeq);
- break;
- }
+ case 'o':
+ {
+ throughputOneway.sendByteSeq(byteSeq);
+ break;
+ }
- case 'r':
- {
- throughput.recvByteSeq();
- break;
- }
-
- case 'e':
- {
- throughput.echoByteSeq(byteSeq);
- break;
+ case 'r':
+ {
+ throughput.recvByteSeq();
+ break;
+ }
+
+ case 'e':
+ {
+ throughput.echoByteSeq(byteSeq);
+ break;
+ }
}
+ break;
}
- break;
- }
- case '2':
- {
- switch(c)
+ case '2':
{
- case 't':
+ switch(c)
{
- throughput.sendStringSeq(stringSeq);
- break;
- }
+ case 't':
+ {
+ throughput.sendStringSeq(stringSeq);
+ break;
+ }
- case 'o':
- {
- throughputOneway.sendStringSeq(stringSeq);
- break;
- }
+ case 'o':
+ {
+ throughputOneway.sendStringSeq(stringSeq);
+ break;
+ }
- case 'r':
- {
- throughput.recvStringSeq();
- break;
- }
-
- case 'e':
- {
- throughput.echoStringSeq(stringSeq);
- break;
+ case 'r':
+ {
+ throughput.recvStringSeq();
+ break;
+ }
+
+ case 'e':
+ {
+ throughput.echoStringSeq(stringSeq);
+ break;
+ }
}
+ break;
}
- break;
- }
-
- case '3':
- {
- switch(c)
+
+ case '3':
{
- case 't':
+ switch(c)
{
- throughput.sendStructSeq(structSeq);
- break;
- }
+ case 't':
+ {
+ throughput.sendStructSeq(structSeq);
+ break;
+ }
- case 'o':
- {
- throughputOneway.sendStructSeq(structSeq);
- break;
- }
+ case 'o':
+ {
+ throughputOneway.sendStructSeq(structSeq);
+ break;
+ }
- case 'r':
- {
- throughput.recvStructSeq();
- break;
- }
-
- case 'e':
- {
- throughput.echoStructSeq(structSeq);
- break;
+ case 'r':
+ {
+ throughput.recvStructSeq();
+ break;
+ }
+
+ case 'e':
+ {
+ throughput.echoStructSeq(structSeq);
+ break;
+ }
}
+ break;
}
- break;
- }
- case '4':
- {
- switch(c)
+ case '4':
{
- case 't':
+ switch(c)
{
- throughput.sendFixedSeq(fixedSeq);
- break;
- }
+ case 't':
+ {
+ throughput.sendFixedSeq(fixedSeq);
+ break;
+ }
- case 'o':
- {
- throughputOneway.sendFixedSeq(fixedSeq);
- break;
- }
+ case 'o':
+ {
+ throughputOneway.sendFixedSeq(fixedSeq);
+ break;
+ }
- case 'r':
- {
- throughput.recvFixedSeq();
- break;
- }
-
- case 'e':
- {
- throughput.echoFixedSeq(fixedSeq);
- break;
+ case 'r':
+ {
+ throughput.recvFixedSeq();
+ break;
+ }
+
+ case 'e':
+ {
+ throughput.echoFixedSeq(fixedSeq);
+ break;
+ }
}
+ break;
}
- break;
}
}
- }
-
- double dmsec = System.DateTime.Now.Ticks / 10000 - tmsec;
- Console.WriteLine("time for " + repetitions + " sequences: " + dmsec.ToString("F") + "ms");
- Console.WriteLine("time per sequence: " + ((double)(dmsec / repetitions)).ToString("F") + "ms");
- int wireSize = 0;
- switch(currentType)
- {
- case '1':
- {
- wireSize = 1;
- break;
- }
- case '2':
- {
- wireSize = stringSeq[0].Length;
- break;
- }
- case '3':
+
+ double dmsec = System.DateTime.Now.Ticks / 10000 - tmsec;
+ Console.WriteLine("time for " + repetitions + " sequences: " + dmsec.ToString("F") + "ms");
+ Console.WriteLine("time per sequence: " + ((double)(dmsec / repetitions)).ToString("F") + "ms");
+ int wireSize = 0;
+ switch(currentType)
{
- wireSize = structSeq[0].s.Length;
- wireSize += 8; // Size of double on the wire.
- break;
+ case '1':
+ {
+ wireSize = 1;
+ break;
+ }
+ case '2':
+ {
+ wireSize = stringSeq[0].Length;
+ break;
+ }
+ case '3':
+ {
+ wireSize = structSeq[0].s.Length;
+ wireSize += 8; // Size of double on the wire.
+ break;
+ }
+ case '4':
+ {
+ wireSize = 16; // Sizes of two ints and a double on the wire.
+ break;
+ }
}
- case '4':
+ double mbit = repetitions * seqSize * wireSize * 8.0 / dmsec / 1000.0;
+ if(c == 'e')
{
- wireSize = 16; // Sizes of two ints and a double on the wire.
- break;
+ mbit *= 2;
}
+ Console.WriteLine("throughput: " + mbit.ToString("#.##") + "Mbps");
}
- double mbit = repetitions * seqSize * wireSize * 8.0 / dmsec / 1000.0;
- if(c == 'e')
+ else if(line.Equals("s"))
{
- mbit *= 2;
+ throughput.shutdown();
+ }
+ else if(line.Equals("x"))
+ {
+ // Nothing to do
+ }
+ else if(line.Equals("?"))
+ {
+ menu();
+ }
+ else
+ {
+ Console.WriteLine("unknown command `" + line + "'");
+ menu();
}
- Console.WriteLine("throughput: " + mbit.ToString("#.##") + "Mbps");
- }
- else if(line.Equals("s"))
- {
- throughput.shutdown();
- }
- else if(line.Equals("x"))
- {
- // Nothing to do
- }
- else if(line.Equals("?"))
- {
- menu();
}
- else
+ catch(System.Exception ex)
{
- Console.WriteLine("unknown command `" + line + "'");
- menu();
+ Console.Error.WriteLine(ex);
}
}
- catch(System.Exception ex)
- {
- Console.Error.WriteLine(ex);
- }
+ while(!line.Equals("x"));
+
+ return 0;
}
- while(!line.Equals("x"));
-
- return 0;
}
public static void Main(string[] args)
{
- Client app = new Client();
+ App app = new App();
int status = app.main(args, "config.client");
if(status != 0)
{