summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/Notify/performance-tests/Throughput/Throughput.h
blob: 8eabd5dd28bb03513cf6d9570f7f8834c2bb0d6b (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
/* -*- C++ -*- */
//=============================================================================
/**
 *  @file   Throughput.h
 *
 *  @author Pradeep Gore <pradeep@cs.wustl.edu>
 */
//=============================================================================


#ifndef NOTIFY_Throughput_H
#define NOTIFY_Throughput_H

#include "Notify_Test_Client.h"
#include "Notify_StructuredPushConsumer.h"
#include "Notify_StructuredPushSupplier.h"
#include "ace/Task.h"
#include "ace/Stats.h"
#include "ace/Throughput_Stats.h"
#include "ace/High_Res_Timer.h"
#include "ace/Sched_Params.h"

#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4250)
#endif /* _MSC_VER */

/**
 * @class Worker
 *
 * @brief Run a server thread
 *
 * Use the ACE_Task_Base class to run server threads
 */
class Worker : public ACE_Task_Base
{
public:
  /// ctor
  Worker (void);

  void orb (CORBA::ORB_ptr orb);

  /// The thread entry point.
  virtual int svc (void);

  int done_;

private:
  /// The orb
  CORBA::ORB_var orb_;
};

/***************************************************************************/

class Notify_Throughput;

class Throughput_StructuredPushConsumer
  : public TAO_Notify_Tests_StructuredPushConsumer
{
public:
  /// Constructor.
  Throughput_StructuredPushConsumer (Notify_Throughput *test_client);

  // = StructuredPushSupplier methods
  virtual void push_structured_event (
        const CosNotification::StructuredEvent & notification
      );

  /// Accumulate the throughput statistics into <throughput>
  void accumulate_into (ACE_Throughput_Stats &throughput) const;

  /// Accumulate the throughput statistics into <throughput>
  void dump_stats (const ACE_TCHAR* msg,
                   ACE_High_Res_Timer::global_scale_factor_type gsf);

protected:
  Notify_Throughput * test_client_;

  /// Protect internal state
  TAO_SYNCH_MUTEX lock_;

  /// The timestamp for the first message received
  ACE_hrtime_t throughput_start_;

  /// Used for reporting stats
  ACE_Throughput_Stats throughput_;

  /// The number of push() calls
  int push_count_;
};

/***************************************************************************/

class Throughput_StructuredPushSupplier
  : public TAO_Notify_Tests_StructuredPushSupplier,
    public ACE_Task_Base
{
public:
  /// Constructor.
  Throughput_StructuredPushSupplier (Notify_Throughput * test_client);

  /// Destructor.
  virtual ~Throughput_StructuredPushSupplier ();

  // = The ACE_Task_Base methods....
  virtual int svc (void);

  /// Accumulate the throughput statistics into <throughput>
  void accumulate_into (ACE_Throughput_Stats &throughput) const;

  /// Accumulate the throughput statistics into <throughput>
  void dump_stats (const ACE_TCHAR* msg,
                   ACE_High_Res_Timer::global_scale_factor_type gsf);

protected:
  Notify_Throughput* test_client_;

  /// Count the number of push() calls
  int push_count_;

  /// The time for the first event sent
  ACE_hrtime_t throughput_start_;

  /// Measure the elapsed time spent while sending the events.
  ACE_Throughput_Stats throughput_;
};

/***************************************************************************/

class Notify_Throughput : public Notify_Test_Client
{
public:
  // Initialization and termination code
  Notify_Throughput (void);
  virtual ~Notify_Throughput ();

  int parse_args(int argc, ACE_TCHAR *argv[]) ;

  /// initialization.
  int init (int argc, ACE_TCHAR *argv []);

  /// Run the test.
  void run_test (void);

  /// Peers call this when done.
  void peer_done (void);

  /// check if we got the expected results.
  void dump_results (void);

  Worker worker_;
protected:
  /// Create participants.
  void create_EC (void);

  /// is the ec collocated.
  CORBA::Boolean collocated_ec_;

  /// How many bursts we will send from each supplier.
  int burst_count_;

  /// The time between each event burst, in microseconds.
  int burst_pause_;

  /// Number of events to send per supplier in every burst
  int burst_size_;

  /// data size to transmit.
  int payload_size_;

  /// the payload.
  char *payload_;

  /// Consumer count
  int consumer_count_;

  /// Supplier count
  int supplier_count_;

  /// Number of events received that each consumer expects to see.
  int perconsumer_count_;

  /// The name of the EC to resolve.
  ACE_CString ec_name_;

  /// The one channel that we create using the factory.
  CosNotifyChannelAdmin::EventChannel_var ec_;

  /// The consumer admin used by consumers.
  CosNotifyChannelAdmin::ConsumerAdmin_var consumer_admin_;

  /// The supplier admin used by suppliers.
  CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin_;

  /// Consumers
  Throughput_StructuredPushConsumer** consumers_;

  /// Suppliers
  Throughput_StructuredPushSupplier** suppliers_;

  int nthreads_;

  // = Helpers to signal done.
  /// how many peers are done.
  int peer_done_count_;

  /// The lock to serialize access to members.
  TAO_SYNCH_MUTEX lock_;

  /// exit wait condition
  TAO_SYNCH_CONDITION condition_;
private:
  friend class Throughput_StructuredPushSupplier;
  friend class Throughput_StructuredPushConsumer;
};

/***************************************************************************/

#if defined(_MSC_VER)
#pragma warning(pop)
#endif /* _MSC_VER */

#endif /* NOTIFY_TESTS_EventS_H */