OnixS C++ Cboe CFE Multicast PITCH Market Data Handler  1.10.3
API documentation
FeedEngine.h
Go to the documentation of this file.
1 /*
2 * Copyright Onix Solutions Limited [OnixS]. All rights reserved.
3 *
4 * This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
5 * and international copyright treaties.
6 *
7 * Access to and use of the software is governed by the terms of the applicable ONIXS Software
8 * Services Agreement (the Agreement) and Customer end user license agreements granting
9 * a non-assignable, non-transferable and non-exclusive license to use the software
10 * for it's own data processing purposes under the terms defined in the Agreement.
11 *
12 * Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
13 * of this source code or associated reference material to any other location for further reproduction
14 * or redistribution, and any amendments to this copyright notice, are expressly prohibited.
15 *
16 * Any reproduction or redistribution for sale or hiring of the Software not in accordance with
17 * the terms of the Agreement is a violation of copyright law.
18 */
19 
20 #pragma once
21 
25 
26 #include <string>
27 
28 namespace OnixS
29 {
30  namespace CboeCFE
31  {
32  namespace MarketData
33  {
34  namespace Pitch
35  {
36  /// Collection of settings affecting Feed Engine behavior.
37  class ONIXS_CBOECFE_PITCH_API FeedEngineSettings
38  {
39  ThreadAffinity threadAffinity_;
40 
41  UInt32 threadCount_;
42 
43  UInt32 dataWaitTime_;
44  UInt32 spinBeforeIdleTime_;
45 
46  UInt32 socketBufferSize_;
47 
48  public:
49  /// Initializes options with default values.
51 
52  /// Defines set of CPUs allowed for each working thread
53  /// to be executed on while processing market data by Handlers
54  /// bound to Feed Engine instance which is configured by given
55  /// settings.
56  ///
57  /// @note By default set is empty thus allowing threads
58  /// to be executed on any CPU available in the system.
60  {
61  return threadAffinity_;
62  }
63 
64  /// Defines set of CPUs allowed for each working thread
65  /// to be executed on while processing market data by Handlers
66  /// bound to Feed Engine instance which is configured by given
67  /// settings.
68  ///
69  /// @note By default set is empty thus allowing threads
70  /// to be executed on any CPU available in the system.
72  {
73  return threadAffinity_;
74  }
75 
76  /// Number of working threads to be used by feed engine.
77  ///
78  /// @note Default value is '1'.
79  UInt32 threadCount() const
80  {
81  return threadCount_;
82  }
83 
84  /// Sets threadsCount. @see threadsCount.
85  void threadCount(UInt32 value)
86  {
87  threadCount_ = value;
88  }
89 
90  /// Defines amount of time Feed Engine spends on socket
91  /// waiting for I/O while running master processing loop.
92  ///
93  /// Time is measured in milliseconds.
94  ///
95  /// @note Default value is '10'.
96  ///
97  /// @warning Given parameter significantly affects
98  /// Handler's responsiveness and load onto CPU!
99  UInt32 dataWaitTime() const
100  {
101  return dataWaitTime_;
102  }
103 
104  /// Sets dataWaitTime. @see dataWaitTime.
105  void dataWaitTime(UInt32 value)
106  {
107  dataWaitTime_ = value;
108  }
109 
110  /// Defines amount of time Feed Engine keeps cycling before
111  /// going to sleep when no useful activity can be done.
112  ///
113  /// Time is measured in milliseconds.
114  ///
115  /// @note Default value is '1'.
116  ///
117  /// @warning Given parameter has direct influence onto CPU load!
118  UInt32 spinBeforeIdleTime() const
119  {
120  return spinBeforeIdleTime_;
121  }
122 
123  /// Sets redundancySpinTime. @see redundancySpinTime.
124  void spinBeforeIdleTime(UInt32 value)
125  {
126  spinBeforeIdleTime_ = value;
127  }
128 
129  /// Defines size of receiving buffer in bytes for sockets.
130  ///
131  /// @note Default value is 8 MiB.
132  UInt32 socketBufferSize() const
133  {
134  return socketBufferSize_;
135  }
136 
137  /// Sets udpSocketBufferSize. @see udpSocketBufferSize.
138  void socketBufferSize(UInt32 value)
139  {
140  socketBufferSize_ = value;
141  }
142 
143  /// Returns the string representation.
144  std::string toString() const;
145  };
146 
147  ONIXS_CBOECFE_PITCH_API std::ostream& operator << (std::ostream& stream, const FeedEngineSettings& settings);
148 
149  /// Identifies reasons feed engine threads becomes idle.
151  {
152  enum Reason
153  {
154  /// Thread waited for incoming data using corresponding
155  /// I/O operations (like 'select') and exited waiting with
156  /// no data availability signs.
158 
159  /// Thread entered idle state due to absence of any data and
160  /// while other threads are waiting for new incoming data.
161  Redundant
162  };
163  };
164 
165  //
167 
168  /// Listener for thread-related events.
169  ///
170  /// Members of this classes are invoked to reflect
171  /// various life-time events of threads spawned and
172  /// used by the feed engine while processing market data.
173  struct ONIXS_CBOECFE_PITCH_API FeedEngineListener
174  {
175  /// Member invoked by feed engine when
176  /// a new processing thread is spawned.
177  ///
178  /// @note Invocation is done within newly
179  /// started thread.
180  virtual void onFeedEngineThreadBegin(const FeedEngine&) {}
181 
182  /// Member is invoked by feed engine when
183  /// processing thread is about to end.
184  ///
185  /// @note Invocation is done within the
186  /// thread that is about to end.
187  virtual void onFeedEngineThreadEnd(const FeedEngine&) {}
188 
189  /// Is called when feed engine's thread is idle.
190  ///
191  /// Thread becomes idle when either no data is received within
192  /// time interval defined by FeedEngineSettings::dataWaitTime
193  /// parameter or no pending data is available for processing.
194  /// In the first case, callback is invoked with 'DataWaitTimeout'
195  /// reason. In the second case, thread is considered as redundant
196  /// and thus callback is invoked with 'Redundant' reason.
197  /// After callback invocation threads may sleep in kernel to reduce
198  /// load onto CPU and racing between feed engine working threads.
199  ///
200  /// Integer parameter-variable defines amount of time feed engine
201  /// suggest for thread to sleep in kernel after invoking given member.
203  };
204 
205  class FeedEngineImpl;
206 
207  /// Manages processing machinery for market data received from feeds.
208  class ONIXS_CBOECFE_PITCH_API FeedEngine
209  {
210  public:
211  /// Initializes engine with given configuration.
212  explicit
213  FeedEngine(const FeedEngineSettings&, FeedEngineListener* = ONIXS_BATS_PITCH_NULLPTR);
214 
215  /// Destructs given instance.
216  ~FeedEngine();
217 
218  /// Settings used define behavior of given instance.
219  const FeedEngineSettings& settings() const;
220 
221  private:
222  // Copying is not supposed for given class.
223  FeedEngine(const FeedEngine&);
224  FeedEngine& operator =(const FeedEngine&);
225 
226  friend class FeedEngineImpl;
227 
228  FeedEngineImpl* impl_;
229  };
230  }
231  }
232  }
233 }
Identifies reasons feed engine threads becomes idle.
Definition: FeedEngine.h:150
virtual void onFeedEngineThreadBegin(const FeedEngine &)
Definition: FeedEngine.h:180
Manages processing machinery for market data received from feeds.
Definition: FeedEngine.h:208
virtual void onFeedEngineThreadEnd(const FeedEngine &)
Definition: FeedEngine.h:187
const ThreadAffinity & threadAffinity() const
Definition: FeedEngine.h:59
ONIXS_CBOECFE_PITCH_API std::ostream & operator<<(std::ostream &stream, const ServiceDescriptor &descriptor)
virtual void onFeedEngineThreadIdle(const FeedEngine &, FeedEngineThreadIdle::Reason, UInt32 &)
Definition: FeedEngine.h:202
void socketBufferSize(UInt32 value)
Sets udpSocketBufferSize.
Definition: FeedEngine.h:138
Collection of settings affecting Feed Engine behavior.
Definition: FeedEngine.h:37
void spinBeforeIdleTime(UInt32 value)
Sets redundancySpinTime.
Definition: FeedEngine.h:124
void threadCount(UInt32 value)
Sets threadsCount.
Definition: FeedEngine.h:85
Represents set of CPU indices.
Definition: Defines.h:131
void dataWaitTime(UInt32 value)
Sets dataWaitTime.
Definition: FeedEngine.h:105
ONIXS_CBOECFE_PITCH_API_DECL(struct, DataSource)