QuantumLibrary
quantum_configuration_impl.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 //NOTE: DO NOT INCLUDE DIRECTLY
17 
18 //##############################################################################################
19 //#################################### IMPLEMENTATIONS #########################################
20 //##############################################################################################
21 
22 namespace Bloomberg {
23 namespace quantum {
24 
25 inline
26 const std::string& Configuration::getJsonSchema()
27 {
28  static std::string schema = R"JSON(
29  {
30  "$schema" : "http://json-schema.org/draft-04/schema#",
31  "$id" : "bloomberg:quantum.json",
32  "title": "Quantum library settings",
33  "type": "object",
34  "properties": {
35  "numCoroutineThreads": {
36  "type": "number",
37  "default": -1
38  },
39  "numIoThreads": {
40  "type": "number",
41  "default": 5
42 
43  },
44  "pinToCores": {
45  "type": "boolean",
46  "default": false
47  },
48  "loadBalanceSharedIoQueues": {
49  "type": "boolean",
50  "default": false
51  },
52  "loadBalancePollIntervalMs": {
53  "type": "number",
54  "default": 100
55  },
56  "loadBalancePollIntervalBackoffPolicy": {
57  "type": "string",
58  "enum": [
59  "exponential",
60  "linear"
61  ],
62  "default": "linear"
63  },
64  "loadBalancePollIntervalNumBackoffs": {
65  "type": "number",
66  "default": 0
67  },
68  "coroQueueIdRangeForAnyLow": {
69  "type": "number",
70  "default": -1
71  },
72  "coroQueueIdRangeForAnyHigh": {
73  "type": "number",
74  "default": -1
75  }
76  },
77  "additionalProperties": false,
78  "required": []
79  }
80  )JSON";
81  return schema;
82 }
83 
84 inline
85 const std::string& Configuration::getJsonSchemaUri()
86 {
87  static std::string uri = "bloomberg:quantum.json";
88  return uri;
89 }
90 
91 inline
93 {
94  _numCoroutineThreads = num;
95 }
96 
97 inline
99 {
100  _numIoThreads = num;
101 }
102 
103 inline
105 {
106  _pinCoroutineThreadsToCores = value;
107 }
108 
109 inline
111 {
112  _loadBalanceSharedIoQueues = value;
113 }
114 
115 inline
116 void Configuration::setLoadBalancePollIntervalMs(std::chrono::milliseconds interval)
117 {
118  _loadBalancePollIntervalMs = interval;
119 }
120 
121 inline
123 {
124  _loadBalancePollIntervalBackoffPolicy = policy;
125 }
126 
127 inline
129 {
130  _loadBalancePollIntervalNumBackoffs = numBackoffs;
131 }
132 
133 inline
134 void Configuration::setCoroQueueIdRangeForAny(const std::pair<int, int>& coroQueueIdRangeForAny)
135 {
136  _coroQueueIdRangeForAny = coroQueueIdRangeForAny;
137 }
138 
139 inline
141 {
142  return _numCoroutineThreads;
143 }
144 
145 inline
147 {
148  return _numIoThreads;
149 }
150 
151 inline
153 {
154  return _pinCoroutineThreadsToCores;
155 }
156 
157 inline
159 {
160  return _loadBalanceSharedIoQueues;
161 }
162 
163 inline
164 std::chrono::milliseconds Configuration::getLoadBalancePollIntervalMs() const
165 {
166  return _loadBalancePollIntervalMs;
167 }
168 
169 inline
171 {
172  return _loadBalancePollIntervalBackoffPolicy;
173 }
174 
175 inline
177 {
178  return _loadBalancePollIntervalNumBackoffs;
179 }
180 
181 inline
182 const std::pair<int, int>& Configuration::getCoroQueueIdRangeForAny() const
183 {
184  return _coroQueueIdRangeForAny;
185 }
186 
187 }
188 }
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.
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 ...