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