1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "common/errno.h"
5 #include "common/Throttle.h"
6 #include "common/WorkQueue.h"
10 #include "rgw_frontend.h"
11 #include "rgw_request.h"
12 #include "rgw_process.h"
13 #include "rgw_loadgen.h"
14 #include "rgw_client_io.h"
18 #define dout_subsys ceph_subsys_rgw
20 extern void signal_shutdown();
22 void RGWLoadGenProcess::checkpoint()
27 void RGWLoadGenProcess::run()
29 m_tp.start(); /* start thread pool */
35 conf->get_val("num_objs", 1000, &num_objs);
38 conf->get_val("num_buckets", 1, &num_buckets);
40 vector<string> buckets(num_buckets);
42 std::atomic<bool> failed = { false };
44 for (i = 0; i < num_buckets; i++) {
45 buckets[i] = "/loadgen";
46 string& bucket = buckets[i];
47 append_rand_alpha(NULL, bucket, bucket, 16);
49 /* first create a bucket */
50 gen_request("PUT", bucket, 0, &failed);
54 string *objs = new string[num_objs];
57 derr << "ERROR: bucket creation failed" << dendl;
61 for (i = 0; i < num_objs; i++) {
63 gen_rand_alphanumeric(NULL, buf, sizeof(buf));
65 objs[i] = buckets[i % num_buckets] + "/" + buf;
68 for (i = 0; i < num_objs; i++) {
69 gen_request("PUT", objs[i], 4096, &failed);
75 derr << "ERROR: bucket creation failed" << dendl;
79 for (i = 0; i < num_objs; i++) {
80 gen_request("GET", objs[i], 4096, NULL);
85 for (i = 0; i < num_objs; i++) {
86 gen_request("DELETE", objs[i], 0, NULL);
91 for (i = 0; i < num_buckets; i++) {
92 gen_request("DELETE", buckets[i], 0, NULL);
103 } /* RGWLoadGenProcess::run() */
105 void RGWLoadGenProcess::gen_request(const string& method,
106 const string& resource,
107 int content_length, std::atomic<bool>* fail_flag)
109 RGWLoadGenRequest* req =
110 new RGWLoadGenRequest(store->get_new_req_id(), method, resource,
111 content_length, fail_flag);
112 dout(10) << "allocated request req=" << hex << req << dec << dendl;
115 } /* RGWLoadGenProcess::gen_request */
117 void RGWLoadGenProcess::handle_request(RGWRequest* r)
119 RGWLoadGenRequest* req = static_cast<RGWLoadGenRequest*>(r);
121 RGWLoadGenRequestEnv env;
123 utime_t tm = ceph_clock_now();
126 env.content_length = req->content_length;
127 env.content_type = "binary/octet-stream";
128 env.request_method = req->method;
129 env.uri = req->resource;
131 env.sign(access_key);
133 RGWLoadGenIO real_client_io(&env);
134 RGWRestfulIO client_io(cct, &real_client_io);
136 int ret = process_request(store, rest, req, uri_prefix,
137 *auth_registry, &client_io, olog);
139 /* we don't really care about return code */
140 dout(20) << "process_request() returned " << ret << dendl;
142 if (req->fail_flag) {
148 } /* RGWLoadGenProcess::handle_request */