QuantumLibrary
quantum_configuration.h
1 /*
2 ** Copyright 2018 Bloomberg Finance L.P.
3 **
4 ** Licensed under the Apache License, Version 2.0 (the "License");
5 ** you may not use this file except in compliance with the License.
6 ** You may obtain a copy of the License at
7 **
8 ** http://www.apache.org/licenses/LICENSE-2.0
9 **
10 ** Unless required by applicable law or agreed to in writing, software
11 ** distributed under the License is distributed on an "AS IS" BASIS,
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
15 */
16 #ifndef BLOOMBERG_QUANTUM_CONFIGURATION_H
17 #define BLOOMBERG_QUANTUM_CONFIGURATION_H
18 
19 #include <quantum/quantum_thread_traits.h>
20 #include <chrono>
21 #include <utility>
22 
23 namespace Bloomberg {
24 namespace quantum {
25 
26 //==============================================================================================
27 // class Configuration
28 //==============================================================================================
32 {
33 public:
34  enum class BackoffPolicy : int { Linear,
35  Exponential };
36 
39  static const std::string& getJsonSchema();
40 
43  static const std::string& getJsonSchemaUri();
44 
48  void setNumCoroutineThreads(int num);
49 
52  void setNumIoThreads(int num);
53 
58  void setPinCoroutineThreadsToCores(bool value);
59 
66  void setLoadBalanceSharedIoQueues(bool value);
67 
72  void setLoadBalancePollIntervalMs(std::chrono::milliseconds interval);
73 
77 
81  void setLoadBalancePollIntervalNumBackoffs(size_t numBackoffs);
82 
88  void setCoroQueueIdRangeForAny(const std::pair<int, int>& coroQueueIdRangeForAny);
89 
92  int getNumCoroutineThreads() const;
93 
96  int getNumIoThreads() const;
97 
100  bool getPinCoroutineThreadsToCores() const;
101 
104  bool getLoadBalanceSharedIoQueues() const;
105 
108  std::chrono::milliseconds getLoadBalancePollIntervalMs() const;
109 
113 
117 
121  const std::pair<int, int>& getCoroQueueIdRangeForAny() const;
122 
123 private:
124  int _numCoroutineThreads{-1};
125  int _numIoThreads{5};
126  bool _pinCoroutineThreadsToCores{false};
127  bool _loadBalanceSharedIoQueues{false};
128  std::chrono::milliseconds _loadBalancePollIntervalMs{100};
129  BackoffPolicy _loadBalancePollIntervalBackoffPolicy{BackoffPolicy::Linear};
130  size_t _loadBalancePollIntervalNumBackoffs{0};
131  std::pair<int, int> _coroQueueIdRangeForAny{-1, -1};
132 };
133 
134 }}
135 
136 #include <quantum/impl/quantum_configuration_impl.h>
137 
138 #endif //BLOOMBERG_QUANTUM_CONFIGURATION_H
size_t getLoadBalancePollIntervalNumBackoffs() const
Get the number of backoffs used.
Definition: quantum_buffer_impl.h:22
void setNumIoThreads(int num)
Set the number of threads running IO tasks.
int getNumIoThreads() const
Get the number of IO threads.
std::chrono::milliseconds getLoadBalancePollIntervalMs() const
Get load balance shared queue poll interval.
void setCoroQueueIdRangeForAny(const std::pair< int, int > &coroQueueIdRangeForAny)
Sets the range of coroutine queueIds covered by IQueue::QueueId::Any when using Dispatcher::post.
bool getLoadBalanceSharedIoQueues() const
Check if IO shared queues are load balanced or not.
void setNumCoroutineThreads(int num)
Set the number of threads running coroutines.
void setPinCoroutineThreadsToCores(bool value)
Indicate if coroutine threads should be pinned to a core.
void setLoadBalancePollIntervalMs(std::chrono::milliseconds interval)
Set the interval between IO thread polls.
bool getPinCoroutineThreadsToCores() const
Check to see if coroutine threads are pinned to cores or not.
static const std::string & getJsonSchema()
Get the JSON schema corresponding to this configuration object.
Definition: quantum_configuration.h:31
void setLoadBalanceSharedIoQueues(bool value)
Load balancee the shared IO queues.
void setLoadBalancePollIntervalNumBackoffs(size_t numBackoffs)
Set the number of backoffs.
static const std::string & getJsonSchemaUri()
Get the schema URI used to resolve remote JSON references '$ref'.
BackoffPolicy getLoadBalancePollIntervalBackoffPolicy() const
Get the backoff policy in load balance mode.
int getNumCoroutineThreads() const
Get the number of coroutine threads.
BackoffPolicy
Definition: quantum_configuration.h:34
void setLoadBalancePollIntervalBackoffPolicy(BackoffPolicy policy)
Set a backoff policy for the shared queue polling interval.
const std::pair< int, int > & getCoroQueueIdRangeForAny() const
Gets the range [minQueueId, maxQueueId] of coroutine queueIds covered by IQueue::QueueId::Any by the ...