]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/rgw/bench_rgw_ratelimit_gc.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / test / rgw / bench_rgw_ratelimit_gc.cc
1 #include "rgw_ratelimit.h"
2 #include "rgw_common.h"
3 #include "random"
4 #include <cstdlib>
5 #include <string>
6 #include <chrono>
7 #include <boost/program_options.hpp>
8 int main(int argc, char **argv)
9 {
10 int num_qos_classes = 1;
11 try
12 {
13 using namespace boost::program_options;
14 options_description desc{"Options"};
15 desc.add_options()
16 ("help,h", "Help screen")
17 ("num_qos_classes", value<int>()->default_value(1), "how many qos tenants");
18 variables_map vm;
19 store(parse_command_line(argc, argv, desc), vm);
20 if (vm.count("help")) {
21 std::cout << desc << std::endl;
22 return EXIT_SUCCESS;
23 }
24 num_qos_classes = vm["num_qos_classes"].as<int>();
25 }
26 catch (const boost::program_options::error &ex)
27 {
28 std::cerr << ex.what() << std::endl;
29 return EXIT_FAILURE;
30 }
31 RGWRateLimitInfo info;
32 info.enabled = true;
33 info.max_read_bytes = 0;
34 info.max_write_bytes = 0;
35 info.max_read_ops = 0;
36 info.max_write_ops = 0;
37 std::unique_ptr<CephContext> cct = std::make_unique<CephContext>(CEPH_ENTITY_TYPE_ANY);
38 if (!g_ceph_context)
39 {
40 g_ceph_context = cct.get();
41 }
42 std::shared_ptr<ActiveRateLimiter> ratelimit(new ActiveRateLimiter(g_ceph_context));
43 ratelimit->start();
44 auto dout = DoutPrefix(g_ceph_context, ceph_subsys_rgw, "rate limiter: ");
45 for(int i = 0; i < num_qos_classes; i++)
46 {
47 std::string tenant = "uuser" + std::to_string(i);
48 auto time = ceph::coarse_real_clock::now();
49 ratelimit->get_active()->should_rate_limit("PUT", tenant, time, &info);
50 }
51
52 }