summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/performance-tests/EC_Federated_Scalability/Coordinator.cpp
blob: 41ac5aa08cfee10c517971f533adf16eaba3ab61 (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
/**
 * @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_Scalability, Coordinator, "$Id$")

ECFS_Coordinator::ECFS_Coordinator (int peers_expected,
                                    int consumer_count,
                                    int iterations,
                                    int do_dump_history,
                                    CORBA::ORB_ptr orb)
  : peers_expected_ (peers_expected)
  , consumer_count_ (consumer_count)
  , 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_]);
}

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

void
ECFS_Coordinator::join (Control::Peer_ptr peer,
                        CORBA::Environment &ACE_TRY_ENV)
  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 (ACE_TRY_ENV);
      ACE_CHECK;

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

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

  /// Run the tests
  for (i = 0; i != 1; ++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,
                                                 ACE_TRY_ENV);
              ACE_CHECK;
            }
        }

      for (int c = 5; c != 105; c += 5)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "Coordinator (%P|%t) "
                      "Starting (%T) test for %d consumer\n",
                      c));
          CORBA::Long gsf;
          Control::Samples_var samples =
            this->peers_[i]->run_experiment (c,
                                             experiment_id,
                                             this->iterations_,
                                             gsf,
                                             ACE_TRY_ENV);
          ACE_CHECK;

          ACE_Sample_History history (samples->length ());


          char filename[1024];
          ACE_OS::sprintf (filename,
                           "ec_federated_scalability.%d.log",
                           c);
          FILE *output_file = ACE_OS::fopen (filename, "w");
          if (output_file == 0)
            {
              ACE_ERROR ((LM_ERROR,
                          "Cannot open output file %s",
                          filename));
            }
          else
            {
              for (CORBA::ULong k = 0; k != samples->length (); ++k)
                {
                  history.sample (samples[k]);
                  ACE_OS::fprintf (output_file,
                                   "HISTO: %d " ACE_UINT64_FORMAT_SPECIFIER "\n",
                                   k, samples[k] / gsf);
                }
              ACE_OS::fclose (output_file);
            }

          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 (j = 0; j != lcount; ++j)
        {
          loopbacks[j]->destroy (ACE_TRY_ENV);
          ACE_CHECK;
        }


    }

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

  this->orb_->shutdown (0, ACE_TRY_ENV);
  ACE_CHECK;
}