summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/performance-tests/EC_Federated_Latency/Coordinator.cpp
blob: d50dd07dfc03b0dfdfb080bce3003c3c1b04a30b (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
/**
 * @file Coordinator.cpp
 *
 * $Id$
 *
 * @author Carlos O'Ryan <coryan@uci.edu>
 */

#include "Coordinator.h"

#include "ace/High_Res_Timer.h"
#include "ace/Sample_History.h"
#include "ace/Basic_Stats.h"

ACE_RCSID(EC_Federated_Latency, Coordinator, "$Id$")

ECFL_Coordinator::ECFL_Coordinator (int peers_expected,
                                    int iterations,
                                    int do_dump_history,
                                    CORBA::ORB_ptr orb)
  : peers_expected_ (peers_expected)
  , iterations_ (iterations)
  , do_dump_history_ (do_dump_history)
  , orb_ (CORBA::ORB::_duplicate (orb))
  , peers_count_ (0)
  , peers_ (0)
{
  ACE_NEW (peers_, Control::Peer_var[this->peers_expected_]);
}

ECFL_Coordinator::~ECFL_Coordinator (void)
{
  delete[] this->peers_;
}

void
ECFL_Coordinator::join (Control::Peer_ptr peer
                        TAO_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  {
    ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, this->mutex_);
    if (this->peers_count_ == this->peers_expected_)
      return;

    this->peers_[this->peers_count_++] =
      Control::Peer::_duplicate (peer);

    if (this->peers_count_ < this->peers_expected_)
      return;
  }

  ACE_DEBUG ((LM_DEBUG,
              "Coordinator (%P|%t) Building the federation\n"));
  /// Build the EC federation
  size_t i;
  for (i = 0; i != this->peers_count_; ++i)
    {
      RtecEventChannelAdmin::EventChannel_var channel =
        this->peers_[i]->channel (TAO_ENV_SINGLE_ARG_PARAMETER);
      ACE_CHECK;

      for (size_t j = 0; j != this->peers_count_; ++j)
        {
          if (i != j)
            {
              this->peers_[j]->connect (channel.in () TAO_ENV_ARG_PARAMETER);
              ACE_CHECK;
            }
        }
    }

  Control::Loopback_var *loopbacks;
  ACE_NEW (loopbacks, Control::Loopback_var[this->peers_count_]);

  /// Run the tests
  for (i = 0; i != this->peers_count_; ++i)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "Coordinator (%P|%t) Running test for peer %d\n",
                  i));
      CORBA::Long experiment_id = 128 + i;

      size_t lcount = 0;

      size_t j;
      for (j = 0; j != this->peers_count_; ++j)
        {
          if (j != i)
            {
              loopbacks[lcount++] =
                this->peers_[j]->setup_loopback (experiment_id
                                                 TAO_ENV_ARG_PARAMETER);
              ACE_CHECK;
            }
        }
      Control::Samples_var samples =
        this->peers_[i]->run_experiment (experiment_id,
                                         this->iterations_
                                         TAO_ENV_ARG_PARAMETER);
      ACE_CHECK;

      for (j = 0; j != lcount; ++j)
        {
          loopbacks[j]->destroy (TAO_ENV_SINGLE_ARG_PARAMETER);
          ACE_CHECK;
        }

      ACE_Sample_History history (samples->length ());
      for (CORBA::ULong k = 0; k != samples->length (); ++k)
        history.sample (samples[k] / 2);

      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));

      ACE_Basic_Stats stats;
      history.collect_basic_stats (stats);
      stats.dump_results ("Total", gsf);

      if (this->do_dump_history_)
        {
          history.dump_samples ("HISTORY", gsf);
        }

    }

  for (i = 0; i != this->peers_count_; ++i)
    {
      this->peers_[i]->shutdown (TAO_ENV_SINGLE_ARG_PARAMETER);
      ACE_CHECK;
    }

  this->orb_->shutdown (0 TAO_ENV_ARG_PARAMETER);
  ACE_CHECK;
}