|
19 | 19 | #include "crimson/osd/pg.h" |
20 | 20 | #include "crimson/osd/shard_services.h" |
21 | 21 |
|
| 22 | +SET_SUBSYS(osd); |
22 | 23 | namespace { |
23 | 24 | seastar::logger& logger() |
24 | 25 | { |
@@ -93,6 +94,105 @@ class SendBeaconHook : public AdminSocketHook { |
93 | 94 | template std::unique_ptr<AdminSocketHook> |
94 | 95 | make_asok_hook<SendBeaconHook>(crimson::osd::OSD& osd); |
95 | 96 |
|
| 97 | +/** |
| 98 | + * An OSD admin hook: run bench |
| 99 | + * Usage parameters: |
| 100 | + * count=Count of bytes to write |
| 101 | + * bsize=block size |
| 102 | + * osize=Object size |
| 103 | + * onum=Number of objects |
| 104 | + */ |
| 105 | +class RunOSDBenchHook : public AdminSocketHook { |
| 106 | +public: |
| 107 | + explicit RunOSDBenchHook(crimson::osd::OSD& osd) : |
| 108 | + AdminSocketHook{"bench", |
| 109 | + "name=count,type=CephInt,req=false " |
| 110 | + "name=size,type=CephInt,req=false " |
| 111 | + "name=object_size,type=CephInt,req=false " |
| 112 | + "name=object_num,type=CephInt,req=false", |
| 113 | + "run OSD bench"}, |
| 114 | + osd(osd) |
| 115 | + {} |
| 116 | + seastar::future<tell_result_t> call(const cmdmap_t& cmdmap, |
| 117 | + std::string_view format, |
| 118 | + ceph::bufferlist&& input) const final |
| 119 | + { |
| 120 | + LOG_PREFIX(RunOSDBenchHook::call); |
| 121 | + int64_t count = cmd_getval_or<int64_t>(cmdmap, "count", 1LL << 30); |
| 122 | + int64_t bsize = cmd_getval_or<int64_t>(cmdmap, "size", 4LL << 20); |
| 123 | + int64_t osize = cmd_getval_or<int64_t>(cmdmap, "object_size", 0); |
| 124 | + int64_t onum = cmd_getval_or<int64_t>(cmdmap, "object_num", 0); |
| 125 | + auto duration = local_conf()->osd_bench_duration; |
| 126 | + auto max_block_size = local_conf()->osd_bench_max_block_size; |
| 127 | + if (bsize > static_cast<int64_t>(max_block_size)) { |
| 128 | + // let us limit the block size because the next checks rely on it |
| 129 | + // having a sane value. If we allow any block size to be set things |
| 130 | + // can still go sideways. |
| 131 | + INFO("block 'size' values are capped at {}. If you wish to use" |
| 132 | + " a higher value, please adjust 'osd_bench_max_block_size'", |
| 133 | + byte_u_t(max_block_size)); |
| 134 | + return seastar::make_ready_future<tell_result_t>(-EINVAL, "block size too large"); |
| 135 | + } else if (bsize < (1LL << 20)) { |
| 136 | + // entering the realm of small block sizes. |
| 137 | + // limit the count to a sane value, assuming a configurable amount of |
| 138 | + // IOPS and duration, so that the OSD doesn't get hung up on this, |
| 139 | + // preventing timeouts from going off |
| 140 | + int64_t max_count = bsize * duration * local_conf()->osd_bench_small_size_max_iops; |
| 141 | + if (count > max_count) { |
| 142 | + INFO("bench count {} > osd_bench_small_size_max_iops {}", |
| 143 | + count, max_count); |
| 144 | + return seastar::make_ready_future<tell_result_t>(-EINVAL, "count too large"); |
| 145 | + } |
| 146 | + } else { |
| 147 | + // 1MB block sizes are big enough so that we get more stuff done. |
| 148 | + // However, to avoid the osd from getting hung on this and having |
| 149 | + // timers being triggered, we are going to limit the count assuming |
| 150 | + // a configurable throughput and duration. |
| 151 | + // NOTE: max_count is the total amount of bytes that we believe we |
| 152 | + // will be able to write during 'duration' for the given |
| 153 | + // throughput. The block size hardly impacts this unless it's |
| 154 | + // way too big. Given we already check how big the block size |
| 155 | + // is, it's safe to assume everything will check out. |
| 156 | + int64_t max_count = local_conf()->osd_bench_large_size_max_throughput * duration; |
| 157 | + if (count > max_count) { |
| 158 | + INFO("'count' values greater than {} for a block size of {}," |
| 159 | + " assuming {} IOPS, for {} seconds, can cause ill effects" |
| 160 | + " on osd. Please adjust 'osd_bench_small_size_max_iops'" |
| 161 | + " with a higher value if you wish to use a higher 'count'.", |
| 162 | + max_count, byte_u_t(bsize), local_conf()->osd_bench_small_size_max_iops, |
| 163 | + duration); |
| 164 | + return seastar::make_ready_future<tell_result_t>(-EINVAL, "count too large"); |
| 165 | + } |
| 166 | + } |
| 167 | + if (osize && bsize > osize) { |
| 168 | + bsize = osize; |
| 169 | + } |
| 170 | + |
| 171 | + return osd.run_bench(count, bsize, osize, onum).then( |
| 172 | + [format, bsize, count](double elapsed) { |
| 173 | + if (elapsed < 0) { |
| 174 | + return seastar::make_ready_future<tell_result_t> |
| 175 | + (elapsed, "bench failed with error"); |
| 176 | + } |
| 177 | + |
| 178 | + unique_ptr<Formatter> f{Formatter::create(format, "json-pretty", "json-pretty")}; |
| 179 | + f->open_object_section("osd_bench_results"); |
| 180 | + f->dump_int("bytes_written", count); |
| 181 | + f->dump_int("blocksize", bsize); |
| 182 | + f->dump_float("elapsed_sec", elapsed); |
| 183 | + f->dump_float("bytes_per_sec", (elapsed > 0) ? count / elapsed : 0); |
| 184 | + f->dump_float("iops", (elapsed > 0) ? (count / elapsed) / bsize : 0); |
| 185 | + f->close_section(); |
| 186 | + |
| 187 | + return seastar::make_ready_future<tell_result_t>(std::move(f)); |
| 188 | + }); |
| 189 | + } |
| 190 | +private: |
| 191 | + crimson::osd::OSD& osd; |
| 192 | +}; |
| 193 | +template std::unique_ptr<AdminSocketHook> |
| 194 | +make_asok_hook<RunOSDBenchHook>(crimson::osd::OSD& osd); |
| 195 | + |
96 | 196 | /** |
97 | 197 | * send the latest pg stats to mgr |
98 | 198 | */ |
|
0 commit comments