Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 1 | #include <concurrency/ThreadManager.h> |
| 2 | #include <concurrency/PosixThreadFactory.h> |
| 3 | #include <concurrency/Monitor.h> |
| 4 | #include <concurrency/Util.h> |
| 5 | #include <protocol/TBinaryProtocol.h> |
| 6 | #include <server/TSimpleServer.h> |
| 7 | #include <server/TThreadPoolServer.h> |
| 8 | #include <transport/TServerSocket.h> |
| 9 | #include <transport/TSocket.h> |
| 10 | #include <transport/TBufferedTransport.h> |
| 11 | #include "StressTest.h" |
| 12 | |
| 13 | #include <iostream> |
| 14 | #include <set> |
| 15 | #include <stdexcept> |
| 16 | #include <sstream> |
| 17 | |
| 18 | using namespace std; |
| 19 | |
| 20 | using namespace facebook::thrift; |
| 21 | using namespace facebook::thrift::protocol; |
| 22 | using namespace facebook::thrift::transport; |
| 23 | using namespace facebook::thrift::server; |
| 24 | |
| 25 | using namespace test::stress; |
| 26 | |
| 27 | class Server : public ServiceServerIf { |
| 28 | public: |
| 29 | Server(shared_ptr<TProtocol> protocol) : |
| 30 | ServiceServerIf(protocol) {} |
| 31 | |
| 32 | void echoVoid() {return;} |
| 33 | uint8_t echoByte(uint8_t arg) {return arg;} |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 34 | int16_t echoI16(int16_t arg) {return arg;} |
| 35 | int32_t echoI32(int32_t arg) {return arg;} |
| 36 | int64_t echoI64(int64_t arg) {return arg;} |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 37 | uint16_t echoU16(uint16_t arg) {return arg;} |
| 38 | uint32_t echoU32(uint32_t arg) {return arg;} |
| 39 | uint64_t echoU64(uint64_t arg) {return arg;} |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 40 | string echoString(string arg) {return arg;} |
| 41 | list<uint8_t> echoList(list<uint8_t> arg) {return arg;} |
| 42 | set<uint8_t> echoSet(set<uint8_t> arg) {return arg;} |
| 43 | map<uint8_t, uint8_t> echoMap(map<uint8_t, uint8_t> arg) {return arg;} |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | class ClientThread: public Runnable { |
| 47 | public: |
| 48 | |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 49 | ClientThread(shared_ptr<TTransport>transport, shared_ptr<ServiceClient> client, Monitor& monitor, size_t& workerCount, size_t loopCount, TType loopType) : |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 50 | _transport(transport), |
| 51 | _client(client), |
| 52 | _monitor(monitor), |
| 53 | _workerCount(workerCount), |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 54 | _loopCount(loopCount), |
| 55 | _loopType(loopType) |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 56 | {} |
| 57 | |
| 58 | void run() { |
| 59 | |
| 60 | // Wait for all worker threads to start |
| 61 | |
| 62 | {Synchronized s(_monitor); |
| 63 | while(_workerCount == 0) { |
| 64 | _monitor.wait(); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | _startTime = Util::currentTime(); |
| 69 | |
| 70 | _transport->open(); |
| 71 | |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 72 | switch(_loopType) { |
| 73 | case T_VOID: loopEchoVoid(); break; |
| 74 | case T_BYTE: loopEchoByte(); break; |
| 75 | case T_I16: loopEchoI16(); break; |
| 76 | case T_I32: loopEchoI32(); break; |
| 77 | case T_I64: loopEchoI64(); break; |
| 78 | case T_U16: loopEchoU16(); break; |
| 79 | case T_U32: loopEchoU32(); break; |
| 80 | case T_U64: loopEchoU64(); break; |
| 81 | case T_STRING: loopEchoString(); break; |
| 82 | default: cerr << "Unexpected loop type" << _loopType << endl; break; |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | _endTime = Util::currentTime(); |
| 86 | |
| 87 | _transport->close(); |
| 88 | |
| 89 | _done = true; |
| 90 | |
| 91 | {Synchronized s(_monitor); |
| 92 | |
| 93 | _workerCount--; |
Marc Slemko | 056f9ba | 2006-08-17 02:59:05 +0000 | [diff] [blame] | 94 | |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 95 | if(_workerCount == 0) { |
| 96 | |
| 97 | _monitor.notify(); |
| 98 | } |
| 99 | } |
| 100 | } |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 101 | |
| 102 | void loopEchoVoid() { |
| 103 | for(size_t ix = 0; ix < _loopCount; ix++) { |
| 104 | _client->echoVoid(); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | void loopEchoByte() { |
| 109 | for(size_t ix = 0; ix < _loopCount; ix++) { |
| 110 | uint8_t arg = 1; |
| 111 | uint8_t result; |
| 112 | result =_client->echoByte(arg); |
| 113 | assert(result == arg); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | void loopEchoI16() { |
| 118 | for(size_t ix = 0; ix < _loopCount; ix++) { |
| 119 | uint16_t arg = 1; |
| 120 | uint16_t result; |
| 121 | result =_client->echoI16(arg); |
| 122 | assert(result == arg); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | void loopEchoI32() { |
| 127 | for(size_t ix = 0; ix < _loopCount; ix++) { |
| 128 | uint32_t arg = 1; |
| 129 | uint32_t result; |
| 130 | result =_client->echoI32(arg); |
| 131 | assert(result == arg); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | void loopEchoI64() { |
| 136 | for(size_t ix = 0; ix < _loopCount; ix++) { |
| 137 | uint64_t arg = 1; |
| 138 | uint64_t result; |
| 139 | result =_client->echoI64(arg); |
| 140 | assert(result == arg); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | void loopEchoU16() { |
| 145 | for(size_t ix = 0; ix < _loopCount; ix++) { |
| 146 | uint16_t arg = 1; |
| 147 | uint16_t result; |
| 148 | result =_client->echoU16(arg); |
| 149 | assert(result == arg); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | void loopEchoU32() { |
| 154 | for(size_t ix = 0; ix < _loopCount; ix++) { |
| 155 | uint32_t arg = 1; |
| 156 | uint32_t result; |
| 157 | result =_client->echoU32(arg); |
| 158 | assert(result == arg); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | void loopEchoU64() { |
| 163 | for(size_t ix = 0; ix < _loopCount; ix++) { |
| 164 | uint64_t arg = 1; |
| 165 | uint64_t result; |
| 166 | result =_client->echoU64(arg); |
| 167 | assert(result == arg); |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | void loopEchoString() { |
| 172 | for(size_t ix = 0; ix < _loopCount; ix++) { |
| 173 | string arg = "hello"; |
| 174 | string result; |
| 175 | result =_client->echoString(arg); |
| 176 | assert(result == arg); |
| 177 | } |
| 178 | } |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 179 | |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 180 | shared_ptr<TTransport> _transport; |
| 181 | shared_ptr<ServiceClient> _client; |
| 182 | Monitor& _monitor; |
| 183 | size_t& _workerCount; |
| 184 | size_t _loopCount; |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 185 | TType _loopType; |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 186 | long long _startTime; |
| 187 | long long _endTime; |
| 188 | bool _done; |
| 189 | Monitor _sleep; |
| 190 | }; |
| 191 | |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 192 | int main(int argc, char **argv) { |
| 193 | |
| 194 | int port = 9090; |
| 195 | string serverType = "thread-pool"; |
| 196 | string protocolType = "binary"; |
| 197 | size_t workerCount = 4; |
| 198 | size_t clientCount = 10; |
| 199 | size_t loopCount = 10000; |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 200 | TType loopType = T_VOID; |
| 201 | string callName = "echoVoid"; |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 202 | bool runServer = true; |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 203 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 204 | ostringstream usage; |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 205 | |
| 206 | usage << |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 207 | argv[0] << " [--port=<port number>] [--server] [--server-type=<server-type>] [--protocol-type=<protocol-type>] [--workers=<worker-count>] [--clients=<client-count>] [--loop=<loop-count>]" << endl << |
| 208 | "\tclients Number of client threads to create - 0 implies no clients, i.e. server only. Default is " << clientCount << endl << |
| 209 | "\thelp Prints this help text." << endl << |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 210 | "\tcall Service method to call. Default is " << callName << endl << |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 211 | "\tloop The number of remote thrift calls each client makes. Default is " << loopCount << endl << |
| 212 | "\tport The port the server and clients should bind to for thrift network connections. Default is " << port << endl << |
| 213 | "\tserver Run the Thrift server in this process. Default is " << runServer << endl << |
| 214 | "\tserver-type Type of server, \"simple\" or \"thread-pool\". Default is " << serverType << endl << |
| 215 | "\tprotocol-type Type of protocol, \"binary\", \"ascii\", or \"xml\". Default is " << protocolType << endl << |
| 216 | "\tworkers Number of thread pools workers. Only valid for thread-pool server type. Default is " << workerCount << endl; |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 217 | |
| 218 | map<string, string> args; |
| 219 | |
| 220 | for(int ix = 1; ix < argc; ix++) { |
| 221 | |
| 222 | string arg(argv[ix]); |
| 223 | |
| 224 | if(arg.compare(0,2, "--") == 0) { |
| 225 | |
| 226 | size_t end = arg.find_first_of("=", 2); |
| 227 | |
Marc Slemko | 056f9ba | 2006-08-17 02:59:05 +0000 | [diff] [blame] | 228 | string key = string(arg, 2, end - 2); |
| 229 | |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 230 | if(end != string::npos) { |
Marc Slemko | 056f9ba | 2006-08-17 02:59:05 +0000 | [diff] [blame] | 231 | args[key] = string(arg, end + 1); |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 232 | } else { |
Marc Slemko | 056f9ba | 2006-08-17 02:59:05 +0000 | [diff] [blame] | 233 | args[key] = "true"; |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 234 | } |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 235 | } else { |
| 236 | throw invalid_argument("Unexcepted command line token: "+arg); |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | try { |
| 241 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 242 | if(!args["clients"].empty()) { |
| 243 | clientCount = atoi(args["clients"].c_str()); |
| 244 | } |
| 245 | |
| 246 | if(!args["help"].empty()) { |
| 247 | cerr << usage.str(); |
| 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | if(!args["loop"].empty()) { |
| 252 | loopCount = atoi(args["loop"].c_str()); |
| 253 | } |
| 254 | |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 255 | if(!args["call"].empty()) { |
| 256 | callName = args["call"]; |
| 257 | } |
| 258 | |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 259 | if(!args["port"].empty()) { |
| 260 | port = atoi(args["port"].c_str()); |
| 261 | } |
| 262 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 263 | if(!args["server"].empty()) { |
| 264 | runServer = args["server"] == "true"; |
| 265 | } |
| 266 | |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 267 | if(!args["server-type"].empty()) { |
| 268 | serverType = args["server-type"]; |
| 269 | |
| 270 | if(serverType == "simple") { |
| 271 | |
| 272 | } else if(serverType == "thread-pool") { |
| 273 | |
| 274 | } else { |
| 275 | |
| 276 | throw invalid_argument("Unknown server type "+serverType); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | if(!args["workers"].empty()) { |
| 281 | workerCount = atoi(args["workers"].c_str()); |
| 282 | } |
| 283 | |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 284 | } catch(exception& e) { |
| 285 | cerr << e.what() << endl; |
| 286 | cerr << usage; |
| 287 | } |
| 288 | |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 289 | shared_ptr<PosixThreadFactory> threadFactory = shared_ptr<PosixThreadFactory>(new PosixThreadFactory()); |
| 290 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 291 | if(runServer) { |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 292 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 293 | // Dispatcher |
| 294 | shared_ptr<TBinaryProtocol> binaryProtocol(new TBinaryProtocol); |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 295 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 296 | shared_ptr<Server> server(new Server(binaryProtocol)); |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 297 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 298 | // Options |
| 299 | shared_ptr<TServerOptions> serverOptions(new TServerOptions()); |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 300 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 301 | // Transport |
| 302 | shared_ptr<TServerSocket> serverSocket(new TServerSocket(port)); |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 303 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 304 | // ThreadFactory |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 305 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 306 | shared_ptr<Thread> serverThread; |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 307 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 308 | if(serverType == "simple") { |
| 309 | |
| 310 | serverThread = threadFactory->newThread(shared_ptr<Runnable>(new TSimpleServer(server, serverOptions, serverSocket))); |
| 311 | |
| 312 | } else if(serverType == "thread-pool") { |
| 313 | |
| 314 | shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(workerCount); |
| 315 | |
| 316 | threadManager->threadFactory(threadFactory); |
| 317 | |
| 318 | threadManager->start(); |
| 319 | |
| 320 | serverThread = threadFactory->newThread(shared_ptr<TServer>(new TThreadPoolServer(server, |
| 321 | serverOptions, |
| 322 | serverSocket, |
| 323 | threadManager))); |
| 324 | } |
| 325 | |
| 326 | cerr << "Starting the server on port " << port << endl; |
| 327 | |
| 328 | serverThread->start(); |
| 329 | |
| 330 | // If we aren't running clients, just wait forever for external clients |
| 331 | |
| 332 | if(clientCount == 0) { |
| 333 | serverThread->join(); |
| 334 | } |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 335 | } |
| 336 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 337 | if(clientCount > 0) { |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 338 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 339 | Monitor monitor; |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 340 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 341 | size_t threadCount = 0; |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 342 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 343 | set<shared_ptr<Thread> > clientThreads; |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 344 | |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 345 | if(callName == "echoVoid") { loopType = T_VOID;} |
| 346 | else if(callName == "echoByte") { loopType = T_BYTE;} |
| 347 | else if(callName == "echoI16") { loopType = T_I16;} |
| 348 | else if(callName == "echoI32") { loopType = T_I32;} |
| 349 | else if(callName == "echoI64") { loopType = T_I64;} |
| 350 | else if(callName == "echoU16") { loopType = T_U16;} |
| 351 | else if(callName == "echoU32") { loopType = T_U32;} |
| 352 | else if(callName == "echoU64") { loopType = T_U64;} |
| 353 | else if(callName == "echoString") { loopType = T_STRING;} |
| 354 | else {throw invalid_argument("Unknown service call "+callName);} |
| 355 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 356 | for(size_t ix = 0; ix < clientCount; ix++) { |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 357 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 358 | shared_ptr<TSocket> socket(new TSocket("127.0.01", port)); |
| 359 | shared_ptr<TBufferedTransport> bufferedSocket(new TBufferedTransport(socket, 2048)); |
| 360 | shared_ptr<TBinaryProtocol> binaryProtocol(new TBinaryProtocol()); |
| 361 | shared_ptr<ServiceClient> serviceClient(new ServiceClient(bufferedSocket, binaryProtocol)); |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 362 | |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 363 | clientThreads.insert(threadFactory->newThread(shared_ptr<ClientThread>(new ClientThread(bufferedSocket, serviceClient, monitor, threadCount, loopCount, loopType)))); |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 364 | } |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 365 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 366 | for(std::set<shared_ptr<Thread> >::const_iterator thread = clientThreads.begin(); thread != clientThreads.end(); thread++) { |
| 367 | (*thread)->start(); |
| 368 | } |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 369 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 370 | long long time00; |
| 371 | long long time01; |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 372 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 373 | {Synchronized s(monitor); |
| 374 | threadCount = clientCount; |
Marc Slemko | 056f9ba | 2006-08-17 02:59:05 +0000 | [diff] [blame] | 375 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 376 | cerr << "Launch "<< clientCount << " client threads" << endl; |
Marc Slemko | 056f9ba | 2006-08-17 02:59:05 +0000 | [diff] [blame] | 377 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 378 | time00 = Util::currentTime(); |
Marc Slemko | 056f9ba | 2006-08-17 02:59:05 +0000 | [diff] [blame] | 379 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 380 | monitor.notifyAll(); |
| 381 | |
| 382 | while(threadCount > 0) { |
| 383 | monitor.wait(); |
| 384 | } |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 385 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 386 | time01 = Util::currentTime(); |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 387 | } |
Marc Slemko | 056f9ba | 2006-08-17 02:59:05 +0000 | [diff] [blame] | 388 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 389 | long long firstTime = 9223372036854775807LL; |
| 390 | long long lastTime = 0; |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 391 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 392 | double averageTime = 0; |
| 393 | long long minTime = 9223372036854775807LL; |
| 394 | long long maxTime = 0; |
Marc Slemko | 056f9ba | 2006-08-17 02:59:05 +0000 | [diff] [blame] | 395 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 396 | for(set<shared_ptr<Thread> >::iterator ix = clientThreads.begin(); ix != clientThreads.end(); ix++) { |
Marc Slemko | 056f9ba | 2006-08-17 02:59:05 +0000 | [diff] [blame] | 397 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 398 | shared_ptr<ClientThread> client = dynamic_pointer_cast<ClientThread>((*ix)->runnable()); |
Marc Slemko | 056f9ba | 2006-08-17 02:59:05 +0000 | [diff] [blame] | 399 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 400 | long long delta = client->_endTime - client->_startTime; |
Marc Slemko | 056f9ba | 2006-08-17 02:59:05 +0000 | [diff] [blame] | 401 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 402 | assert(delta > 0); |
Marc Slemko | 056f9ba | 2006-08-17 02:59:05 +0000 | [diff] [blame] | 403 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 404 | if(client->_startTime < firstTime) { |
| 405 | firstTime = client->_startTime; |
| 406 | } |
Marc Slemko | 056f9ba | 2006-08-17 02:59:05 +0000 | [diff] [blame] | 407 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 408 | if(client->_endTime > lastTime) { |
| 409 | lastTime = client->_endTime; |
| 410 | } |
Marc Slemko | 056f9ba | 2006-08-17 02:59:05 +0000 | [diff] [blame] | 411 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 412 | if(delta < minTime) { |
| 413 | minTime = delta; |
| 414 | } |
Marc Slemko | 056f9ba | 2006-08-17 02:59:05 +0000 | [diff] [blame] | 415 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 416 | if(delta > maxTime) { |
| 417 | maxTime = delta; |
| 418 | } |
Marc Slemko | 056f9ba | 2006-08-17 02:59:05 +0000 | [diff] [blame] | 419 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 420 | averageTime+= delta; |
| 421 | } |
| 422 | |
| 423 | averageTime /= clientCount; |
| 424 | |
| 425 | |
| 426 | cout << "workers :" << workerCount << ", client : " << clientCount << ", loops : " << loopCount << ", rate : " << (clientCount * loopCount * 1000) / ((double)(time01 - time00)) << endl; |
| 427 | |
| 428 | cerr << "done." << endl; |
Marc Slemko | 056f9ba | 2006-08-17 02:59:05 +0000 | [diff] [blame] | 429 | } |
Marc Slemko | 056f9ba | 2006-08-17 02:59:05 +0000 | [diff] [blame] | 430 | |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 431 | return 0; |
| 432 | } |