David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | |
Roger Meier | 49ff8b1 | 2012-04-13 09:12:31 +0000 | [diff] [blame] | 20 | #include <thrift/concurrency/ThreadManager.h> |
| 21 | #include <thrift/concurrency/PlatformThreadFactory.h> |
| 22 | #include <thrift/concurrency/Monitor.h> |
| 23 | #include <thrift/concurrency/Util.h> |
| 24 | #include <thrift/concurrency/Mutex.h> |
| 25 | #include <thrift/protocol/TBinaryProtocol.h> |
| 26 | #include <thrift/server/TSimpleServer.h> |
| 27 | #include <thrift/server/TThreadPoolServer.h> |
| 28 | #include <thrift/server/TThreadedServer.h> |
| 29 | #include <thrift/transport/TServerSocket.h> |
| 30 | #include <thrift/transport/TSocket.h> |
| 31 | #include <thrift/transport/TTransportUtils.h> |
| 32 | #include <thrift/transport/TFileTransport.h> |
Roger Meier | 33eaa0f | 2012-04-13 09:13:13 +0000 | [diff] [blame] | 33 | #include <thrift/TLogging.h> |
Aditya Agarwal | 3950f47 | 2006-10-11 02:50:15 +0000 | [diff] [blame] | 34 | |
| 35 | #include "Service.h" |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 36 | |
| 37 | #include <iostream> |
| 38 | #include <set> |
| 39 | #include <stdexcept> |
| 40 | #include <sstream> |
Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 41 | #include <map> |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 42 | #if _WIN32 |
| 43 | #include <thrift/windows/TWinsockSingleton.h> |
| 44 | #endif |
Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 45 | |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 46 | using namespace std; |
| 47 | |
T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 48 | using namespace apache::thrift; |
| 49 | using namespace apache::thrift::protocol; |
| 50 | using namespace apache::thrift::transport; |
| 51 | using namespace apache::thrift::server; |
| 52 | using namespace apache::thrift::concurrency; |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 53 | |
| 54 | using namespace test::stress; |
| 55 | |
Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 56 | struct eqstr { |
| 57 | bool operator()(const char* s1, const char* s2) const { |
| 58 | return strcmp(s1, s2) == 0; |
| 59 | } |
| 60 | }; |
| 61 | |
| 62 | struct ltstr { |
| 63 | bool operator()(const char* s1, const char* s2) const { |
| 64 | return strcmp(s1, s2) < 0; |
| 65 | } |
| 66 | }; |
| 67 | |
| 68 | |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 69 | // typedef hash_map<const char*, int, hash<const char*>, eqstr> count_map; |
| 70 | typedef map<const char*, int, ltstr> count_map; |
Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 71 | |
Aditya Agarwal | 3950f47 | 2006-10-11 02:50:15 +0000 | [diff] [blame] | 72 | class Server : public ServiceIf { |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 73 | public: |
Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 74 | Server() {} |
| 75 | |
| 76 | void count(const char* method) { |
David Reiss | 4637990 | 2008-02-04 19:23:57 +0000 | [diff] [blame] | 77 | Guard m(lock_); |
Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 78 | int ct = counts_[method]; |
| 79 | counts_[method] = ++ct; |
| 80 | } |
| 81 | |
| 82 | void echoVoid() { |
| 83 | count("echoVoid"); |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | count_map getCount() { |
David Reiss | 4637990 | 2008-02-04 19:23:57 +0000 | [diff] [blame] | 88 | Guard m(lock_); |
Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 89 | return counts_; |
| 90 | } |
| 91 | |
Mark Slee | 739dbe5 | 2007-02-01 22:55:30 +0000 | [diff] [blame] | 92 | int8_t echoByte(const int8_t arg) {return arg;} |
| 93 | int32_t echoI32(const int32_t arg) {return arg;} |
| 94 | int64_t echoI64(const int64_t arg) {return arg;} |
| 95 | void echoString(string& out, const string &arg) { |
Aditya Agarwal | e9ef8d7 | 2006-12-08 23:52:57 +0000 | [diff] [blame] | 96 | if (arg != "hello") { |
Roger Meier | a8cef6e | 2011-07-17 18:55:59 +0000 | [diff] [blame] | 97 | T_ERROR_ABORT("WRONG STRING (%s)!!!!", arg.c_str()); |
Aditya Agarwal | e9ef8d7 | 2006-12-08 23:52:57 +0000 | [diff] [blame] | 98 | } |
Mark Slee | 739dbe5 | 2007-02-01 22:55:30 +0000 | [diff] [blame] | 99 | out = arg; |
Aditya Agarwal | e9ef8d7 | 2006-12-08 23:52:57 +0000 | [diff] [blame] | 100 | } |
Mark Slee | 739dbe5 | 2007-02-01 22:55:30 +0000 | [diff] [blame] | 101 | void echoList(vector<int8_t> &out, const vector<int8_t> &arg) { out = arg; } |
| 102 | void echoSet(set<int8_t> &out, const set<int8_t> &arg) { out = arg; } |
| 103 | void echoMap(map<int8_t, int8_t> &out, const map<int8_t, int8_t> &arg) { out = arg; } |
Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 104 | |
| 105 | private: |
| 106 | count_map counts_; |
| 107 | Mutex lock_; |
| 108 | |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | class ClientThread: public Runnable { |
| 112 | public: |
| 113 | |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 114 | ClientThread(boost::shared_ptr<TTransport>transport, boost::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] | 115 | _transport(transport), |
| 116 | _client(client), |
| 117 | _monitor(monitor), |
| 118 | _workerCount(workerCount), |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 119 | _loopCount(loopCount), |
| 120 | _loopType(loopType) |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 121 | {} |
| 122 | |
| 123 | void run() { |
| 124 | |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 125 | // Wait for all worker threads to start |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 126 | |
| 127 | {Synchronized s(_monitor); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 128 | while(_workerCount == 0) { |
| 129 | _monitor.wait(); |
| 130 | } |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | _startTime = Util::currentTime(); |
| 134 | |
| 135 | _transport->open(); |
| 136 | |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 137 | switch(_loopType) { |
| 138 | case T_VOID: loopEchoVoid(); break; |
| 139 | case T_BYTE: loopEchoByte(); break; |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 140 | case T_I32: loopEchoI32(); break; |
| 141 | case T_I64: loopEchoI64(); break; |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 142 | case T_STRING: loopEchoString(); break; |
| 143 | default: cerr << "Unexpected loop type" << _loopType << endl; break; |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 144 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 145 | |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 146 | _endTime = Util::currentTime(); |
| 147 | |
| 148 | _transport->close(); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 149 | |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 150 | _done = true; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 151 | |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 152 | {Synchronized s(_monitor); |
| 153 | |
| 154 | _workerCount--; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 155 | |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 156 | if (_workerCount == 0) { |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 157 | |
| 158 | _monitor.notify(); |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | } |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 162 | |
| 163 | void loopEchoVoid() { |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 164 | for (size_t ix = 0; ix < _loopCount; ix++) { |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 165 | _client->echoVoid(); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | void loopEchoByte() { |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 170 | for (size_t ix = 0; ix < _loopCount; ix++) { |
Aditya Agarwal | 3950f47 | 2006-10-11 02:50:15 +0000 | [diff] [blame] | 171 | int8_t arg = 1; |
| 172 | int8_t result; |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 173 | result =_client->echoByte(arg); |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 174 | (void)result; |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 175 | assert(result == arg); |
| 176 | } |
| 177 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 178 | |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 179 | void loopEchoI32() { |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 180 | for (size_t ix = 0; ix < _loopCount; ix++) { |
Aditya Agarwal | 3950f47 | 2006-10-11 02:50:15 +0000 | [diff] [blame] | 181 | int32_t arg = 1; |
| 182 | int32_t result; |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 183 | result =_client->echoI32(arg); |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 184 | (void)result; |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 185 | assert(result == arg); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | void loopEchoI64() { |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 190 | for (size_t ix = 0; ix < _loopCount; ix++) { |
Aditya Agarwal | 3950f47 | 2006-10-11 02:50:15 +0000 | [diff] [blame] | 191 | int64_t arg = 1; |
| 192 | int64_t result; |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 193 | result =_client->echoI64(arg); |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 194 | (void)result; |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 195 | assert(result == arg); |
| 196 | } |
| 197 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 198 | |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 199 | void loopEchoString() { |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 200 | for (size_t ix = 0; ix < _loopCount; ix++) { |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 201 | string arg = "hello"; |
| 202 | string result; |
Mark Slee | 739dbe5 | 2007-02-01 22:55:30 +0000 | [diff] [blame] | 203 | _client->echoString(result, arg); |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 204 | assert(result == arg); |
| 205 | } |
| 206 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 207 | |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 208 | boost::shared_ptr<TTransport> _transport; |
| 209 | boost::shared_ptr<ServiceClient> _client; |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 210 | Monitor& _monitor; |
| 211 | size_t& _workerCount; |
| 212 | size_t _loopCount; |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 213 | TType _loopType; |
Roger Meier | 5f9614c | 2010-11-21 16:59:05 +0000 | [diff] [blame] | 214 | int64_t _startTime; |
| 215 | int64_t _endTime; |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 216 | bool _done; |
| 217 | Monitor _sleep; |
| 218 | }; |
Aditya Agarwal | e9ef8d7 | 2006-12-08 23:52:57 +0000 | [diff] [blame] | 219 | |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 220 | class TStartObserver : public apache::thrift::server::TServerEventHandler |
| 221 | { |
| 222 | public: |
| 223 | TStartObserver() : awake_(false) {} |
| 224 | virtual void preServe() |
| 225 | { |
| 226 | apache::thrift::concurrency::Synchronized s(m_); |
| 227 | awake_ = true; |
| 228 | m_.notifyAll(); |
| 229 | } |
| 230 | void waitForService() |
| 231 | { |
| 232 | apache::thrift::concurrency::Synchronized s(m_); |
| 233 | while(!awake_) |
| 234 | m_.waitForever(); |
| 235 | } |
| 236 | private: |
| 237 | apache::thrift::concurrency::Monitor m_; |
| 238 | bool awake_; |
| 239 | }; |
Aditya Agarwal | e9ef8d7 | 2006-12-08 23:52:57 +0000 | [diff] [blame] | 240 | |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 241 | int main(int argc, char **argv) { |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 242 | #if _WIN32 |
| 243 | transport::TWinsockSingleton::create(); |
| 244 | #endif |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 245 | |
Aditya Agarwal | e9ef8d7 | 2006-12-08 23:52:57 +0000 | [diff] [blame] | 246 | int port = 9091; |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 247 | string serverType = "thread-pool"; |
| 248 | string protocolType = "binary"; |
| 249 | size_t workerCount = 4; |
Aditya Agarwal | e9ef8d7 | 2006-12-08 23:52:57 +0000 | [diff] [blame] | 250 | size_t clientCount = 20; |
| 251 | size_t loopCount = 50000; |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 252 | TType loopType = T_VOID; |
| 253 | string callName = "echoVoid"; |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 254 | bool runServer = true; |
Aditya Agarwal | 3950f47 | 2006-10-11 02:50:15 +0000 | [diff] [blame] | 255 | bool logRequests = false; |
| 256 | string requestLogPath = "./requestlog.tlog"; |
Aditya Agarwal | e9ef8d7 | 2006-12-08 23:52:57 +0000 | [diff] [blame] | 257 | bool replayRequests = false; |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 258 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 259 | ostringstream usage; |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 260 | |
| 261 | usage << |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 262 | argv[0] << " [--port=<port number>] [--server] [--server-type=<server-type>] [--protocol-type=<protocol-type>] [--workers=<worker-count>] [--clients=<client-count>] [--loop=<loop-count>]" << endl << |
| 263 | "\tclients Number of client threads to create - 0 implies no clients, i.e. server only. Default is " << clientCount << endl << |
| 264 | "\thelp Prints this help text." << endl << |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 265 | "\tcall Service method to call. Default is " << callName << endl << |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 266 | "\tloop The number of remote thrift calls each client makes. Default is " << loopCount << endl << |
| 267 | "\tport The port the server and clients should bind to for thrift network connections. Default is " << port << endl << |
| 268 | "\tserver Run the Thrift server in this process. Default is " << runServer << endl << |
| 269 | "\tserver-type Type of server, \"simple\" or \"thread-pool\". Default is " << serverType << endl << |
| 270 | "\tprotocol-type Type of protocol, \"binary\", \"ascii\", or \"xml\". Default is " << protocolType << endl << |
Aditya Agarwal | 3950f47 | 2006-10-11 02:50:15 +0000 | [diff] [blame] | 271 | "\tlog-request Log all request to ./requestlog.tlog. Default is " << logRequests << endl << |
Aditya Agarwal | e9ef8d7 | 2006-12-08 23:52:57 +0000 | [diff] [blame] | 272 | "\treplay-request Replay requests from log file (./requestlog.tlog) Default is " << replayRequests << endl << |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 273 | "\tworkers Number of thread pools workers. Only valid for thread-pool server type. Default is " << workerCount << endl; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 274 | |
| 275 | |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 276 | map<string, string> args; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 277 | |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 278 | for (int ix = 1; ix < argc; ix++) { |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 279 | |
| 280 | string arg(argv[ix]); |
| 281 | |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 282 | if (arg.compare(0,2, "--") == 0) { |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 283 | |
| 284 | size_t end = arg.find_first_of("=", 2); |
| 285 | |
Marc Slemko | 056f9ba | 2006-08-17 02:59:05 +0000 | [diff] [blame] | 286 | string key = string(arg, 2, end - 2); |
| 287 | |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 288 | if (end != string::npos) { |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 289 | args[key] = string(arg, end + 1); |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 290 | } else { |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 291 | args[key] = "true"; |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 292 | } |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 293 | } else { |
| 294 | throw invalid_argument("Unexcepted command line token: "+arg); |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | try { |
| 299 | |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 300 | if (!args["clients"].empty()) { |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 301 | clientCount = atoi(args["clients"].c_str()); |
| 302 | } |
| 303 | |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 304 | if (!args["help"].empty()) { |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 305 | cerr << usage.str(); |
| 306 | return 0; |
| 307 | } |
| 308 | |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 309 | if (!args["loop"].empty()) { |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 310 | loopCount = atoi(args["loop"].c_str()); |
| 311 | } |
| 312 | |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 313 | if (!args["call"].empty()) { |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 314 | callName = args["call"]; |
| 315 | } |
| 316 | |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 317 | if (!args["port"].empty()) { |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 318 | port = atoi(args["port"].c_str()); |
| 319 | } |
| 320 | |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 321 | if (!args["server"].empty()) { |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 322 | runServer = args["server"] == "true"; |
| 323 | } |
| 324 | |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 325 | if (!args["log-request"].empty()) { |
Aditya Agarwal | 3950f47 | 2006-10-11 02:50:15 +0000 | [diff] [blame] | 326 | logRequests = args["log-request"] == "true"; |
| 327 | } |
| 328 | |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 329 | if (!args["replay-request"].empty()) { |
Aditya Agarwal | e9ef8d7 | 2006-12-08 23:52:57 +0000 | [diff] [blame] | 330 | replayRequests = args["replay-request"] == "true"; |
| 331 | } |
| 332 | |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 333 | if (!args["server-type"].empty()) { |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 334 | serverType = args["server-type"]; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 335 | |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 336 | if (serverType == "simple") { |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 337 | |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 338 | } else if (serverType == "thread-pool") { |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 339 | |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 340 | } else if (serverType == "threaded") { |
Mark Slee | 739dbe5 | 2007-02-01 22:55:30 +0000 | [diff] [blame] | 341 | |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 342 | } else { |
| 343 | |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 344 | throw invalid_argument("Unknown server type "+serverType); |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 345 | } |
| 346 | } |
| 347 | |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 348 | if (!args["workers"].empty()) { |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 349 | workerCount = atoi(args["workers"].c_str()); |
| 350 | } |
| 351 | |
Roger Meier | bb09f44 | 2011-05-31 20:35:37 +0000 | [diff] [blame] | 352 | } catch(std::exception& e) { |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 353 | cerr << e.what() << endl; |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 354 | cerr << usage.str(); |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 355 | } |
| 356 | |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 357 | boost::shared_ptr<PlatformThreadFactory> threadFactory = boost::shared_ptr<PlatformThreadFactory>(new PlatformThreadFactory()); |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 358 | |
Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 359 | // Dispatcher |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 360 | boost::shared_ptr<Server> serviceHandler(new Server()); |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 361 | |
Aditya Agarwal | e9ef8d7 | 2006-12-08 23:52:57 +0000 | [diff] [blame] | 362 | if (replayRequests) { |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 363 | boost::shared_ptr<Server> serviceHandler(new Server()); |
| 364 | boost::shared_ptr<ServiceProcessor> serviceProcessor(new ServiceProcessor(serviceHandler)); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 365 | |
Aditya Agarwal | e9ef8d7 | 2006-12-08 23:52:57 +0000 | [diff] [blame] | 366 | // Transports |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 367 | boost::shared_ptr<TFileTransport> fileTransport(new TFileTransport(requestLogPath)); |
Aditya Agarwal | e9ef8d7 | 2006-12-08 23:52:57 +0000 | [diff] [blame] | 368 | fileTransport->setChunkSize(2 * 1024 * 1024); |
| 369 | fileTransport->setMaxEventSize(1024 * 16); |
| 370 | fileTransport->seekToEnd(); |
| 371 | |
| 372 | // Protocol Factory |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 373 | boost::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory()); |
Aditya Agarwal | e9ef8d7 | 2006-12-08 23:52:57 +0000 | [diff] [blame] | 374 | |
| 375 | TFileProcessor fileProcessor(serviceProcessor, |
| 376 | protocolFactory, |
| 377 | fileTransport); |
| 378 | |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 379 | fileProcessor.process(0, true); |
Aditya Agarwal | e9ef8d7 | 2006-12-08 23:52:57 +0000 | [diff] [blame] | 380 | exit(0); |
| 381 | } |
| 382 | |
| 383 | |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 384 | if (runServer) { |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 385 | |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 386 | boost::shared_ptr<ServiceProcessor> serviceProcessor(new ServiceProcessor(serviceHandler)); |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 387 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 388 | // Transport |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 389 | boost::shared_ptr<TServerSocket> serverSocket(new TServerSocket(port)); |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 390 | |
Aditya Agarwal | 3950f47 | 2006-10-11 02:50:15 +0000 | [diff] [blame] | 391 | // Transport Factory |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 392 | boost::shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory()); |
Aditya Agarwal | 3950f47 | 2006-10-11 02:50:15 +0000 | [diff] [blame] | 393 | |
Mark Slee | d717347 | 2006-10-25 19:52:10 +0000 | [diff] [blame] | 394 | // Protocol Factory |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 395 | boost::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory()); |
Aditya Agarwal | 3950f47 | 2006-10-11 02:50:15 +0000 | [diff] [blame] | 396 | |
| 397 | if (logRequests) { |
| 398 | // initialize the log file |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 399 | boost::shared_ptr<TFileTransport> fileTransport(new TFileTransport(requestLogPath)); |
Aditya Agarwal | e9ef8d7 | 2006-12-08 23:52:57 +0000 | [diff] [blame] | 400 | fileTransport->setChunkSize(2 * 1024 * 1024); |
| 401 | fileTransport->setMaxEventSize(1024 * 16); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 402 | |
| 403 | transportFactory = |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 404 | boost::shared_ptr<TTransportFactory>(new TPipedTransportFactory(fileTransport)); |
Aditya Agarwal | 3950f47 | 2006-10-11 02:50:15 +0000 | [diff] [blame] | 405 | } |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 406 | |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 407 | boost::shared_ptr<TServer> server; |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 408 | |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 409 | if (serverType == "simple") { |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 410 | |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 411 | server.reset(new TSimpleServer(serviceProcessor, serverSocket, transportFactory, protocolFactory)); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 412 | |
Mark Slee | 739dbe5 | 2007-02-01 22:55:30 +0000 | [diff] [blame] | 413 | } else if (serverType == "threaded") { |
| 414 | |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 415 | server.reset(new TThreadedServer(serviceProcessor, serverSocket, transportFactory, protocolFactory)); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 416 | |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 417 | } else if (serverType == "thread-pool") { |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 418 | |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 419 | boost::shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(workerCount); |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 420 | |
| 421 | threadManager->threadFactory(threadFactory); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 422 | threadManager->start(); |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 423 | server.reset(new TThreadPoolServer(serviceProcessor, serverSocket, transportFactory, protocolFactory, threadManager)); |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 424 | } |
| 425 | |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 426 | boost::shared_ptr<TStartObserver> observer(new TStartObserver); |
| 427 | server->setServerEventHandler(observer); |
| 428 | boost::shared_ptr<Thread> serverThread = threadFactory->newThread(server); |
| 429 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 430 | cerr << "Starting the server on port " << port << endl; |
| 431 | |
| 432 | serverThread->start(); |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 433 | observer->waitForService(); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 434 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 435 | // If we aren't running clients, just wait forever for external clients |
Mark Slee | d717347 | 2006-10-25 19:52:10 +0000 | [diff] [blame] | 436 | if (clientCount == 0) { |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 437 | serverThread->join(); |
| 438 | } |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 439 | } |
| 440 | |
Mark Slee | d717347 | 2006-10-25 19:52:10 +0000 | [diff] [blame] | 441 | if (clientCount > 0) { |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 442 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 443 | Monitor monitor; |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 444 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 445 | size_t threadCount = 0; |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 446 | |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 447 | set<boost::shared_ptr<Thread> > clientThreads; |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 448 | |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 449 | if (callName == "echoVoid") { loopType = T_VOID;} |
| 450 | else if (callName == "echoByte") { loopType = T_BYTE;} |
| 451 | else if (callName == "echoI32") { loopType = T_I32;} |
| 452 | else if (callName == "echoI64") { loopType = T_I64;} |
| 453 | else if (callName == "echoString") { loopType = T_STRING;} |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 454 | else {throw invalid_argument("Unknown service call "+callName);} |
| 455 | |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 456 | for (size_t ix = 0; ix < clientCount; ix++) { |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 457 | |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 458 | boost::shared_ptr<TSocket> socket(new TSocket("127.0.0.1", port)); |
| 459 | boost::shared_ptr<TBufferedTransport> bufferedSocket(new TBufferedTransport(socket, 2048)); |
| 460 | boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(bufferedSocket)); |
| 461 | boost::shared_ptr<ServiceClient> serviceClient(new ServiceClient(protocol)); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 462 | |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 463 | clientThreads.insert(threadFactory->newThread(boost::shared_ptr<ClientThread>(new ClientThread(socket, serviceClient, monitor, threadCount, loopCount, loopType)))); |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 464 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 465 | |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 466 | for (std::set<boost::shared_ptr<Thread> >::const_iterator thread = clientThreads.begin(); thread != clientThreads.end(); thread++) { |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 467 | (*thread)->start(); |
| 468 | } |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 469 | |
Roger Meier | 5f9614c | 2010-11-21 16:59:05 +0000 | [diff] [blame] | 470 | int64_t time00; |
| 471 | int64_t time01; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 472 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 473 | {Synchronized s(monitor); |
| 474 | threadCount = clientCount; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 475 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 476 | cerr << "Launch "<< clientCount << " client threads" << endl; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 477 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 478 | time00 = Util::currentTime(); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 479 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 480 | monitor.notifyAll(); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 481 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 482 | while(threadCount > 0) { |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 483 | monitor.wait(); |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 484 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 485 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 486 | time01 = Util::currentTime(); |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 487 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 488 | |
Roger Meier | 5f9614c | 2010-11-21 16:59:05 +0000 | [diff] [blame] | 489 | int64_t firstTime = 9223372036854775807LL; |
| 490 | int64_t lastTime = 0; |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 491 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 492 | double averageTime = 0; |
Roger Meier | 5f9614c | 2010-11-21 16:59:05 +0000 | [diff] [blame] | 493 | int64_t minTime = 9223372036854775807LL; |
| 494 | int64_t maxTime = 0; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 495 | |
Roger Meier | 611f90c | 2011-12-11 22:08:51 +0000 | [diff] [blame] | 496 | for (set<boost::shared_ptr<Thread> >::iterator ix = clientThreads.begin(); ix != clientThreads.end(); ix++) { |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 497 | |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 498 | boost::shared_ptr<ClientThread> client = boost::dynamic_pointer_cast<ClientThread>((*ix)->runnable()); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 499 | |
Roger Meier | 5f9614c | 2010-11-21 16:59:05 +0000 | [diff] [blame] | 500 | int64_t delta = client->_endTime - client->_startTime; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 501 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 502 | assert(delta > 0); |
Marc Slemko | 056f9ba | 2006-08-17 02:59:05 +0000 | [diff] [blame] | 503 | |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 504 | if (client->_startTime < firstTime) { |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 505 | firstTime = client->_startTime; |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 506 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 507 | |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 508 | if (client->_endTime > lastTime) { |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 509 | lastTime = client->_endTime; |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 510 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 511 | |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 512 | if (delta < minTime) { |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 513 | minTime = delta; |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 514 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 515 | |
Mark Slee | 3e5d2d7 | 2007-06-15 01:45:56 +0000 | [diff] [blame] | 516 | if (delta > maxTime) { |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 517 | maxTime = delta; |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 518 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 519 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 520 | averageTime+= delta; |
| 521 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 522 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 523 | averageTime /= clientCount; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 524 | |
| 525 | |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 526 | cout << "workers :" << workerCount << ", client : " << clientCount << ", loops : " << loopCount << ", rate : " << (clientCount * loopCount * 1000) / ((double)(time01 - time00)) << endl; |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 527 | |
Mark Slee | b9ff32a | 2006-11-16 01:00:24 +0000 | [diff] [blame] | 528 | count_map count = serviceHandler->getCount(); |
| 529 | count_map::iterator iter; |
| 530 | for (iter = count.begin(); iter != count.end(); ++iter) { |
| 531 | printf("%s => %d\n", iter->first, iter->second); |
| 532 | } |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 533 | cerr << "done." << endl; |
Marc Slemko | 056f9ba | 2006-08-17 02:59:05 +0000 | [diff] [blame] | 534 | } |
Marc Slemko | 056f9ba | 2006-08-17 02:59:05 +0000 | [diff] [blame] | 535 | |
Marc Slemko | 3ea0033 | 2006-08-17 01:11:13 +0000 | [diff] [blame] | 536 | return 0; |
| 537 | } |