]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rest_bench: initial work
authorYehuda Sadeh <yehuda@hq.newdream.net>
Sat, 21 Apr 2012 00:36:00 +0000 (17:36 -0700)
committerYehuda Sadeh <yehuda@inktank.com>
Fri, 4 May 2012 22:53:26 +0000 (15:53 -0700)
Signed-off-by: Yehuda Sadeh <yehuda@hq.newdream.net>
src/Makefile.am
src/tools/rest_bench.cc [new file with mode: 0644]

index 33b2e8d2115bd874decb940b9ab851baa8e8e6e9..92aa9b6b60da0a993f5fbd5bc51791d9f692c8bc 100644 (file)
@@ -322,6 +322,10 @@ rados_SOURCES = rados.cc rados_import.cc rados_export.cc rados_sync.cc common/ob
 rados_LDADD = libglobal.la librados.la $(PTHREAD_LIBS) -lm $(CRYPTO_LIBS) $(EXTRALIBS)
 bin_PROGRAMS += rados
 
+rest_bench_SOURCES = tools/rest_bench.cc common/obj_bencher.cc
+rest_bench_LDADD = libglobal.la $(PTHREAD_LIBS) -lm $(CRYPTO_LIBS) $(EXTRALIBS) -ls3
+bin_PROGRAMS += rest-bench
+
 scratchtool_SOURCES = scratchtool.c
 scratchtool_LDADD = librados.la $(PTHREAD_LIBS) -lm $(CRYPTO_LIBS) $(EXTRALIBS)
 scratchtoolpp_SOURCES = scratchtoolpp.cc
diff --git a/src/tools/rest_bench.cc b/src/tools/rest_bench.cc
new file mode 100644 (file)
index 0000000..7853270
--- /dev/null
@@ -0,0 +1,152 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+#include "include/types.h"
+
+#include "common/obj_bencher.h"
+#include "common/config.h"
+#include "common/ceph_argparse.h"
+#include "global/global_init.h"
+
+#include "libs3.h"
+
+#include <errno.h>
+
+#define DEFAULT_USER_AGENT "rest-bench"
+#define DEFAULT_BUCKET "rest-bench-bucket"
+
+void usage(ostream& out)
+{
+  out <<                                       \
+"usage: rest_bench [options] [commands]\n"
+"COMMANDS\n"
+"\n";
+}
+
+static void usage_exit()
+{
+  usage(cerr);
+  exit(1);
+}
+
+class RESTBencher : public ObjBencher {
+  void **completions;
+protected:
+  int completions_init(int concurrentios) {
+    return 0;
+  }
+  void completions_done() {
+    delete[] completions;
+    completions = NULL;
+  }
+  int create_completion(int slot, void (*cb)(void *, void*), void *arg) {
+    if (!completions[slot])
+      return -EINVAL;
+
+    return 0;
+  }
+  void release_completion(int slot) {
+
+    completions[slot] = 0;
+  }
+
+  int aio_read(const std::string& oid, int slot, bufferlist *pbl, size_t len) {
+  }
+
+  int aio_write(const std::string& oid, int slot, const bufferlist& bl, size_t len) {
+  }
+
+  int sync_read(const std::string& oid, bufferlist& bl, size_t len) {
+  }
+  int sync_write(const std::string& oid, bufferlist& bl, size_t len) {
+  }
+
+  bool completion_is_done(int slot) {
+  }
+
+  int completion_wait(int slot) {
+  }
+  int completion_ret(int slot) {
+  }
+
+public:
+  RESTBencher() : completions(NULL) {}
+  ~RESTBencher() { }
+};
+
+int main(int argc, const char **argv)
+{
+  vector<const char*> args;
+  argv_to_vec(argc, argv, args);
+  env_to_vec(args);
+
+  global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
+  common_init_finish(g_ceph_context);
+
+  std::map < std::string, std::string > opts;
+  std::vector<const char*>::iterator i;
+  std::string val;
+  std::string host;
+  std::string user_agent;
+  std::string access_key;
+  std::string secret;
+  std::string bucket;
+  for (i = args.begin(); i != args.end(); ) {
+    if (ceph_argparse_double_dash(args, i)) {
+      break;
+    } else if (ceph_argparse_flag(args, i, "-h", "--help", (char*)NULL)) {
+      usage(cout);
+      exit(0);
+    } else if (ceph_argparse_witharg(args, i, &user_agent, "--agent", (char*)NULL)) {
+      /* nothing */
+    } else if (ceph_argparse_witharg(args, i, &user_agent, "--access-key", (char*)NULL)) {
+      /* nothing */
+    } else if (ceph_argparse_witharg(args, i, &user_agent, "--secret", (char*)NULL)) {
+      /* nothing */
+    } else if (ceph_argparse_witharg(args, i, &user_agent, "--bucket", (char*)NULL)) {
+      /* nothing */
+    } else {
+      if (val[0] == '-')
+        usage_exit();
+      i++;
+    }
+  }
+
+  host = g_conf->host;
+
+  if (host.empty()) {
+    cerr << "rest-bench: host not provided." << std::endl;
+    usage_exit();
+  }
+
+  if (access_key.empty() || secret.empty()) {
+    cerr << "rest-bench: access key or secret was not provided" << std::endl;
+    usage_exit();
+  }
+
+  if (bucket.empty()) {
+    bucket = DEFAULT_BUCKET;
+  }
+
+  if (user_agent.empty())
+    user_agent = DEFAULT_USER_AGENT;
+
+  S3Status status = S3_initialize(user_agent.c_str(), S3_INIT_ALL, host.c_str());
+  if (status != S3StatusOK) {
+    cerr << "failed to init: " << S3_get_status_name(status) << std::endl;
+  }
+
+  RESTBencher bencher();
+}
+