introduce concept of active versus total tenants in mako

This commit is contained in:
Jon Fu 2022-06-15 15:30:02 -07:00
parent 0fea3fb731
commit 2b9c8ca874
2 changed files with 32 additions and 19 deletions

View File

@ -66,7 +66,8 @@ namespace mako {
struct alignas(64) ThreadArgs { struct alignas(64) ThreadArgs {
int worker_id; int worker_id;
int thread_id; int thread_id;
int tenants; int active_tenants;
int total_tenants;
pid_t parent_id; pid_t parent_id;
Arguments const* args; Arguments const* args;
shared_memory::Access shm; shared_memory::Access shm;
@ -82,11 +83,11 @@ thread_local Logger logr = Logger(MainProcess{}, VERBOSE_DEFAULT);
Transaction createNewTransaction(Database db, Arguments const& args, int id = -1, Tenant* tenants = nullptr) { Transaction createNewTransaction(Database db, Arguments const& args, int id = -1, Tenant* tenants = nullptr) {
// No tenants specified // No tenants specified
if (args.tenants <= 0) { if (args.active_tenants <= 0) {
return db.createTransaction(); return db.createTransaction();
} }
// Create Tenant Transaction // Create Tenant Transaction
int tenant_id = (id == -1) ? urand(0, args.tenants - 1) : id; int tenant_id = (id == -1) ? urand(0, args.active_tenants - 1) : id;
// If provided tenants array (only necessary in runWorkload), use it // If provided tenants array (only necessary in runWorkload), use it
if (tenants) { if (tenants) {
return tenants[tenant_id].createTransaction(); return tenants[tenant_id].createTransaction();
@ -117,9 +118,9 @@ int cleanup(Database db, Arguments const& args) {
auto watch = Stopwatch(StartAtCtor{}); auto watch = Stopwatch(StartAtCtor{});
int num_iterations = (args.tenants > 1) ? args.tenants : 1; int num_iterations = (args.total_tenants > 1) ? args.total_tenants : 1;
for (int i = 0; i < num_iterations; ++i) { for (int i = 0; i < num_iterations; ++i) {
// If args.tenants is zero, this will use a non-tenant txn and perform a single range clear. // If args.total_tenants is zero, this will use a non-tenant txn and perform a single range clear.
// If 1, it will use a tenant txn and do a single range clear instead. // If 1, it will use a tenant txn and do a single range clear instead.
// If > 1, it will perform a range clear with a different tenant txn per iteration. // If > 1, it will perform a range clear with a different tenant txn per iteration.
Transaction tx = createNewTransaction(db, args, i); Transaction tx = createNewTransaction(db, args, i);
@ -138,7 +139,7 @@ int cleanup(Database db, Arguments const& args) {
} }
// If tenants are specified, also delete the tenant after clearing out its keyspace // If tenants are specified, also delete the tenant after clearing out its keyspace
if (args.tenants > 0) { if (args.total_tenants > 0) {
Transaction systemTx = db.createTransaction(); Transaction systemTx = db.createTransaction();
while (true) { while (true) {
Tenant::deleteTenant(systemTx, toBytesRef("tenant" + std::to_string(i))); Tenant::deleteTenant(systemTx, toBytesRef("tenant" + std::to_string(i)));
@ -184,11 +185,11 @@ int populate(Database db,
auto key_checkpoint = key_begin; // in case of commit failure, restart from this key auto key_checkpoint = key_begin; // in case of commit failure, restart from this key
Transaction systemTx = db.createTransaction(); Transaction systemTx = db.createTransaction();
for (int i = 0; i < args.tenants; ++i) { for (int i = 0; i < args.total_tenants; ++i) {
while (true) { while (true) {
// Until this issue https://github.com/apple/foundationdb/issues/7260 is resolved // Until this issue https://github.com/apple/foundationdb/issues/7260 is resolved
// we have to commit each tenant creation transaction one-by-one // we have to commit each tenant creation transaction one-by-one
// while (i % 10 == 9 || i == args.tenants - 1) { // while (i % 10 == 9 || i == args.total_tenants - 1) {
std::string tenant_name = "tenant" + std::to_string(i); std::string tenant_name = "tenant" + std::to_string(i);
Tenant::createTenant(systemTx, toBytesRef(tenant_name)); Tenant::createTenant(systemTx, toBytesRef(tenant_name));
auto future_commit = systemTx.commit(); auto future_commit = systemTx.commit();
@ -428,8 +429,8 @@ int runWorkload(Database db,
// mimic typical tenant usage: keep tenants in memory // mimic typical tenant usage: keep tenants in memory
// and create transactions as needed // and create transactions as needed
Tenant tenants[args.tenants]; Tenant tenants[args.active_tenants];
for (int i = 0; i < args.tenants; ++i) { for (int i = 0; i < args.active_tenants; ++i) {
std::string tenantStr = "tenant" + std::to_string(i); std::string tenantStr = "tenant" + std::to_string(i);
BytesRef tenant_name = toBytesRef(tenantStr); BytesRef tenant_name = toBytesRef(tenantStr);
tenants[i] = db.openTenant(tenant_name); tenants[i] = db.openTenant(tenant_name);
@ -437,7 +438,7 @@ int runWorkload(Database db,
/* main transaction loop */ /* main transaction loop */
while (1) { while (1) {
Transaction tx = createNewTransaction(db, args, -1, args.tenants > 0 ? tenants : nullptr); Transaction tx = createNewTransaction(db, args, -1, args.active_tenants > 0 ? tenants : nullptr);
while ((thread_tps > 0) && (xacts >= current_tps)) { while ((thread_tps > 0) && (xacts >= current_tps)) {
/* throttle on */ /* throttle on */
const auto time_now = steady_clock::now(); const auto time_now = steady_clock::now();
@ -797,7 +798,8 @@ int workerProcessMain(Arguments const& args, int worker_id, shared_memory::Acces
this_args.worker_id = worker_id; this_args.worker_id = worker_id;
this_args.thread_id = i; this_args.thread_id = i;
this_args.parent_id = pid_main; this_args.parent_id = pid_main;
this_args.tenants = args.tenants; this_args.active_tenants = args.active_tenants;
this_args.total_tenants = args.total_tenants;
this_args.args = &args; this_args.args = &args;
this_args.shm = shm; this_args.shm = shm;
this_args.database = databases[i % args.num_databases]; this_args.database = databases[i % args.num_databases];
@ -866,7 +868,8 @@ int initArguments(Arguments& args) {
args.sampling = 1000; args.sampling = 1000;
args.key_length = 32; args.key_length = 32;
args.value_length = 16; args.value_length = 16;
args.tenants = 0; args.active_tenants = 0;
args.total_tenants = 0;
args.zipf = 0; args.zipf = 0;
args.commit_get = 0; args.commit_get = 0;
args.verbose = 1; args.verbose = 1;
@ -1097,7 +1100,8 @@ int parseArguments(int argc, char* argv[], Arguments& args) {
{ "iteration", required_argument, NULL, 'i' }, { "iteration", required_argument, NULL, 'i' },
{ "keylen", required_argument, NULL, ARG_KEYLEN }, { "keylen", required_argument, NULL, ARG_KEYLEN },
{ "vallen", required_argument, NULL, ARG_VALLEN }, { "vallen", required_argument, NULL, ARG_VALLEN },
{ "tenants", required_argument, NULL, ARG_TENANTS }, { "active_tenants", required_argument, NULL, ARG_ACTIVE_TENANTS },
{ "total_tenants", required_argument, NULL, ARG_TOTAL_TENANTS },
{ "transaction", required_argument, NULL, 'x' }, { "transaction", required_argument, NULL, 'x' },
{ "tps", required_argument, NULL, ARG_TPS }, { "tps", required_argument, NULL, ARG_TPS },
{ "tpsmax", required_argument, NULL, ARG_TPSMAX }, { "tpsmax", required_argument, NULL, ARG_TPSMAX },
@ -1214,8 +1218,11 @@ int parseArguments(int argc, char* argv[], Arguments& args) {
case ARG_VALLEN: case ARG_VALLEN:
args.value_length = atoi(optarg); args.value_length = atoi(optarg);
break; break;
case ARG_TENANTS: case ARG_ACTIVE_TENANTS:
args.tenants = atoi(optarg); args.active_tenants = atoi(optarg);
break;
case ARG_TOTAL_TENANTS:
args.total_tenants = atoi(optarg);
break; break;
case ARG_TPS: case ARG_TPS:
case ARG_TPSMAX: case ARG_TPSMAX:
@ -1406,6 +1413,10 @@ int validateArguments(Arguments const& args) {
4 + args.row_digits); 4 + args.row_digits);
return -1; return -1;
} }
if (args.active_tenants > args.total_tenants) {
logr.error("--active_tenants must be less than or equal to --total_tenants");
return -1;
}
if (args.mode == MODE_RUN) { if (args.mode == MODE_RUN) {
if ((args.seconds > 0) && (args.iteration > 0)) { if ((args.seconds > 0) && (args.iteration > 0)) {
logr.error("Cannot specify seconds and iteration together"); logr.error("Cannot specify seconds and iteration together");
@ -1972,7 +1983,7 @@ int statsProcessMain(Arguments const& args,
fmt::fprintf(fp, "\"sampling\": %d,", args.sampling); fmt::fprintf(fp, "\"sampling\": %d,", args.sampling);
fmt::fprintf(fp, "\"key_length\": %d,", args.key_length); fmt::fprintf(fp, "\"key_length\": %d,", args.key_length);
fmt::fprintf(fp, "\"value_length\": %d,", args.value_length); fmt::fprintf(fp, "\"value_length\": %d,", args.value_length);
fmt::fprintf(fp, "\"tenants\": %d,", args.tenants); fmt::fprintf(fp, "\"tenants\": %d,", args.active_tenants);
fmt::fprintf(fp, "\"commit_get\": %d,", args.commit_get); fmt::fprintf(fp, "\"commit_get\": %d,", args.commit_get);
fmt::fprintf(fp, "\"verbose\": %d,", args.verbose); fmt::fprintf(fp, "\"verbose\": %d,", args.verbose);
fmt::fprintf(fp, "\"cluster_files\": \"%s\",", args.cluster_files[0]); fmt::fprintf(fp, "\"cluster_files\": \"%s\",", args.cluster_files[0]);

View File

@ -50,7 +50,8 @@ constexpr const int MODE_REPORT = 3;
enum ArgKind { enum ArgKind {
ARG_KEYLEN, ARG_KEYLEN,
ARG_VALLEN, ARG_VALLEN,
ARG_TENANTS, ARG_ACTIVE_TENANTS,
ARG_TOTAL_TENANTS,
ARG_TPS, ARG_TPS,
ARG_ASYNC, ARG_ASYNC,
ARG_COMMITGET, ARG_COMMITGET,
@ -145,7 +146,8 @@ struct Arguments {
int sampling; int sampling;
int key_length; int key_length;
int value_length; int value_length;
int tenants; int active_tenants;
int total_tenants;
int zipf; int zipf;
int commit_get; int commit_get;
int verbose; int verbose;