summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/performance-tests/RTEvent/Federated_Roundtrip/client.cpp
blob: 8720b8bb599900168c8ed255699d32525a0e926e (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
// $Id$

#include "RT_Class.h"
#include "ORB_Holder.h"
#include "Servant_var.h"
#include "RIR_Narrow.h"
#include "RTServer_Setup.h"
#include "Peer_Base.h"
#include "Auto_Disconnect.h"
#include "Send_Task.h"
#include "Task_Activator.h"
#include "Client_Pair.h"

#include "orbsvcs/Event_Service_Constants.h"
#include "orbsvcs/Event/EC_Default_Factory.h"

#include "tao/Messaging/Messaging.h"
#include "tao/Strategies/advanced_resource.h"
#include "tao/RTCORBA/Priority_Mapping_Manager.h"
#include "tao/RTCORBA/Continuous_Priority_Mapping.h"
#include "tao/RTPortableServer/RTPortableServer.h"
#include "ace/Get_Opt.h"
#include "ace/Auto_Ptr.h"
#include "ace/High_Res_Timer.h"
#include "ace/Sample_History.h"
#include "ace/Basic_Stats.h"
#include "ace/Stats.h"
#include "ace/Sched_Params.h"
#include "ace/Barrier.h"

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

const char *ior = "file://test.ior";
int nthreads   = 0;
int high_priority_period = 0;
int high_priority_workload = 0;
int low_priority_period  = 0;
int low_priority_workload = 0;
int disable_low_priority = 0;
int use_rt_corba = 0;

class Roundtrip_Peer : public Peer_Base
{
public:
  Roundtrip_Peer (CORBA::ORB_ptr orb,
                  RTServer_Setup &rtserver_setup,
                  RT_Class &rt_class
                  ACE_ENV_ARG_DECL)
    : Peer_Base (orb, rtserver_setup
                 ACE_ENV_ARG_PARAMETER)
    , rt_class_ (&rt_class)
  {
  }

  //@{
  /** @name The Federated_Test::Peer methods
   */
  virtual Federated_Test::Experiment_Results *
      run_experiment (CORBA::Long experiment_id,
                      CORBA::Long iterations
                      ACE_ENV_ARG_DECL)
        ACE_THROW_SPEC ((CORBA::SystemException));
  //@}

private:
  RT_Class *rt_class_;
};

int
parse_args (int argc, char *argv[])
{
  ACE_Get_Opt get_opts (argc, argv, "k:n:l:h:w:v:zr");
  int c;

  while ((c = get_opts ()) != -1)
    switch (c)
      {
      case 'k':
        ior = get_opts.opt_arg ();
        break;

      case 'n':
        nthreads = ACE_OS::atoi (get_opts.opt_arg ());
        break;

      case 'h':
        high_priority_period = ACE_OS::atoi (get_opts.opt_arg ());
        break;

      case 'l':
        low_priority_period = ACE_OS::atoi (get_opts.opt_arg ());
        break;

      case 'w':
        high_priority_workload = ACE_OS::atoi (get_opts.opt_arg ());
        break;

      case 'v':
        low_priority_workload = ACE_OS::atoi (get_opts.opt_arg ());
        break;

      case 'z':
        disable_low_priority = 1;
        break;

      case 'r':
        use_rt_corba = 1;
        break;

      case '?':
      default:
        ACE_ERROR_RETURN ((LM_ERROR,
                           "usage:  %s "
                           "-k <IOR> "
                           "-i iterations (iterations) "
                           "-h high_priority_period (usecs) "
                           "-l low_priority_period (usecs) "
                           "-w high_priority_workload (usecs) "
                           "-v low_priority_workload (usecs) "
                           "-r (enable RT-CORBA) "
                           "-n nthreads (low priority thread) "
                           "-z (disable low priority) "
                           "\n",
                           argv [0]),
                          -1);
      }
  // Indicates sucessful parsing of the command line
  return 0;
}

int main (int argc, char *argv[])
{
  TAO_EC_Default_Factory::init_svcs();
  RT_Class rt_class;

  ACE_TRY_NEW_ENV
    {
      ORB_Holder orb (argc, argv, ""
                      ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      if (parse_args (argc, argv) != 0)
        return 1;

      RTServer_Setup rtserver_setup (use_rt_corba,
                                     orb,
                                     rt_class,
                                     nthreads
                                     ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      PortableServer::POA_var root_poa =
        RIR_Narrow<PortableServer::POA>::resolve (orb,
                                                  "RootPOA"
                                                  ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      PortableServer::POAManager_var poa_manager =
        root_poa->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_TRY_CHECK;

      poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_TRY_CHECK;

      ACE_DEBUG ((LM_DEBUG, "Finished ORB and POA configuration\n"));

      Servant_var<Roundtrip_Peer> peer_impl (
          new Roundtrip_Peer (orb,
                              rtserver_setup,
                              rt_class
                              ACE_ENV_ARG_PARAMETER)
          );
      ACE_TRY_CHECK;

      Federated_Test::Peer_var peer =
        peer_impl->_this (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_TRY_CHECK;

      ACE_DEBUG ((LM_DEBUG, "Finished peer configuration and activation\n"));

      CORBA::Object_var object =
        orb->string_to_object (ior ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      Federated_Test::Control_var control =
        Federated_Test::Control::_narrow (object.in ()
                                          ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      control->join (peer.in ()
                     ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      orb->run (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_TRY_CHECK;
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
                           "Exception caught:");
      return 1;
    }
  ACE_ENDTRY;

  return 0;
}

Federated_Test::Experiment_Results *
Roundtrip_Peer::run_experiment (CORBA::Long experiment_id,
                                CORBA::Long iterations
                                ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  int thread_count = 1;
#if 0
  if (disable_low_priority == 0)
    thread_count += nthreads;
#endif

  ACE_Barrier the_barrier (thread_count);

  ACE_DEBUG ((LM_DEBUG, "Calibrating high res timer ...."));
  ACE_High_Res_Timer::calibrate ();

  ACE_UINT32 gsf = ACE_High_Res_Timer::global_scale_factor ();
  ACE_DEBUG ((LM_DEBUG, "Done (%d)\n", gsf));

#if 0
  Low_Priority_Setup<Client_Pair> low_priority_setup (
          nthreads,
          0, // no limit on the number of iterations
          1, // each client gets its own type
          experiment_id,
          ACE_ES_EVENT_UNDEFINED + 2,
          low_priority_workload,
          gsf,
          disable_low_priority ? 0 : 1,
          this->rt_class_.priority_low (),
          this->rt_class_.thr_sched_class (),
          low_priority_period,
          this->poa_.in (),
          this->poa_.in (),
          this->event_channel_.in (),
          &the_barrier
          ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (0);
#endif

  Client_Pair high_priority_group;
  high_priority_group.init (experiment_id,
                            ACE_ES_EVENT_UNDEFINED,
                            iterations,
                            high_priority_workload,
                            gsf,
                            this->poa_.in (),
                            this->poa_.in ());
  high_priority_group.connect (this->event_channel_.in ()
                               ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (0);
  Auto_Disconnect<Client_Pair> high_priority_disconnect (&high_priority_group);

  Send_Task high_priority_task;
  high_priority_task.init (iterations,
                           high_priority_period,
                           0,
                           ACE_ES_EVENT_UNDEFINED,
                           experiment_id,
                           high_priority_group.supplier (),
                           &the_barrier);
  {
    // Artificial scope to wait for the high priority task...
    Task_Activator<Send_Task> high_priority_act (this->rt_class_->priority_high (),
                                                 this->rt_class_->thr_sched_class (),
                                                 1,
                                                 &high_priority_task);
  }

  ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - high priority task completed\n"));

#if 0
  if (disable_low_priority == 0)
    {
      low_priority_setup.stop_all_threads ();
    }

  ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - low priority task(s) stopped\n"));
#endif

  ACE_Sample_History &history =
    high_priority_group.consumer ()->sample_history ();

  Federated_Test::Experiment_Results_var results (
     new Federated_Test::Experiment_Results (iterations)
     );
  results->length (iterations);
  for (CORBA::ULong i = 0; i != results->length (); ++i)
    {
      results[i] = history.get_sample (i) / gsf;
    }

  return results._retn ();
}