Skip to content

Commit

Permalink
rest-bench: multiple fixes
Browse files Browse the repository at this point in the history
write seems to work

Signed-off-by: Yehuda Sadeh <[email protected]>
  • Loading branch information
Yehuda Sadeh authored and yehudasa committed May 4, 2012
1 parent 4fe068e commit 072c316
Showing 1 changed file with 64 additions and 22 deletions.
86 changes: 64 additions & 22 deletions src/tools/rest_bench.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,25 @@ void usage(ostream& out)
out << \
"usage: rest_bench [options] <seconds> <write|seq>\n"
"BENCHMARK OPTIONS\n"
" -t concurrent_operations\n"
" --concurrent-ios=concurrent_operations\n"
" --t concurrent_operations\n"
" select bucket by name\n"
" -b op-size\n"
" --block-size=op-size\n"
" set the size of write ops for put or benchmarking\n"
"REST CONFIG OPTIONS\n"
" --api-host=bhost\n"
" host name\n"
" --bucket=bucket\n"
" select bucket by name\n"
" --access-key=access_key\n"
" access key to RESTful storage provider\n"
" --secret=secret_key\n"
" secret key for the specified access key\n";
" secret key for the specified access key\n"
" --protocol=<http|https>\n"
" protocol to be used (default: http)\n"
" --uri_style=<path|vhost>\n"
" uri style in requests (default: path)\n";
}

static void usage_exit()
Expand All @@ -58,7 +64,7 @@ static void usage_exit()
}

struct req_context {
atomic_t complete;
bool complete;
S3Status status;
S3RequestContext *ctx;
void (*cb)(void *, void *);
Expand All @@ -69,7 +75,7 @@ struct req_context {
Mutex lock;
Cond cond;

req_context() : status(S3StatusOK), ctx(NULL), cb(NULL), arg(NULL), in_bl(NULL), off(0),
req_context() : complete(false), status(S3StatusOK), ctx(NULL), cb(NULL), arg(NULL), in_bl(NULL), off(0),
lock("req_context") {}
~req_context() {
if (ctx) {
Expand Down Expand Up @@ -155,12 +161,21 @@ class RESTDispatcher {
void queue(req_context *ctx) {
req_wq.queue(ctx);
}

void start() {
m_tp.start();
}
};

void RESTDispatcher::process_context(req_context *ctx)
{
S3Status status = S3_runall_request_context(ctx->ctx);
generic_dout(0) << "processed request, status=" << status << dendl;

if (status != S3StatusOK) {
cerr << "ERROR: S3_runall_request_context() returned " << S3_get_status_name(status) << std::endl;
} else if (ctx->status != S3StatusOK) {
cerr << "ERROR: " << S3_get_status_name(ctx->status) << std::endl;
}

Mutex::Locker l(ctx->lock);
ctx->cond.SignalAll();
Expand All @@ -177,8 +192,11 @@ static void complete_callback(S3Status status, const S3ErrorDetails *details, vo
return;

struct req_context *ctx = (struct req_context *)cb_data;
ctx->complete.set(1);

ctx->lock.Lock();
ctx->complete = true;
ctx->status = status;
ctx->lock.Unlock();

if (ctx->cb) {
ctx->cb((void *)ctx->cb, ctx->arg);
Expand Down Expand Up @@ -320,7 +338,7 @@ class RESTBencher : public ObjBencher {
S3_get_object(&bucket_ctx, oid.c_str(), NULL, 0, len, NULL,
&get_obj_handler, &ctx);

return ctx.ret();
return bl.length();
}
int sync_write(const std::string& oid, bufferlist& bl, size_t len) {
struct req_context ctx;
Expand All @@ -329,6 +347,7 @@ class RESTBencher : public ObjBencher {
return ret;
}
ctx.out_bl = bl;

S3_put_object(&bucket_ctx, oid.c_str(),
bl.length(),
NULL,
Expand All @@ -339,33 +358,36 @@ class RESTBencher : public ObjBencher {
}

bool completion_is_done(int slot) {
int val = completions[slot]->complete.read();
return (val != 0);
return completions[slot]->complete;
}

int completion_wait(int slot) {
req_context *ctx = completions[slot];

Mutex::Locker l(ctx->lock);

ctx->cond.Wait(ctx->lock);
while (!ctx->complete) {
ctx->cond.Wait(ctx->lock);
}

return 0;
}

int completion_ret(int slot) {
S3Status status = completions[slot]->status;
if (status >= 200 && status < 300)
return 0;
return -EIO;
if (status != S3StatusOK)
return -EIO;
return 0;
}

public:
RESTBencher(RESTDispatcher *_dispatcher) : dispatcher(_dispatcher), completions(NULL) {}
RESTBencher(RESTDispatcher *_dispatcher) : dispatcher(_dispatcher), completions(NULL) {
dispatcher->start();
}
~RESTBencher() { }

int init(string& _agent, string& _host, string& _bucket, S3Protocol _protocol,
string& _access_key, string& _secret) {
S3UriStyle uri_style, string& _access_key, string& _secret) {
user_agent = _agent;
host = _host;
bucket = _bucket;
Expand All @@ -378,6 +400,7 @@ class RESTBencher : public ObjBencher {
bucket_ctx.protocol = protocol;
bucket_ctx.accessKeyId = access_key.c_str();
bucket_ctx.secretAccessKey = secret.c_str();
bucket_ctx.uriStyle = uri_style;

struct req_context ctx;

Expand All @@ -397,6 +420,13 @@ class RESTBencher : public ObjBencher {
NULL, /* requestContext */
&response_handler, /* handler */
(void *)&ctx /* callbackData */);

ret = ctx.ret();
if (ret < 0) {
cerr << "ERROR: failed to create bucket: " << S3_get_status_name(ctx.status) << std::endl;
return ret;
}

return 0;
}
};
Expand All @@ -412,13 +442,14 @@ int main(int argc, const char **argv)

std::map < std::string, std::string > opts;
std::vector<const char*>::iterator i;
std::string val;
std::string host;
std::string val;
std::string user_agent;
std::string access_key;
std::string secret;
std::string bucket = DEFAULT_BUCKET;
S3Protocol protocol = S3ProtocolHTTP;
S3UriStyle uri_style = S3UriStylePath;
std::string proto_str;
int concurrent_ios = 16;
int op_size = 1 << 22;
Expand All @@ -438,6 +469,9 @@ int main(int argc, const char **argv)
/* nothing */
} else if (ceph_argparse_witharg(args, i, &bucket, "--bucket", (char*)NULL)) {
/* nothing */
} else if (ceph_argparse_witharg(args, i, &host, "--api-host", (char*)NULL)) {
cerr << "host=" << host << std::endl;
/* nothing */
} else if (ceph_argparse_witharg(args, i, &proto_str, "--protocol", (char*)NULL)) {
if (strcasecmp(proto_str.c_str(), "http") == 0) {
protocol = S3ProtocolHTTP;
Expand All @@ -448,6 +482,15 @@ int main(int argc, const char **argv)
usage_exit();
}
/* nothing */
} else if (ceph_argparse_witharg(args, i, &proto_str, "--uri-style", (char*)NULL)) {
if (strcasecmp(proto_str.c_str(), "vhost") == 0) {
uri_style = S3UriStyleVirtualHost;
} else if (strcasecmp(proto_str.c_str(), "path") == 0) {
uri_style = S3UriStylePath;
} else {
cerr << "bad protocol" << std::endl;
usage_exit();
}
} else if (ceph_argparse_witharg(args, i, &val, "-t", "--concurrent-ios", (char*)NULL)) {
concurrent_ios = strtol(val.c_str(), NULL, 10);
} else if (ceph_argparse_witharg(args, i, &val, "-b", "--block-size", (char*)NULL)) {
Expand All @@ -460,7 +503,7 @@ int main(int argc, const char **argv)
}

if (bucket.empty()) {
cerr << "bucket not specified" << std::endl;
cerr << "rest-bench: bucket not specified" << std::endl;
usage_exit();
}
if (args.size() < 2)
Expand All @@ -476,10 +519,8 @@ int main(int argc, const char **argv)
else
usage_exit();

host = g_conf->host;

if (host.empty()) {
cerr << "rest-bench: host not provided." << std::endl;
cerr << "rest-bench: api host not provided." << std::endl;
usage_exit();
}

Expand All @@ -495,12 +536,13 @@ int main(int argc, const char **argv)
if (user_agent.empty())
user_agent = DEFAULT_USER_AGENT;

RESTDispatcher dispatcher(g_ceph_context, g_conf->rgw_thread_pool_size);
RESTDispatcher dispatcher(g_ceph_context, concurrent_ios);

RESTBencher bencher(&dispatcher);

int ret = bencher.init(user_agent, host, bucket, protocol, access_key, secret);
int ret = bencher.init(user_agent, host, bucket, protocol, uri_style, access_key, secret);
if (ret < 0) {
cerr << "failed initializing benchmark" << std::endl;
exit(1);
}

Expand Down

0 comments on commit 072c316

Please sign in to comment.