Zero  0.1.0
shore_client.h
Go to the documentation of this file.
1 /* -*- mode:C++; c-basic-offset:4 -*-
2  Shore-kits -- Benchmark implementations for Shore-MT
3 
4  Copyright (c) 2007-2009
5  Data Intensive Applications and Systems Labaratory (DIAS)
6  Ecole Polytechnique Federale de Lausanne
7 
8  All Rights Reserved.
9 
10  Permission to use, copy, modify and distribute this software and
11  its documentation is hereby granted, provided that both the
12  copyright notice and this permission notice appear in all copies of
13  the software, derivative works or modified versions, and any
14  portions thereof, and that both notices appear in supporting
15  documentation.
16 
17  This code is distributed in the hope that it will be useful, but
18  WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS
20  DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
21  RESULTING FROM THE USE OF THIS SOFTWARE.
22 */
23 
32 #ifndef __SHORE_CLIENT_H
33 #define __SHORE_CLIENT_H
34 
35 // #include "k_defines.h"
36 
37 #include "shore_env.h"
38 #include "daemons.h"
39 
40 // enumuration of different binding types
42  BT_NONE = 0,
43  BT_NEXT = 1,
45 };
46 
47 
49 
50 
51 // Default values for the power-runs //
52 
53 
54 // default value to spread threads
55 const int DF_SPREAD_THREADS = 1;
56 
57 // default number of threads
58 const int DF_NUM_OF_THR = 5;
59 
60 // maximum number of threads
61 const int MAX_NUM_OF_THR = 1000;
62 
63 // default number of transactions executed per thread
64 const int DF_TRX_PER_THR = 100;
65 
66 // default duration for time-based measurements (in secs)
67 const int DF_DURATION = 20;
68 
69 // default number of iterations
70 const int DF_NUM_OF_ITERS = 5;
71 
72 // default processor binding
74 
75 
76 // Default values for the warmups //
77 
78 // default number of transactions executed per thread during warmup
79 const int DF_WARMUP_TRX_PER_THR = 1000;
80 
81 // default duration of warmup (in secs)
82 const int DF_WARMUP_DURATION = 20;
83 
84 // default number of iterations during warmup
85 const int DF_WARMUP_ITERS = 3;
86 
87 // default batch size
88 const int BATCH_SIZE = 10;
89 
90 // default think time
91 const int THINK_TIME = 0;
92 
93 // Instanciate and close the Shore environment
94 int inst_test_env(int argc, char* argv[]);
95 
96 int close_test_env();
97 
98 /********************************************************************
99  *
100  * @enum MeasurementType
101  *
102  * @brief Possible measurement types for tester thread
103  *
104  ********************************************************************/
105 
106 const int DF_WARMUP_INTERVAL = 2; // 2 secs
107 
114 };
115 
116 /********************************************************************
117  *
118  * @enum: base_client_t
119  *
120  * @brief: An smthread-based base class for the clients
121  *
122  ********************************************************************/
123 
124 class base_client_t : public thread_t {
125 public:
126 
127  // supported trxs
128  typedef map<int, string> mapSupTrxs;
129 
130  typedef mapSupTrxs::iterator mapSupTrxsIt;
131 
132  typedef mapSupTrxs::const_iterator mapSupTrxsConstIt;
133 
134 protected:
135 
136  // the environment
138 
139  // workload parameters
141 
142  int _trxid;
143 
144  int _notrxs;
145 
146  // used for submitting batches
148 
149  // for processor binding
150  bool _is_bound;
151 
152  int _id; // thread id
153  int _rv;
154 
155  boost::program_options::variables_map optionValues;
156 
157 public:
158 
160  : thread_t("none"),
161  _env(nullptr),
162  _measure_type(MT_UNDEF),
163  _trxid(-1),
164  _notrxs(-1),
165  _is_bound(false),
166  _rv(1) {}
167 
168  base_client_t(std::string tname, const int id, ShoreEnv* env,
169  const MeasurementType aType, const int trxid,
170  const int numOfTrxs)
171  : thread_t(tname),
172  _env(env),
173  _measure_type(aType),
174  _trxid(trxid),
175  _notrxs(numOfTrxs),
176  _id(id),
177  _rv(0) {
178  assert (_env);
179  assert (_measure_type != MT_UNDEF);
180  assert (_notrxs || (_measure_type == MT_TIME_DUR) || (_measure_type == MT_LOG_VOL)
181  || (_measure_type == MT_NO_STOP));
182  _cp = new condex_pair();
183  }
184 
185  virtual ~base_client_t() {}
186 
187  // thread entrance
188  void work() {
189  // 2. init env in not initialized
190  if (!_env->is_initialized()) {
191  if (_env->init()) {
192  // Couldn't initialize the Shore environment
193  // cannot proceed
194  TRACE(TRACE_ALWAYS, "Couldn't initialize Shore...\n");
195  _rv = 1;
196  return;
197  }
198  }
199 
200  // _env->log_insert(kits_logger_t::t_worker_begin);
201 
202  // 4. run workload
203  powerrun();
204 
205  // _env->log_insert(kits_logger_t::t_worker_end);
206  }
207 
208  // access methods
209  int id() {
210  return (_id);
211  }
212 
213  bool is_bound() const {
214  return (_is_bound);
215  }
216 
217  inline int rv() {
218  return (_rv);
219  }
220 
221  // methods
222  w_rc_t run_xcts(int xct_type, int num_xct);
223 
224  int powerrun() {
225  w_rc_t rc = _env->load();
226  if (rc.is_error()) {
227  return rc.err_num();
228  }
229  return (run_xcts(_trxid, _notrxs).err_num());
230  }
231 
232  w_rc_t submit_batch(int xct_type, int& trx_cnt, const int batch_size);
233 
234  static void abort_test();
235 
236  static void resume_test();
237 
238  static bool is_test_aborted();
239 
240  // every client class should implement this functions
241  static int load_sup_xct(mapSupTrxs& map) {
242  map.clear();
243  return (map.size());
244  }
245 
246  // INTERFACE
247 
248  virtual w_rc_t submit_one(int xct_type, int num_xct) = 0;
249 
250 
251  // debugging
252 
253  void print_tables() {
254  assert (_env);
255  _env->dump();
256  }
257 
258 private:
259 
260  // copying not allowed
262 
263  void operator=(base_client_t const&);
264 }; // EOF: base_client_t
265 
266 
267 #endif // __SHORE_CLIENT_H
const int THINK_TIME
Definition: shore_client.h:91
const int BATCH_SIZE
Definition: shore_client.h:88
void print_tables()
Definition: shore_client.h:253
boost::program_options::variables_map optionValues
Definition: shore_client.h:155
w_error_codes err_num() const
Definition: w_rc.h:510
bool _is_bound
Definition: shore_client.h:150
int _id
Definition: shore_client.h:152
bool is_error() const
True if this return code is not RCOK or equivalent. This must be called for every w_rc_t before destr...
Definition: w_rc.h:505
static void abort_test()
Definition: shore_client.cpp:43
virtual int dump()
Definition: shore_env.cpp:885
const int DF_SPREAD_THREADS
Definition: shore_client.h:55
Definition: shore_client.h:43
virtual w_rc_t submit_one(int xct_type, int num_xct)=0
virtual int init()
Definition: shore_env.cpp:376
base_client_t(std::string tname, const int id, ShoreEnv *env, const MeasurementType aType, const int trxid, const int numOfTrxs)
Definition: shore_client.h:168
MeasurementType
Definition: shore_client.h:108
const int DF_WARMUP_TRX_PER_THR
Definition: shore_client.h:79
w_rc_t run_xcts(int xct_type, int num_xct)
Definition: shore_client.cpp:112
map< int, string > mapSupTrxs
Definition: shore_client.h:128
virtual ~base_client_t()
Definition: shore_client.h:185
guard< condex_pair > _cp
Definition: shore_client.h:147
const int MAX_NUM_OF_THR
Definition: shore_client.h:61
int _trxid
Definition: shore_client.h:142
int _notrxs
Definition: shore_client.h:144
Definition: shore_client.h:124
const int DF_WARMUP_DURATION
Definition: shore_client.h:82
Definition: kits_thread.h:134
base_client_t()
Definition: shore_client.h:159
mapSupTrxs::iterator mapSupTrxsIt
Definition: shore_client.h:130
: Definition of a Shore environment (database)
const eBindingType DF_BINDING_TYPE
Definition: shore_client.h:73
const int DF_WARMUP_INTERVAL
Definition: shore_client.h:106
Definition: shore_client.h:109
int inst_test_env(int argc, char *argv[])
Definition: condex.h:87
int _rv
Definition: shore_client.h:153
static void resume_test()
Definition: shore_client.cpp:47
bool is_bound() const
Definition: shore_client.h:213
MeasurementType _measure_type
Definition: shore_client.h:140
int id()
Definition: shore_client.h:209
Return code for most functions and methods.
Definition: w_rc.h:87
w_rc_t load()
Definition: shore_env.cpp:150
Definition: shore_client.h:112
Definition: shore_client.h:44
Definition: shore_client.h:42
#define TRACE
Other modules in our program use this macro for reporting. We can use preprocessor macros like FILE a...
Definition: trace.h:91
static int load_sup_xct(mapSupTrxs &map)
Definition: shore_client.h:241
Definition: shore_client.h:111
: Definition of helper loader thread classes
Definition: shore_client.h:113
int rv()
Definition: shore_client.h:217
Definition: shore_client.h:110
bool is_initialized()
Definition: shore_env.cpp:140
const int DF_TRX_PER_THR
Definition: shore_client.h:64
#define TRACE_ALWAYS
Definition: trace_types.h:41
Definition: shore_env.h:349
w_rc_t submit_batch(int xct_type, int &trx_cnt, const int batch_size)
Definition: shore_client.cpp:64
int close_test_env()
void operator=(base_client_t const &)
mapSupTrxs::const_iterator mapSupTrxsConstIt
Definition: shore_client.h:132
int powerrun()
Definition: shore_client.h:224
const int DF_DURATION
Definition: shore_client.h:67
eBindingType
Definition: shore_client.h:41
const int DF_NUM_OF_THR
Definition: shore_client.h:58
void work()
Definition: shore_client.h:188
ShoreEnv * _env
Definition: shore_client.h:137
const int DF_NUM_OF_ITERS
Definition: shore_client.h:70
static bool is_test_aborted()
Definition: shore_client.cpp:51
const int DF_WARMUP_ITERS
Definition: shore_client.h:85