Format code
parent
420debc2f5
commit
c0a05c8fea
2
Makefile
2
Makefile
|
@ -16,7 +16,7 @@ clean:
|
||||||
$(CC) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
|
$(CC) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
|
||||||
|
|
||||||
indent: *.cpp *.h
|
indent: *.cpp *.h
|
||||||
clang-format-6.0 -i $^
|
clang-format -style=Microsoft -i $^
|
||||||
|
|
||||||
builddep:
|
builddep:
|
||||||
sudo apt install -y --no-install-recommends libjsoncpp-dev libtcmalloc-minimal4
|
sudo apt install -y --no-install-recommends libjsoncpp-dev libtcmalloc-minimal4
|
||||||
|
|
47
main.cpp
47
main.cpp
|
@ -1,14 +1,14 @@
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <librados.hpp>
|
#include <librados.hpp>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <fstream>
|
#include <system_error>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <system_error>
|
|
||||||
|
|
||||||
#include "mysignals.h"
|
#include "mysignals.h"
|
||||||
#include "radosutil.h"
|
#include "radosutil.h"
|
||||||
|
@ -43,8 +43,7 @@ template <class T> static uint64_t dur2nsec(const T &dur)
|
||||||
return duration_cast<duration<uint64_t, nano>>(dur).count();
|
return duration_cast<duration<uint64_t, nano>>(dur).count();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T> static void print_breakdown(const vector<T> &all_ops, size_t thread_count)
|
||||||
static void print_breakdown(const vector<T> &all_ops, size_t thread_count)
|
|
||||||
{
|
{
|
||||||
T totaltime(0);
|
T totaltime(0);
|
||||||
|
|
||||||
|
@ -112,10 +111,7 @@ static void fill_urandom(char *buf, size_t len)
|
||||||
}
|
}
|
||||||
|
|
||||||
// May be called in a thread.
|
// May be called in a thread.
|
||||||
static void _do_bench(
|
static void _do_bench(const unique_ptr<bench_settings> &settings, const vector<string> &obj_names, IoCtx &ioctx,
|
||||||
const unique_ptr<bench_settings> &settings,
|
|
||||||
const vector<string> &obj_names,
|
|
||||||
IoCtx &ioctx,
|
|
||||||
vector<steady_clock::duration> &ops)
|
vector<steady_clock::duration> &ops)
|
||||||
{
|
{
|
||||||
// TODO: pass bufferlist as arguments
|
// TODO: pass bufferlist as arguments
|
||||||
|
@ -142,12 +138,8 @@ static void _do_bench(
|
||||||
while (b <= stop)
|
while (b <= stop)
|
||||||
{
|
{
|
||||||
abort_if_signalled();
|
abort_if_signalled();
|
||||||
if (ioctx.write(
|
if (ioctx.write(obj_names[rand() % 16], (ops.size() % 2) ? bar1 : bar2, settings->block_size,
|
||||||
obj_names[rand() % 16],
|
settings->block_size * (rand() % (settings->object_size / settings->block_size))) < 0)
|
||||||
(ops.size() % 2) ? bar1 : bar2,
|
|
||||||
settings->block_size,
|
|
||||||
settings->block_size * (rand() % (settings->object_size / settings->block_size))
|
|
||||||
) < 0)
|
|
||||||
{
|
{
|
||||||
throw "Write error";
|
throw "Write error";
|
||||||
}
|
}
|
||||||
|
@ -182,7 +174,9 @@ static void do_bench(const unique_ptr<bench_settings> &settings, const vector<st
|
||||||
throw std::system_error(err, std::system_category(), "Failed to set thread sigmask");
|
throw std::system_error(err, std::system_category(), "Failed to set thread sigmask");
|
||||||
}
|
}
|
||||||
|
|
||||||
threads.push_back(thread(_do_bench, ref(settings), vector<string>(names.begin()+i*16, names.begin()+i*16+16), ref(ioctx), ref(listofops[i])));
|
threads.push_back(thread(_do_bench, ref(settings),
|
||||||
|
vector<string>(names.begin() + i * 16, names.begin() + i * 16 + 16), ref(ioctx),
|
||||||
|
ref(listofops[i])));
|
||||||
|
|
||||||
if ((err = pthread_sigmask(SIG_SETMASK, &old_set, NULL)))
|
if ((err = pthread_sigmask(SIG_SETMASK, &old_set, NULL)))
|
||||||
{
|
{
|
||||||
|
@ -226,31 +220,28 @@ static void _main(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
// duration
|
// duration
|
||||||
++ai;
|
++ai;
|
||||||
if (ai >= argc || sscanf(argv[ai], "%i", &settings->secs) != 1 ||
|
if (ai >= argc || sscanf(argv[ai], "%i", &settings->secs) != 1 || settings->secs < 1)
|
||||||
settings->secs < 1)
|
|
||||||
throw "Wrong duration";
|
throw "Wrong duration";
|
||||||
}
|
}
|
||||||
else if (!strcmp(argv[ai], "-t"))
|
else if (!strcmp(argv[ai], "-t"))
|
||||||
{
|
{
|
||||||
// threads
|
// threads
|
||||||
++ai;
|
++ai;
|
||||||
if (ai >= argc || sscanf(argv[ai], "%i", &settings->threads) != 1 ||
|
if (ai >= argc || sscanf(argv[ai], "%i", &settings->threads) != 1 || settings->threads < 1)
|
||||||
settings->threads < 1)
|
|
||||||
throw "Wrong thread number";
|
throw "Wrong thread number";
|
||||||
}
|
}
|
||||||
else if (!strcmp(argv[ai], "-b"))
|
else if (!strcmp(argv[ai], "-b"))
|
||||||
{
|
{
|
||||||
// block size
|
// block size
|
||||||
++ai;
|
++ai;
|
||||||
if (ai >= argc || sscanf(argv[ai], "%i", (int*)&settings->block_size) != 1 ||
|
if (ai >= argc || sscanf(argv[ai], "%i", (int *)&settings->block_size) != 1 || settings->block_size < 1)
|
||||||
settings->block_size < 1)
|
|
||||||
throw "Wrong block size";
|
throw "Wrong block size";
|
||||||
}
|
}
|
||||||
else if (!strcmp(argv[ai], "-o"))
|
else if (!strcmp(argv[ai], "-o"))
|
||||||
{
|
{
|
||||||
// object size
|
// object size
|
||||||
++ai;
|
++ai;
|
||||||
if (ai >= argc || sscanf(argv[ai], "%i", (int*)&settings->object_size) != 1 ||
|
if (ai >= argc || sscanf(argv[ai], "%i", (int *)&settings->object_size) != 1 ||
|
||||||
settings->object_size < 1)
|
settings->object_size < 1)
|
||||||
throw "Wrong object size";
|
throw "Wrong object size";
|
||||||
}
|
}
|
||||||
|
@ -274,8 +265,7 @@ static void _main(int argc, const char *argv[])
|
||||||
|
|
||||||
if (settings->pool.empty() || settings->mode.empty())
|
if (settings->pool.empty() || settings->mode.empty())
|
||||||
{
|
{
|
||||||
cerr << "Usage: " << argv[0]
|
cerr << "Usage: " << argv[0] << " <poolname> <mode=host|osd> [specific item name to test]" << endl;
|
||||||
<< " <poolname> <mode=host|osd> [specific item name to test]" << endl;
|
|
||||||
throw "Wrong cmdline";
|
throw "Wrong cmdline";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,8 +319,7 @@ static void _main(int argc, const char *argv[])
|
||||||
if (location.find(settings->mode) != location.end())
|
if (location.find(settings->mode) != location.end())
|
||||||
{
|
{
|
||||||
const auto &osd_loc = location.at(settings->mode);
|
const auto &osd_loc = location.at(settings->mode);
|
||||||
if (settings->specific_bench_item.empty() ||
|
if (settings->specific_bench_item.empty() || osd_loc == settings->specific_bench_item)
|
||||||
osd_loc == settings->specific_bench_item)
|
|
||||||
{
|
{
|
||||||
bench_items.insert(osd_loc);
|
bench_items.insert(osd_loc);
|
||||||
}
|
}
|
||||||
|
@ -362,7 +351,7 @@ static void _main(int argc, const char *argv[])
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto &names = name2location[bench_item];
|
auto &names = name2location[bench_item];
|
||||||
if (names.size() >= (unsigned)settings->threads*16)
|
if (names.size() >= (unsigned)settings->threads * 16)
|
||||||
{
|
{
|
||||||
bench_items.erase(bench_item);
|
bench_items.erase(bench_item);
|
||||||
continue;
|
continue;
|
||||||
|
@ -391,8 +380,8 @@ static void _main(int argc, const char *argv[])
|
||||||
}
|
}
|
||||||
rados.watch_flush();
|
rados.watch_flush();
|
||||||
|
|
||||||
//rados_ioctx_destroy(io);
|
// rados_ioctx_destroy(io);
|
||||||
//rados_shutdown(cluster);
|
// rados_shutdown(cluster);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, const char *argv[])
|
int main(int argc, const char *argv[])
|
||||||
|
|
|
@ -1,16 +1,21 @@
|
||||||
#include <csignal>
|
|
||||||
|
|
||||||
#include "mysignals.h"
|
#include "mysignals.h"
|
||||||
|
|
||||||
|
#include <csignal>
|
||||||
static volatile std::sig_atomic_t gSignalStatus;
|
static volatile std::sig_atomic_t gSignalStatus;
|
||||||
|
|
||||||
static void signal_handler(int signal) { gSignalStatus = signal; }
|
static void signal_handler(int signal)
|
||||||
|
{
|
||||||
|
gSignalStatus = signal;
|
||||||
|
}
|
||||||
|
|
||||||
void setup_signal_handlers() {
|
void setup_signal_handlers()
|
||||||
|
{
|
||||||
std::signal(SIGINT, signal_handler);
|
std::signal(SIGINT, signal_handler);
|
||||||
std::signal(SIGTERM, signal_handler);
|
std::signal(SIGTERM, signal_handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
void abort_if_signalled() {
|
void abort_if_signalled()
|
||||||
|
{
|
||||||
if (gSignalStatus)
|
if (gSignalStatus)
|
||||||
throw AbortException();
|
throw AbortException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,9 @@
|
||||||
|
|
||||||
void setup_signal_handlers();
|
void setup_signal_handlers();
|
||||||
|
|
||||||
class AbortException : public std::exception {};
|
class AbortException : public std::exception
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
void abort_if_signalled();
|
void abort_if_signalled();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#include <string>
|
#include "radosutil.h"
|
||||||
|
|
||||||
#include <json/json.h>
|
#include <json/json.h>
|
||||||
#include <librados.hpp>
|
|
||||||
|
|
||||||
#include "radosutil.h"
|
#include <librados.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace librados;
|
using namespace librados;
|
||||||
|
@ -12,13 +12,13 @@ RadosUtils::RadosUtils(Rados *rados_)
|
||||||
: rados(rados_), /* */
|
: rados(rados_), /* */
|
||||||
json_reader(new Json::Reader(Json::Features::strictMode())), /* */
|
json_reader(new Json::Reader(Json::Features::strictMode())), /* */
|
||||||
json_writer(new Json::FastWriter()) /* */
|
json_writer(new Json::FastWriter()) /* */
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
// RadosUtils::~RadosUtils() {}
|
// RadosUtils::~RadosUtils() {}
|
||||||
|
|
||||||
unsigned int RadosUtils::get_obj_acting_primary(const string &name,
|
unsigned int RadosUtils::get_obj_acting_primary(const string &name, const string &pool)
|
||||||
const string &pool) {
|
{
|
||||||
|
|
||||||
Json::Value cmd(Json::objectValue);
|
Json::Value cmd(Json::objectValue);
|
||||||
cmd["prefix"] = "osd map";
|
cmd["prefix"] = "osd map";
|
||||||
cmd["object"] = name;
|
cmd["object"] = name;
|
||||||
|
@ -33,7 +33,8 @@ unsigned int RadosUtils::get_obj_acting_primary(const string &name,
|
||||||
return acting_primary.asUInt();
|
return acting_primary.asUInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
map<string, string> RadosUtils::get_osd_location(unsigned int osd) {
|
map<string, string> RadosUtils::get_osd_location(unsigned int osd)
|
||||||
|
{
|
||||||
Json::Value cmd(Json::objectValue);
|
Json::Value cmd(Json::objectValue);
|
||||||
cmd["prefix"] = "osd find";
|
cmd["prefix"] = "osd find";
|
||||||
cmd["id"] = osd;
|
cmd["id"] = osd;
|
||||||
|
@ -43,7 +44,8 @@ map<string, string> RadosUtils::get_osd_location(unsigned int osd) {
|
||||||
|
|
||||||
map<string, string> result;
|
map<string, string> result;
|
||||||
|
|
||||||
for (auto &&it = crush.begin(); it != crush.end(); ++it) {
|
for (auto &&it = crush.begin(); it != crush.end(); ++it)
|
||||||
|
{
|
||||||
result[it.name()] = it->asString();
|
result[it.name()] = it->asString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +54,8 @@ map<string, string> RadosUtils::get_osd_location(unsigned int osd) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
set<unsigned int> RadosUtils::get_osds(const string &pool) {
|
set<unsigned int> RadosUtils::get_osds(const string &pool)
|
||||||
|
{
|
||||||
Json::Value cmd(Json::objectValue);
|
Json::Value cmd(Json::objectValue);
|
||||||
cmd["prefix"] = "pg ls-by-pool";
|
cmd["prefix"] = "pg ls-by-pool";
|
||||||
cmd["poolstr"] = pool;
|
cmd["poolstr"] = pool;
|
||||||
|
@ -61,10 +64,12 @@ set<unsigned int> RadosUtils::get_osds(const string &pool) {
|
||||||
|
|
||||||
set<unsigned int> osds;
|
set<unsigned int> osds;
|
||||||
|
|
||||||
if (pgs.isMember("pg_stats")) {
|
if (pgs.isMember("pg_stats"))
|
||||||
|
{
|
||||||
pgs = pgs["pg_stats"];
|
pgs = pgs["pg_stats"];
|
||||||
}
|
}
|
||||||
for (const auto &pg : pgs) {
|
for (const auto &pg : pgs)
|
||||||
|
{
|
||||||
const auto &primary = pg["acting_primary"];
|
const auto &primary = pg["acting_primary"];
|
||||||
if (!primary.isNumeric())
|
if (!primary.isNumeric())
|
||||||
throw "Failed to get acting_primary";
|
throw "Failed to get acting_primary";
|
||||||
|
@ -74,7 +79,8 @@ set<unsigned int> RadosUtils::get_osds(const string &pool) {
|
||||||
return osds;
|
return osds;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int RadosUtils::get_pool_size(const string &pool) {
|
unsigned int RadosUtils::get_pool_size(const string &pool)
|
||||||
|
{
|
||||||
Json::Value cmd(Json::objectValue);
|
Json::Value cmd(Json::objectValue);
|
||||||
cmd["prefix"] = "osd pool get";
|
cmd["prefix"] = "osd pool get";
|
||||||
cmd["pool"] = pool;
|
cmd["pool"] = pool;
|
||||||
|
@ -85,15 +91,15 @@ unsigned int RadosUtils::get_pool_size(const string &pool) {
|
||||||
return v["size"].asUInt();
|
return v["size"].asUInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
Json::Value RadosUtils::do_mon_command(Json::Value &cmd) {
|
Json::Value RadosUtils::do_mon_command(Json::Value &cmd)
|
||||||
|
{
|
||||||
int err;
|
int err;
|
||||||
bufferlist outbl;
|
bufferlist outbl;
|
||||||
string outs;
|
string outs;
|
||||||
cmd["format"] = "json";
|
cmd["format"] = "json";
|
||||||
bufferlist inbl;
|
bufferlist inbl;
|
||||||
|
|
||||||
if ((err = rados->mon_command(json_writer->write(cmd), inbl, &outbl, &outs)) <
|
if ((err = rados->mon_command(json_writer->write(cmd), inbl, &outbl, &outs)) < 0)
|
||||||
0)
|
|
||||||
throw MyRadosException(err, outs);
|
throw MyRadosException(err, outs);
|
||||||
|
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
|
|
32
radosutil.h
32
radosutil.h
|
@ -1,39 +1,45 @@
|
||||||
|
#include <json/json.h>
|
||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <json/json.h>
|
|
||||||
#include "librados_fwd.hpp"
|
#include "librados_fwd.hpp"
|
||||||
|
|
||||||
namespace Json {
|
namespace Json
|
||||||
|
{
|
||||||
class Reader;
|
class Reader;
|
||||||
class FastWriter;
|
class FastWriter;
|
||||||
class Value;
|
class Value;
|
||||||
} // namespace Json
|
} // namespace Json
|
||||||
|
|
||||||
class RadosUtils {
|
class RadosUtils
|
||||||
public:
|
{
|
||||||
|
public:
|
||||||
explicit RadosUtils(librados::Rados *rados_);
|
explicit RadosUtils(librados::Rados *rados_);
|
||||||
unsigned int get_obj_acting_primary(const std::string &name,
|
unsigned int get_obj_acting_primary(const std::string &name, const std::string &pool);
|
||||||
const std::string &pool);
|
|
||||||
std::map<std::string, std::string> get_osd_location(unsigned int osd);
|
std::map<std::string, std::string> get_osd_location(unsigned int osd);
|
||||||
std::set<unsigned int> get_osds(const std::string &pool);
|
std::set<unsigned int> get_osds(const std::string &pool);
|
||||||
unsigned int get_pool_size(const std::string &pool);
|
unsigned int get_pool_size(const std::string &pool);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Json::Value do_mon_command(Json::Value &cmd);
|
Json::Value do_mon_command(Json::Value &cmd);
|
||||||
librados::Rados *rados;
|
librados::Rados *rados;
|
||||||
std::unique_ptr<Json::Reader> json_reader;
|
std::unique_ptr<Json::Reader> json_reader;
|
||||||
std::unique_ptr<Json::FastWriter> json_writer;
|
std::unique_ptr<Json::FastWriter> json_writer;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MyRadosException : public std::exception {
|
class MyRadosException : public std::exception
|
||||||
public:
|
{
|
||||||
MyRadosException(int err, const std::string &msg)
|
public:
|
||||||
: descr("Rados err " + std::to_string(err) + ": " + msg){};
|
MyRadosException(int err, const std::string &msg) : descr("Rados err " + std::to_string(err) + ": " + msg){};
|
||||||
const char *what() const throw() { return descr.c_str(); }
|
const char *what() const throw()
|
||||||
|
{
|
||||||
|
return descr.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string descr;
|
std::string descr;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue