summaryrefslogtreecommitdiff
path: root/TAO/performance-tests/Demux/client.cpp
blob: f69d001788a121eabe9fab3131a1ea575bbcd5b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
// $Id$

#include <sys/types.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include "tao_demuxC.h"
#include "tao/debug.h"

#include "ace/streams.h"

ACE_RCSID(Demux_Test, client, "$Id$")

void print_exception (const CORBA_Exception     *x,
                      const char                  *info,
                      FILE                        *stream
                      );

char Usage[] = "\
Usage: client options\n\
options:\n\
-l strategy: operation lookup strategy - a(active), l(linear), d (dyn hash), p (perf)\n\
-i iter: number of iterations \n\
-m num: number of methods \n\
-o num: number of objects \n\
-t type: type can be l(linear), r(random), b (best), w (worst)\n\
";

#if !defined (__cplusplus)
typedef void (*SIG_TYP)();
#endif

#ifdef SVR4
void
sigpipe (int foo)
#else
  void
sigpipe ()
#endif
{
}

static const char ior_prefix [] = "IOR:";
static const char iiop_prefix [] = "iiop:";

enum SendType{
  LINEAR,
  BEST,
  WORST,
  RANDOM
};

void do_test(tao_demux_ptr *demux, int olimit, int mlimit, SendType, int iter);

int
main (int argc, char *argv[])
{

  unsigned long addr_tmp;
  unsigned short done = 0;
  int c;

  CORBA_ORB_ptr orb_ptr;
  CORBA_Environment     env;
  CORBA_Object_ptr      objref;
  tao_demux_ptr        *demux;
  unsigned              loop_count = 0;
  int                   exit_later = 0;
  int                   i;
  int                   ObjectLimit = 5,
    MethodLimit = 4;
  int iter= 1; // number of iterations
  SendType              st = RANDOM;
  TAO_Operation_Table_Parameters *op_params = TAO_OP_TABLE_PARAMETERS::instance();

  CORBA_String str;
  fstream iorfile;

  while (!done && ((c = getopt (argc, argv, "i:l:t:m:o:")) !=
                   -1)){
    switch(c){
    case 'i':
      iter = atoi (optarg);
      break;
    case 'l': // op table lookup strategy
      break;
    case 'm':
      MethodLimit = atoi(optarg);
      break;
    case 'o':
      ObjectLimit = atoi(optarg);
      break;
    case 't':
      switch(*optarg){
      case 'b':
        st = BEST;
        break;
      case 'w':
        st = WORST;
        break;
      case 'l':
        st = LINEAR;
        break;
      case 'r':
      default:
        st = RANDOM;
        break;
      }
      break;
    default:
      goto usage;
    }
  }

  TAO_debug_level = 0;
  //
  // Transmitter
  //
  orb_ptr = CORBA_ORB_init (argc, argv, "ior", env);
  if (env.exception () != 0) {
    print_exception (env.exception (), "ORB initialization", stdout);
    return 1;
  }

  str = CORBA_string_alloc (500);

  // read the IOR from the file ior.txt
  iorfile.open("./ior.txt", ios::in);

  for (;!iorfile.eof ();){
    memset(str, '\0', 500);
    iorfile >> ((char *)str);
    if (iorfile.good ())
      loop_count++;
  }
  iorfile.close();

  ACE_DEBUG ((LM_DEBUG, "Total of %d object references read\n", loop_count));
  demux = new tao_demux_ptr [loop_count];
  for (i=0; i < loop_count; i++){
    demux[i] = 0;
  }

  // read the IOR from the file ior.txt
  iorfile.open("./ior.txt", ios::in);

  for (i=0; i < loop_count; i++){
    ACE_OS::memset (str, '\0', 500);
    iorfile >> ((char *)str);
    objref = orb_ptr->string_to_object(str, env);
    if (env.exception() != 0){
      print_exception(env.exception(), "string2object", stdout);
      return 1;
    }

    cout << "objref " << i << " has key = " << objref->_get_name(env) << endl;
    if (!CORBA_is_nil(objref)){
      // narrow to the desired interface type
      demux[i] = tao_demux::_narrow (objref);
    }
  }
  iorfile.close();
  CORBA_string_free(str);


  // send operations
  do_test(demux, ObjectLimit, MethodLimit, st, iter);

  for (i=0; i < loop_count; i++){
    CORBA_release(demux[i]);
  }
  delete [] demux;
  return(0);
usage:
  fprintf (stderr, Usage);
  return 1;
}

typedef void (*method_ptr)(tao_demux_ptr);
struct method_db {
  method_ptr method;
};

#include "client.i"

void do_test(tao_demux_ptr *demux, int olimit, int mlimit, SendType st, int iter)
{
  int i, j, k;
  int loop = 0;
  hrtime_t  start, end, sum, diff;
  fstream result;
  CORBA_Environment env;

  result.open("result.dat",ios::out|ios::app);
#ifdef __TAO_ACTIVE__
  result << "# ACTIVE ";
#endif
#ifdef __TAO_GPERF__
  result << "# GPERF ";
#endif
#ifdef __TAO_LINEAR__
  result << "# LINEAR ";
#endif

  //  result << "@type xy" << endl;
  sum = 0;

  if (st == LINEAR){
    result << " LINEAR" << endl;
#ifdef __DEBUG__
    cout << "Linear strategy for sending" << endl;
#endif
    for (k=0; k < iter; k++) {
      // invoke the jth method on the ith object
      for (i=0; i < olimit; i++){
        for (j=0; j < mlimit; j++){
          loop++;
          start = ACE_OS::gethrtime ();
          mtbl[j].method(demux[i]);
          end = ACE_OS::gethrtime ();
          diff = (end - start);
#ifdef __DEBUG__
          cout << "Latency for this request = " << diff/1.0e+06 << endl;
#endif
          sum += diff;
          //    result << loop << "\t" << diff/1.e+06 << endl;
        }
      }
    }
  } else if (st == BEST){
    result << " BEST" << endl;
#ifdef __DEBUG__
    cout << "best strategy for sending" << endl;
#endif
    for (k=0; k < iter; k++) {
      // invoke the jth method on the ith object
      for (i=0; i < olimit; i++){
        for (j=0; j < mlimit; j++){
          loop++;
          start = ACE_OS::gethrtime ();
          mtbl[0].method(demux[0]);
          end = ACE_OS::gethrtime ();
          diff = (end - start);
#ifdef __DEBUG__
          cout << "Latency for this request = " << diff/1.0e+06 << endl;
#endif
          sum += diff;
          //    result << loop << "\t" << diff/1.e+06 << endl;
        }
      }
    }
  } else if (st == RANDOM) {
    result << " RANDOM" << endl;
#ifdef __DEBUG__
    cout << "Random strategy for sending" << endl;
#endif
    // choose the object and method name randomly
    srand48(time(NULL));
    long p, q;
    for (k=0; k < iter; k++) {
      for (i=0; i < olimit; i++){
        for (j=0; j < mlimit; j++){
          loop++;
          p = lrand48() % olimit;
          q = lrand48() % mlimit;
          start = ACE_OS::gethrtime ();
#ifdef DEBUG
          ACE_DEBUG ((LM_DEBUG, "Invoking op %s on object with key %s\n",
                      mtbl[q], demux[p]->_get_name(env)));
#endif
          mtbl[q].method(demux[p]);
          end = ACE_OS::gethrtime ();
          diff = (end - start);
#ifdef __DEBUG__
          cout << "Latency for this request = " << diff/1.0e+06 << endl;
#endif
          sum += diff;
          //    result << loop << "\t" << diff/1.e+06 << endl;
        }
      }
    }
  } else if (st == WORST){
    result << " WORST" << endl;
#ifdef __DEBUG__
    cout << "worst strategy for sending" << endl;
#endif
    // invoke the jth method on the ith object
    for (k=0; k < iter; k++) {
      for (i=0; i < olimit; i++){
        for (j=0; j < mlimit; j++){
          loop++;
          start = ACE_OS::gethrtime ();
          mtbl[mlimit-1].method(demux[olimit-1]);
          end = ACE_OS::gethrtime ();
          diff = (end - start);
#ifdef __DEBUG__
          cout << "Latency for this request = " << diff/1.0e+06  << endl;
#endif
          sum += diff;
          //    result << loop << "\t" << diff/1.e+06 << endl;
        }
      }
    }
  }
  result << olimit << "\t" << mlimit << "\t" << sum/(loop*1000000.0) << endl;
  cout << olimit << "\t" << mlimit << "\t" << sum/(loop*1000000.0) << endl;
  result.close();
}