Skip to content

Commit 125a2f6

Browse files
author
Alexander Damian
committed
Added json schema for the sequencer configuration.
Moved schema getters into base classes. Return reference to self for easier chaining when using config setters. Signed-off-by: Alexander Damian <[email protected]>
1 parent 342ba0e commit 125a2f6

File tree

4 files changed

+123
-45
lines changed

4 files changed

+123
-45
lines changed

quantum/impl/quantum_configuration_impl.h

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace Bloomberg {
2323
namespace quantum {
2424

2525
inline
26-
const std::string& Configuration::getJsonSchema()
26+
const std::string& ConfigurationSchemaProvider::getJsonSchema()
2727
{
2828
static std::string schema = R"JSON(
2929
{
@@ -85,64 +85,73 @@ const std::string& Configuration::getJsonSchema()
8585
}
8686

8787
inline
88-
const std::string& Configuration::getJsonSchemaUri()
88+
const std::string& ConfigurationSchemaProvider::getJsonSchemaUri()
8989
{
9090
static std::string uri = "bloomberg:quantum.json";
9191
return uri;
9292
}
9393

9494
inline
95-
void Configuration::setNumCoroutineThreads(int num)
95+
Configuration& Configuration::setNumCoroutineThreads(int num)
9696
{
9797
_numCoroutineThreads = num;
98+
return *this;
9899
}
99100

100101
inline
101-
void Configuration::setNumIoThreads(int num)
102+
Configuration& Configuration::setNumIoThreads(int num)
102103
{
103104
_numIoThreads = num;
105+
return *this;
104106
}
105107

106108
inline
107-
void Configuration::setPinCoroutineThreadsToCores(bool value)
109+
Configuration& Configuration::setPinCoroutineThreadsToCores(bool value)
108110
{
109111
_pinCoroutineThreadsToCores = value;
112+
return *this;
110113
}
111114

112115
inline
113-
void Configuration::setLoadBalanceSharedIoQueues(bool value)
116+
Configuration& Configuration::setLoadBalanceSharedIoQueues(bool value)
114117
{
115118
_loadBalanceSharedIoQueues = value;
119+
return *this;
116120
}
117121

118122
inline
119-
void Configuration::setLoadBalancePollIntervalMs(std::chrono::milliseconds interval)
123+
Configuration& Configuration::setLoadBalancePollIntervalMs(std::chrono::milliseconds interval)
120124
{
121125
_loadBalancePollIntervalMs = interval;
126+
return *this;
122127
}
123128

124129
inline
125-
void Configuration::setLoadBalancePollIntervalBackoffPolicy(BackoffPolicy policy)
130+
Configuration& Configuration::setLoadBalancePollIntervalBackoffPolicy(BackoffPolicy policy)
126131
{
127132
_loadBalancePollIntervalBackoffPolicy = policy;
133+
return *this;
128134
}
129135

130136
inline
131-
void Configuration::setLoadBalancePollIntervalNumBackoffs(size_t numBackoffs)
137+
Configuration& Configuration::setLoadBalancePollIntervalNumBackoffs(size_t numBackoffs)
132138
{
133139
_loadBalancePollIntervalNumBackoffs = numBackoffs;
140+
return *this;
134141
}
135142

136143
inline
137-
void Configuration::setCoroQueueIdRangeForAny(const std::pair<int, int>& coroQueueIdRangeForAny)
144+
Configuration& Configuration::setCoroQueueIdRangeForAny(const std::pair<int, int>& coroQueueIdRangeForAny)
138145
{
139146
_coroQueueIdRangeForAny = coroQueueIdRangeForAny;
147+
return *this;
140148
}
141149

142150
inline
143-
void Configuration::setCoroutineSharingForAny(bool sharing)
151+
Configuration& Configuration::setCoroutineSharingForAny(bool sharing)
144152
{
145153
_coroutineSharingForAny = sharing;
154+
return *this;
146155
}
147156

148157
inline

quantum/quantum_configuration.h

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,78 +24,96 @@
2424
namespace Bloomberg {
2525
namespace quantum {
2626

27+
//==============================================================================================
28+
// class ConfigurationSchemaProvider
29+
//==============================================================================================
30+
/// @class ConfigurationSchemaProvider
31+
/// @brief Provides static accessors to a json schema representing a Configuration object
32+
struct ConfigurationSchemaProvider
33+
{
34+
/// @brief Get the JSON schema corresponding to this configuration object.
35+
/// @return The draft-04 compatible schema.
36+
static const std::string& getJsonSchema();
37+
38+
/// @brief Get the schema URI used to resolve remote JSON references '$ref'.
39+
/// @return The URI.
40+
static const std::string& getJsonSchemaUri();
41+
};
42+
2743
//==============================================================================================
2844
// class Configuration
2945
//==============================================================================================
3046
/// @class class Configuration.
3147
/// @brief Configuration parameters for the Quantum library.
32-
class Configuration
48+
class Configuration : public ConfigurationSchemaProvider
3349
{
3450
public:
3551
enum class BackoffPolicy : int {
3652
Linear = QUANTUM_BACKOFF_LINEAR, ///< Linear backoff
3753
Exponential = QUANTUM_BACKOFF_EXPONENTIAL ///< Exponential backoff (doubles every time)
3854
};
39-
/// @brief Get the JSON schema corresponding to this configuration object.
40-
/// @return The draft-04 compatible schema.
41-
static const std::string& getJsonSchema();
42-
43-
/// @brief Get the schema URI used to resolve remote JSON references '$ref'.
44-
/// @return The URI.
45-
static const std::string& getJsonSchemaUri();
4655

4756
/// @brief Set the number of threads running coroutines.
4857
/// @param[in] num The number of threads. Set to -1 to have one coroutine thread per core.
4958
/// Default is -1.
50-
void setNumCoroutineThreads(int num);
59+
/// @return A reference to itself
60+
Configuration& setNumCoroutineThreads(int num);
5161

5262
/// @brief Set the number of threads running IO tasks.
5363
/// @param[in] num The number of threads. Default is 5.
54-
void setNumIoThreads(int num);
64+
/// @return A reference to itself
65+
Configuration& setNumIoThreads(int num);
5566

5667
/// @brief Indicate if coroutine threads should be pinned to a core.
5768
/// @param[in] value True or False. Default is False.
5869
/// @note For best performance, the number of coroutine threads should
5970
/// be <= the number of cores in the system.
60-
void setPinCoroutineThreadsToCores(bool value);
71+
/// @return A reference to itself
72+
Configuration& setPinCoroutineThreadsToCores(bool value);
6173

62-
/// @brief Load balancee the shared IO queues.
74+
/// @brief Load balance the shared IO queues.
6375
/// @param[in] value If set to true, posting to the 'any' IO queue will result in
6476
/// the load being spread among N queues. This mode can provide higher
6577
/// throughput if dealing with high task loads. Default is false.
6678
/// @note To achieve higher performance, the threads run in polling mode which
6779
/// increases CPU usage even when idle.
68-
void setLoadBalanceSharedIoQueues(bool value);
80+
/// @return A reference to itself
81+
Configuration& setLoadBalanceSharedIoQueues(bool value);
6982

7083
/// @brief Set the interval between IO thread polls.
7184
/// @param[in] interval Interval in milliseconds. Default is 100ms.
7285
/// @note Setting this to a higher value means it may take longer to react to the first
7386
/// IO task posted, and vice-versa if the interval is lower.
74-
void setLoadBalancePollIntervalMs(std::chrono::milliseconds interval);
87+
/// @return A reference to itself
88+
Configuration& setLoadBalancePollIntervalMs(std::chrono::milliseconds interval);
7589

7690
/// @brief Set a backoff policy for the shared queue polling interval.
7791
/// @param[in] policy The backoff policy to use. Default is 'Linear'.
78-
void setLoadBalancePollIntervalBackoffPolicy(BackoffPolicy policy);
92+
/// @return A reference to itself
93+
Configuration& setLoadBalancePollIntervalBackoffPolicy(BackoffPolicy policy);
7994

8095
/// @brief Set the number of backoffs.
8196
/// @param[in] numBackoffs The number of backoff increments. Default is 0.
8297
/// When the number of backoffs is reached, the poll interval remains unchanged thereafter.
83-
void setLoadBalancePollIntervalNumBackoffs(size_t numBackoffs);
98+
/// @return A reference to itself
99+
Configuration& setLoadBalancePollIntervalNumBackoffs(size_t numBackoffs);
84100

85101
/// @brief Sets the range of coroutine queueIds covered by IQueue::QueueId::Any when using Dispatcher::post
86102
/// @param[in] coroQueueIdRangeForAny The range [minQueueId, maxQueueId] of queueIds that IQueue::QueueId::Any
87103
/// will cover.
88104
/// @remark if the provided range is empty or invalid, then the default range of
89105
/// std::pair<int, int>(0, getNumCoroutineThreads()-1) will be used
90-
void setCoroQueueIdRangeForAny(const std::pair<int, int>& coroQueueIdRangeForAny);
106+
/// @return A reference to itself
107+
Configuration& setCoroQueueIdRangeForAny(const std::pair<int, int>& coroQueueIdRangeForAny);
91108

92109
/// @brief Enables or disables the shared-coro-queue-for-any settings
93110
/// @param[in] isSharedCoroQueueForAny sets the shared-coro-queue-for any setting
94111
/// @warning When the coroutine sharing feature is enabled, then after each yield
95112
/// (explicit or implicit) a coroutine sent to the Any queue may be executed by
96113
/// a different thread. As a result, coroutines using thread-local-storage (e.g., via thread_local),
97114
/// will _not_ work as expected.
98-
void setCoroutineSharingForAny(bool sharing);
115+
/// @return A reference to itself
116+
Configuration& setCoroutineSharingForAny(bool sharing);
99117

100118
/// @brief Get the number of coroutine threads.
101119
/// @return The number of threads.

quantum/util/impl/quantum_sequencer_configuration_impl.h

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,45 @@ struct SequenceKeyData
3535
StatsPtr _stats;
3636
};
3737

38+
inline const std::string&
39+
SequencerConfigurationSchemaProvider::getJsonSchema()
40+
{
41+
static std::string schema = R"JSON(
42+
{
43+
"$schema" : "http://json-schema.org/draft-04/schema#",
44+
"$id" : "bloomberg:sequencer.quantum.json",
45+
"title": "Quantum sequencer settings",
46+
"type": "object",
47+
"properties": {
48+
"controlQueueId": {
49+
"type": "number",
50+
"default": 0
51+
},
52+
"bucketCount": {
53+
"type": "number",
54+
"default": 100
55+
}
56+
},
57+
"additionalProperties": false,
58+
"required": []
59+
}
60+
)JSON";
61+
return schema;
62+
}
63+
64+
inline const std::string&
65+
SequencerConfigurationSchemaProvider::getJsonSchemaUri()
66+
{
67+
static std::string uri = "bloomberg:sequencer.quantum.json";
68+
return uri;
69+
}
70+
3871
template <class SequenceKey, class Hash, class KeyEqual, class Allocator>
39-
void
72+
SequencerConfiguration<SequenceKey, Hash, KeyEqual, Allocator>&
4073
SequencerConfiguration<SequenceKey, Hash, KeyEqual, Allocator>::setControlQueueId(int controlQueueId)
4174
{
4275
_controllerQueueId = controlQueueId;
76+
return *this;
4377
}
4478

4579
template <class SequenceKey, class Hash, class KeyEqual, class Allocator>
@@ -50,10 +84,11 @@ SequencerConfiguration<SequenceKey, Hash, KeyEqual, Allocator>::getControlQueueI
5084
}
5185

5286
template <class SequenceKey, class Hash, class KeyEqual, class Allocator>
53-
void
87+
SequencerConfiguration<SequenceKey, Hash, KeyEqual, Allocator>&
5488
SequencerConfiguration<SequenceKey, Hash, KeyEqual, Allocator>::setBucketCount(size_t bucketCount)
5589
{
5690
_bucketCount = bucketCount;
91+
return *this;
5792
}
5893

5994
template <class SequenceKey, class Hash, class KeyEqual, class Allocator>

quantum/util/quantum_sequencer_configuration.h

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@ namespace quantum {
2525

2626
struct SequenceKeyData;
2727

28+
//==============================================================================================
29+
// class SequencerConfigurationSchemaProvider
30+
//==============================================================================================
31+
/// @class SequencerConfigurationSchemaProvider
32+
/// @brief Provides static accessors to a json schema representing a SequencerConfiguration object
33+
struct SequencerConfigurationSchemaProvider
34+
{
35+
/// @brief Get the JSON schema corresponding to this configuration object.
36+
/// @return The draft-04 compatible schema.
37+
static const std::string& getJsonSchema();
38+
39+
/// @brief Get the schema URI used to resolve remote JSON references '$ref'.
40+
/// @return The URI.
41+
static const std::string& getJsonSchemaUri();
42+
};
43+
2844
//==============================================================================================
2945
// class SequencerConfiguration
3046
//==============================================================================================
@@ -38,29 +54,29 @@ template <class SequenceKey,
3854
class Hash = std::hash<SequenceKey>,
3955
class KeyEqual = std::equal_to<SequenceKey>,
4056
class Allocator = std::allocator<std::pair<const SequenceKey, SequenceKeyData>>>
41-
class SequencerConfiguration
57+
class SequencerConfiguration : public SequencerConfigurationSchemaProvider
4258
{
43-
public:
44-
59+
public:
4560
/// @brief Callback for unhandled exceptions in tasks posted to Sequencer
4661
/// @param exception pointer to the thrown exception
4762
/// @param opaque opaque data passed when posting a task
4863
using ExceptionCallback = std::function<void(std::exception_ptr exception, void* opaque)>;
49-
50-
public:
64+
5165
/// @brief Sets the id of the control queue
5266
/// @param controlQueueId the queue id
5367
/// @remark Sequencer typically processes tasks with the lower latency when the control queue is
54-
/// dedicated for the sequencer control tasks only, and no other tasks are enqueued into it.
55-
void setControlQueueId(int controlQueueId);
68+
/// dedicated for the sequencer control tasks only, and no other tasks are enqueued into it.
69+
/// @return A reference to itself
70+
SequencerConfiguration& setControlQueueId(int controlQueueId);
5671

5772
/// @brief Gets the id of the control queue
5873
/// @return the queue id
5974
int getControlQueueId() const;
6075

6176
/// @brief Sets the minimal number of buckets to be used for the context hash map
6277
/// @param bucketCount the bucket number
63-
void setBucketCount(size_t bucketCount);
78+
/// @return A reference to itself
79+
SequencerConfiguration& setBucketCount(size_t bucketCount);
6480

6581
/// @brief gets the minimal number of buckets to be used for the context hash map
6682
/// @return the bucket number
@@ -99,12 +115,12 @@ class SequencerConfiguration
99115
const ExceptionCallback& getExceptionCallback() const;
100116

101117
private:
102-
int _controllerQueueId{0};
103-
size_t _bucketCount{0};
104-
Hash _hash;
105-
KeyEqual _keyEqual;
106-
Allocator _allocator;
107-
ExceptionCallback _exceptionCallback;
118+
int _controllerQueueId{0};
119+
size_t _bucketCount{100};
120+
Hash _hash;
121+
KeyEqual _keyEqual;
122+
Allocator _allocator;
123+
ExceptionCallback _exceptionCallback;
108124
};
109125

110126
}}

0 commit comments

Comments
 (0)