Skip to content

Commit 8713de2

Browse files
committed
Feat[MQB]: dispatcher stats
Signed-off-by: Evgeny Malygin <[email protected]>
1 parent 01693b0 commit 8713de2

10 files changed

+438
-58
lines changed

src/groups/mqb/mqba/mqba_application.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ int Application::start(bsl::ostream& errorDescription)
309309
// Start dispatcher
310310
d_dispatcher_mp.load(new (*d_allocator_p) Dispatcher(
311311
mqbcfg::BrokerConfig::get().dispatcherConfig(),
312+
d_statController_mp->dispatcherStatContext(),
312313
d_scheduler_p,
313314
d_allocators.get("Dispatcher")),
314315
d_allocator_p);

src/groups/mqb/mqba/mqba_dispatcher.cpp

+21-1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,12 @@ int Dispatcher::startContext(bsl::ostream& errorDescription,
256256
DispatcherContext(config, d_allocator_p),
257257
d_allocator_p);
258258

259+
context->d_statContext_mp =
260+
mqbstat::DispatcherStatsUtil::initializeClientStatContext(
261+
d_statContext_p,
262+
mqbi::DispatcherClientType::toAscii(type),
263+
d_allocator_p);
264+
259265
// Create and start the threadPool
260266
context->d_threadPool_mp.load(
261267
new (*d_allocator_p)
@@ -360,6 +366,8 @@ void Dispatcher::queueEventCb(mqbi::DispatcherClientType::Enum type,
360366
case ProcessorPool::Event::MWCC_USER: {
361367
BALL_LOG_TRACE << "Dispatching Event to queue " << processorId
362368
<< " of " << type << " dispatcher: " << event->object();
369+
DispatcherContext& dispatcherContext = *(d_contexts[type]);
370+
363371
if (event->object().type() ==
364372
mqbi::DispatcherEventType::e_DISPATCHER) {
365373
const mqbi::DispatcherDispatcherEvent* realEvent =
@@ -380,7 +388,6 @@ void Dispatcher::queueEventCb(mqbi::DispatcherClientType::Enum type,
380388
}
381389
}
382390
else {
383-
DispatcherContext& dispatcherContext = *(d_contexts[type]);
384391
event->object().destination()->onDispatcherEvent(event->object());
385392
if (!event->object()
386393
.destination()
@@ -394,6 +401,11 @@ void Dispatcher::queueEventCb(mqbi::DispatcherClientType::Enum type,
394401
.setAddedToFlushList(true);
395402
}
396403
}
404+
405+
dispatcherContext.d_statContext_mp->adjustValue(
406+
mqbstat::DispatcherStats::Stat::e_DONE_START +
407+
event->object().type(),
408+
1);
397409
} break;
398410
case ProcessorPool::Event::MWCC_QUEUE_EMPTY: {
399411
flushClients(type, processorId);
@@ -449,11 +461,13 @@ void Dispatcher::onNewClient(mqbi::DispatcherClientType::Enum type,
449461
}
450462

451463
Dispatcher::Dispatcher(const mqbcfg::DispatcherConfig& config,
464+
mwcst::StatContext* statContext,
452465
bdlmt::EventScheduler* scheduler,
453466
bslma::Allocator* allocator)
454467
: d_allocator_p(allocator)
455468
, d_isStarted(false)
456469
, d_config(config)
470+
, d_statContext_p(statContext)
457471
, d_scheduler_p(scheduler)
458472
, d_contexts(allocator)
459473
{
@@ -582,6 +596,9 @@ Dispatcher::registerClient(mqbi::DispatcherClient* client,
582596
.setClientType(type)
583597
.setProcessorHandle(processor);
584598

599+
context.d_statContext_mp->adjustValue(
600+
mqbstat::DispatcherStats::Stat::e_CLIENT_COUNT,
601+
1);
585602
BALL_LOG_DEBUG << "Registered a new client to the dispatcher "
586603
<< "[Client: " << client->description()
587604
<< ", type: " << type << ", processor: " << processor
@@ -628,6 +645,9 @@ void Dispatcher::unregisterClient(mqbi::DispatcherClient* client)
628645
case mqbi::DispatcherClientType::e_QUEUE:
629646
case mqbi::DispatcherClientType::e_CLUSTER: {
630647
d_contexts[type]->d_loadBalancer.removeClient(client);
648+
d_contexts[type]->d_statContext_mp->adjustValue(
649+
mqbstat::DispatcherStats::Stat::e_CLIENT_COUNT,
650+
-1);
631651
} break;
632652
case mqbi::DispatcherClientType::e_UNDEFINED:
633653
case mqbi::DispatcherClientType::e_ALL:

src/groups/mqb/mqba/mqba_dispatcher.h

+17-6
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@
5252

5353
#include <mqbcfg_messages.h>
5454
#include <mqbi_dispatcher.h>
55+
#include <mqbstat_dispatcherstats.h>
5556
#include <mqbu_loadbalancer.h>
5657

5758
// MWC
5859
#include <mwcc_multiqueuethreadpool.h>
5960
#include <mwcex_executor.h>
61+
#include <mwcst_statcontext.h>
6062

6163
// BDE
6264
#include <ball_log.h>
@@ -245,6 +247,9 @@ class Dispatcher BSLS_CPP11_FINAL : public mqbi::Dispatcher {
245247
// for distributing clients
246248
// across processors
247249

250+
/// Stat context for this client type
251+
bslma::ManagedPtr<mwcst::StatContext> d_statContext_mp;
252+
248253
bsl::vector<DispatcherClientPtrVector> d_flushList;
249254
// Vector of vector of
250255
// pointers to
@@ -277,21 +282,23 @@ class Dispatcher BSLS_CPP11_FINAL : public mqbi::Dispatcher {
277282

278283
private:
279284
// DATA
285+
/// Allocator to use
280286
bslma::Allocator* d_allocator_p;
281-
// Allocator to use
282287

288+
/// True if this component is started
283289
bool d_isStarted;
284-
// True if this component is started
285290

291+
/// Configuration for the dispatcher
286292
mqbcfg::DispatcherConfig d_config;
287-
// Configuration for the dispatcher
288293

294+
/// Top-level stat context for all dispatcher client types
295+
mwcst::StatContext* d_statContext_p;
296+
297+
/// Event scheduler to use
289298
bdlmt::EventScheduler* d_scheduler_p;
290-
// Event scheduler to use
291299

300+
/// The various contexts, one for each ClientType
292301
bsl::vector<DispatcherContextSp> d_contexts;
293-
// The various context, one for each
294-
// ClientType
295302

296303
// FRIENDS
297304
friend class Dispatcher_ClientExecutor;
@@ -348,6 +355,7 @@ class Dispatcher BSLS_CPP11_FINAL : public mqbi::Dispatcher {
348355
/// All memory allocation will be performed using the specified
349356
/// `allocator`.
350357
Dispatcher(const mqbcfg::DispatcherConfig& config,
358+
mwcst::StatContext* statContext,
351359
bdlmt::EventScheduler* scheduler,
352360
bslma::Allocator* allocator);
353361

@@ -549,6 +557,9 @@ inline void Dispatcher::dispatchEvent(mqbi::DispatcherEvent* event,
549557
case mqbi::DispatcherClientType::e_QUEUE:
550558
case mqbi::DispatcherClientType::e_CLUSTER: {
551559
d_contexts[type]->d_processorPool_mp->enqueueEvent(event, handle);
560+
d_contexts[type]->d_statContext_mp->adjustValue(
561+
mqbstat::DispatcherStats::Stat::e_ENQ_START + event->type(),
562+
1);
552563
} break;
553564
case mqbi::DispatcherClientType::e_UNDEFINED:
554565
case mqbi::DispatcherClientType::e_ALL:

src/groups/mqb/mqba/mqba_dispatcher.t.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
// MQB
2020
#include <mqbcfg_messages.h>
2121
#include <mqbmock_dispatcher.h>
22+
#include <mqbstat_dispatcherstats.h>
2223

2324
// MWC
2425
#include <mwcex_bindutil.h>
@@ -118,8 +119,15 @@ static void test1_breathingTest()
118119
s_allocator_p);
119120
eventScheduler.start();
120121

122+
bsl::shared_ptr<mwcst::StatContext> statContext_sp(
123+
mqbstat::DispatcherStatsUtil::initializeStatContext(10,
124+
s_allocator_p));
125+
121126
{
122-
mqba::Dispatcher obj(dispatcherConfig, &eventScheduler, s_allocator_p);
127+
mqba::Dispatcher obj(dispatcherConfig,
128+
statContext_sp.get(),
129+
&eventScheduler,
130+
s_allocator_p);
123131
}
124132

125133
eventScheduler.stop();
@@ -211,7 +219,12 @@ static void test3_executorsSupport()
211219
dispatcherConfig.clusters().processorConfig().queueSizeHighWatermark() =
212220
100;
213221

222+
bsl::shared_ptr<mwcst::StatContext> statContext_sp(
223+
mqbstat::DispatcherStatsUtil::initializeStatContext(10,
224+
s_allocator_p));
225+
214226
mqba::Dispatcher dispatcher(dispatcherConfig,
227+
statContext_sp.get(),
215228
&eventScheduler,
216229
s_allocator_p);
217230

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Copyright 2018-2023 Bloomberg Finance L.P.
2+
// SPDX-License-Identifier: Apache-2.0
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+
// mqbstat_dispatcherstats.cpp -*-C++-*-
17+
#include <mqbstat_dispatcherstats.h>
18+
19+
#include <mqbscm_version.h>
20+
// BMQ
21+
#include <bmqt_uri.h>
22+
23+
// MQB
24+
#include <mqbi_cluster.h>
25+
#include <mqbi_domain.h>
26+
27+
// MWC
28+
#include <mwcst_statcontext.h>
29+
#include <mwcst_statutil.h>
30+
#include <mwcst_statvalue.h>
31+
32+
// BDE
33+
#include <bdld_datummapbuilder.h>
34+
#include <bdld_manageddatum.h>
35+
#include <bdlma_localsequentialallocator.h>
36+
#include <bsls_assert.h>
37+
38+
namespace BloombergLP {
39+
namespace mqbstat {
40+
41+
// ---------------------
42+
// class DomainStatsUtil
43+
// ---------------------
44+
45+
bsl::shared_ptr<mwcst::StatContext>
46+
DispatcherStatsUtil::initializeStatContext(int historySize,
47+
bslma::Allocator* allocator)
48+
{
49+
bdlma::LocalSequentialAllocator<2048> localAllocator(allocator);
50+
51+
mwcst::StatContextConfiguration config("dispatcher", &localAllocator);
52+
config.defaultHistorySize(historySize)
53+
.statValueAllocator(allocator)
54+
.storeExpiredSubcontextValues(true);
55+
56+
return bsl::shared_ptr<mwcst::StatContext>(
57+
new (*allocator) mwcst::StatContext(config, allocator),
58+
allocator);
59+
}
60+
61+
bslma::ManagedPtr<mwcst::StatContext>
62+
DispatcherStatsUtil::initializeClientStatContext(mwcst::StatContext* parent,
63+
const bslstl::StringRef& name,
64+
bslma::Allocator* allocator)
65+
{
66+
bdlma::LocalSequentialAllocator<2048> localAllocator(allocator);
67+
68+
mwcst::StatContextConfiguration statConfig(name, &localAllocator);
69+
statConfig.isTable(true)
70+
.value("enq_undefined")
71+
.value("enq_dispatcher")
72+
.value("enq_callback")
73+
.value("enq_control_msg")
74+
.value("enq_confirm")
75+
.value("enq_reject")
76+
.value("enq_push")
77+
.value("enq_put")
78+
.value("enq_ack")
79+
.value("enq_cluster_state")
80+
.value("enq_storage")
81+
.value("enq_recovery")
82+
.value("enq_replication_receipt")
83+
.value("done_undefined")
84+
.value("done_dispatcher")
85+
.value("done_callback")
86+
.value("done_control_msg")
87+
.value("done_confirm")
88+
.value("done_reject")
89+
.value("done_push")
90+
.value("done_put")
91+
.value("done_ack")
92+
.value("done_cluster_state")
93+
.value("done_storage")
94+
.value("done_recovery")
95+
.value("done_replication_receipt")
96+
.value("nb_client");
97+
return parent->addSubcontext(statConfig);
98+
}
99+
100+
} // close package namespace
101+
} // close enterprise namespace

0 commit comments

Comments
 (0)