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