Skip to content

Commit 87dbfb6

Browse files
authored
Merge pull request ceph#56775 from cyx1231st/wip-crimson-osd-report-stats
crimson/osd: implement basic reactor-utilization stats report to log Reviewed-by: Samuel Just <[email protected]> Reviewed-by: chunmei-liu <[email protected]> Reviewed-by: Matan Breizman <[email protected]>
2 parents c5f0c17 + 99909d4 commit 87dbfb6

File tree

5 files changed

+51
-0
lines changed

5 files changed

+51
-0
lines changed

src/common/options/crimson.yaml.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ options:
3131
desc: CPU cores on which alienstore threads will run in cpuset(7) format
3232
flags:
3333
- startup
34+
- name: crimson_osd_stat_interval
35+
type: int
36+
level: advanced
37+
default: 0
38+
desc: Report OSD status periodically in seconds, 0 to disable
3439
- name: seastore_segment_size
3540
type: size
3641
desc: Segment size to use for SegmentManager

src/crimson/common/utility.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include <type_traits>
77

8+
#include <seastar/core/metrics_api.hh>
9+
810
namespace _impl {
911
template <class T> struct always_false : std::false_type {};
1012
};
@@ -36,3 +38,16 @@ auto apply_method_to_tuple(Obj &obj, Method method, ArgTuple &&tuple) {
3638
obj, method, std::forward<ArgTuple>(tuple),
3739
std::make_index_sequence<tuple_size>());
3840
}
41+
42+
inline double get_reactor_utilization() {
43+
auto &value_map = seastar::metrics::impl::get_value_map();
44+
auto found = value_map.find("reactor_utilization");
45+
assert(found != value_map.end());
46+
auto &[full_name, metric_family] = *found;
47+
std::ignore = full_name;
48+
assert(metric_family.size() == 1);
49+
const auto& [labels, metric] = *metric_family.begin();
50+
std::ignore = labels;
51+
auto value = (*metric)();
52+
return value.d();
53+
}

src/crimson/osd/osd.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,26 @@ seastar::future<> OSD::start()
387387
std::ref(osd_states));
388388
});
389389
}).then([this, FNAME] {
390+
auto stats_seconds = local_conf().get_val<int64_t>("crimson_osd_stat_interval");
391+
if (stats_seconds > 0) {
392+
shard_stats.resize(seastar::smp::count);
393+
stats_timer.set_callback([this, FNAME] {
394+
std::ignore = shard_services.invoke_on_all(
395+
[this](auto &local_service) {
396+
auto stats = local_service.report_stats();
397+
shard_stats[seastar::this_shard_id()] = stats;
398+
}).then([this, FNAME] {
399+
std::ostringstream oss;
400+
for (const auto &stats : shard_stats) {
401+
oss << int(stats.reactor_utilization);
402+
oss << ",";
403+
}
404+
INFO("reactor_utilizations: {}", oss.str());
405+
});
406+
});
407+
stats_timer.arm_periodic(std::chrono::seconds(stats_seconds));
408+
}
409+
390410
heartbeat.reset(new Heartbeat{
391411
whoami, get_shard_services(),
392412
*monc, *hb_front_msgr, *hb_back_msgr});
@@ -1320,6 +1340,7 @@ seastar::future<> OSD::restart()
13201340
{
13211341
beacon_timer.cancel();
13221342
tick_timer.cancel();
1343+
stats_timer.cancel();
13231344
return pg_shard_manager.set_up_epoch(
13241345
0
13251346
).then([this] {

src/crimson/osd/osd.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ class OSD final : public crimson::net::Dispatcher,
128128
std::unique_ptr<Heartbeat> heartbeat;
129129
seastar::timer<seastar::lowres_clock> tick_timer;
130130

131+
seastar::timer<seastar::lowres_clock> stats_timer;
132+
std::vector<ShardServices::shard_stats_t> shard_stats;
133+
131134
const char** get_tracked_conf_keys() const final;
132135
void handle_conf_change(const ConfigProxy& conf,
133136
const std::set<std::string> &changed) final;

src/crimson/osd/shard_services.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,13 @@ class ShardServices : public OSDMapService {
402402
return local_state.store;
403403
}
404404

405+
struct shard_stats_t {
406+
double reactor_utilization;
407+
};
408+
shard_stats_t report_stats() {
409+
return {get_reactor_utilization()};
410+
}
411+
405412
auto remove_pg(spg_t pgid) {
406413
local_state.pg_map.remove_pg(pgid);
407414
return pg_to_shard_mapping.remove_pg_mapping(pgid);

0 commit comments

Comments
 (0)