00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 / I assume here that repeatedly executing 2+2 on the server is a reasonable
00013 / benchmark to see the latency of the calls.
00014
00015
00016 benchmark : {[]
00017 2+2;
00018 }
00019
00020
00021 iterations : 10000
00022
00023
00024 port : 5000
00025
00026
00027
00028
00029 echo : {[val]
00030 $[10h=type val; -1 val; -1 (string val)]
00031 }
00032
00033
00034
00035
00036
00037
00038
00039 asDestination : {[host;port]
00040 hsym `$(":", host, ":", string port)
00041 }
00042
00043
00044
00045
00046
00047
00048 asFile : {[filename]
00049 hsym `$(":", filename)
00050 }
00051
00052
00053 argv : .z.x
00054
00055
00056 argc : count .z.x
00057
00058
00059
00060 argvAsDictionary : .Q.opt .z.x
00061
00062
00063
00064
00065
00066 haveArgument : {[arg]
00067 arg in key argvAsDictionary
00068 }
00069
00070 / Check that we have at least one of remote and server flags. If not
00071 / print usage and exit.
00072 if [(not haveArgument[`remote]) and (not haveArgument[`server]);
00073 echo "Usage: q cisco.q (-remote hostname | -server) [-port number] [-iterations number] [-save run.log] [-exit]";
00074 exit 1;
00075 ]
00076
00077 / Override the default port if we are passed one.
00078 if [haveArgument[`port];
00079 port : value first argvAsDictionary[`port]
00080 ]
00081
00082 / Start listening on the port if we're the server
00083 if [haveArgument[`server];
00084 system ("p ", string port)
00085 ]
00086
00087 / Override the number of iterations to execute if we are passed one.
00088 if [haveArgument[`iterations];
00089 iterations : value first argvAsDictionary[`iterations];
00090 ]
00091
00092 // Performs an RPC call to execute one call to the benchmark function.
00093 //
00094 // @param handle an open handle to the remote server
00095 // @return returns whatever the benchmark server returns
00096 rpcOnce : {[handle]
00097 handle["benchmark[]"]
00098 }
00099
00100 // Try to connect to the remote server on the given port. If we fail, then complain
00101 // and exit.
00102 //
00103 // @param server The server to connect to
00104 // @param port The port on which to connect
00105 // @return The open connection handle
00106 createHandleOrDie : {[server; port]
00107 host : asDestination[server;port];
00108 @[hopen; host; {echo "Could not connect to server; exiting."; exit -1;}]
00109 }
00110
00111 // A function to open a connection to the server and execute 'iterations' number
00112 // of RPC calls to the server. Save the timing data in the log file if requested.
00113 executeRemoteCalls : {[]
00114 server :: first argvAsDictionary[`remote];
00115 handle :: createHandleOrDie[server; port];
00116 time : system ("t do[iterations; rpcOnce[handle]]");
00117 averageTime : time % iterations;
00118 if [haveArgument[`save];
00119 filename : first argvAsDictionary[`save];
00120 file : hopen (asFile filename);
00121 file ((string .z.z), ",", (string iterations), ",", (string averageTime), "\n");
00122 ]
00123 }
00124
00125 / If we're the client, make the RPC calls.
00126 if [haveArgument[`remote];
00127 executeRemoteCalls[]
00128 ]
00129
00130 / Exit if requested.
00131 if [haveArgument[`exit];
00132 exit 1
00133 ]