Skip to content

Commit 7473712

Browse files
Fixed Zipfian support for arbitrary commands.
1 parent b2041a4 commit 7473712

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

config_types.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ bool arbitrary_command::set_key_pattern(const char* pattern_str) {
326326

327327
if (pattern_str[0] != 'R' &&
328328
pattern_str[0] != 'G' &&
329+
pattern_str[0] != 'Z' &&
329330
pattern_str[0] != 'S' &&
330331
pattern_str[0] != 'P') {
331332

memtier_benchmark.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ static int config_parse_args(int argc, char *argv[], struct benchmark_config *cf
997997
// command configuration always applied on last configured command
998998
arbitrary_command& cmd = cfg->arbitrary_commands->get_last_command();
999999
if (!cmd.set_key_pattern(optarg)) {
1000-
fprintf(stderr, "error: key-pattern for command %s must be in the format of [S/R/G/P].\n", cmd.command_name.c_str());
1000+
fprintf(stderr, "error: key-pattern for command %s must be in the format of [S/R/Z/G/P].\n", cmd.command_name.c_str());
10011001
return -1;
10021002
}
10031003
break;
@@ -1160,6 +1160,7 @@ void usage() {
11601160
" --command-key-pattern Key pattern for the command (default: R):\n"
11611161
" G for Gaussian distribution.\n"
11621162
" R for uniform Random.\n"
1163+
" Z for zipf distribution (will limit keys to positive).\n"
11631164
" S for Sequential.\n"
11641165
" P for Parallel (Sequential were each client has a subset of the key-range).\n"
11651166
"\n"
@@ -1779,7 +1780,20 @@ int main(int argc, char *argv[])
17791780
obj_gen->set_key_range(cfg.key_minimum, cfg.key_maximum);
17801781
}
17811782
if (cfg.key_stddev>0 || cfg.key_median>0) {
1782-
if (cfg.key_pattern[key_pattern_set]!='G' && cfg.key_pattern[key_pattern_get]!='G') {
1783+
// Check if Gaussian distribution is used in global key patterns or arbitrary commands
1784+
bool has_gaussian = (cfg.key_pattern[key_pattern_set]=='G' || cfg.key_pattern[key_pattern_get]=='G');
1785+
1786+
// Also check if any arbitrary command uses Gaussian distribution
1787+
if (!has_gaussian && cfg.arbitrary_commands->is_defined()) {
1788+
for (size_t i = 0; i < cfg.arbitrary_commands->size(); i++) {
1789+
if (cfg.arbitrary_commands->at(i).key_pattern == 'G') {
1790+
has_gaussian = true;
1791+
break;
1792+
}
1793+
}
1794+
}
1795+
1796+
if (!has_gaussian) {
17831797
fprintf(stderr, "error: key-stddev and key-median are only allowed together with key-pattern set to G.\n");
17841798
usage();
17851799
}
@@ -1790,7 +1804,21 @@ int main(int argc, char *argv[])
17901804
obj_gen->set_key_distribution(cfg.key_stddev, cfg.key_median);
17911805
}
17921806
obj_gen->set_expiry_range(cfg.expiry_range.min, cfg.expiry_range.max);
1793-
if (cfg.key_pattern[key_pattern_set] == 'Z' || cfg.key_pattern[key_pattern_get] == 'Z') {
1807+
1808+
// Check if Zipfian distribution is needed for global key patterns or arbitrary commands
1809+
bool needs_zipfian = (cfg.key_pattern[key_pattern_set] == 'Z' || cfg.key_pattern[key_pattern_get] == 'Z');
1810+
1811+
// Also check if any arbitrary command uses Zipfian distribution
1812+
if (!needs_zipfian && cfg.arbitrary_commands->is_defined()) {
1813+
for (size_t i = 0; i < cfg.arbitrary_commands->size(); i++) {
1814+
if (cfg.arbitrary_commands->at(i).key_pattern == 'Z') {
1815+
needs_zipfian = true;
1816+
break;
1817+
}
1818+
}
1819+
}
1820+
1821+
if (needs_zipfian) {
17941822
if (cfg.key_zipf_exp == 0.0) {
17951823
// user can't specify 0.0, so 0.0 means unset
17961824
cfg.key_zipf_exp = 1.0;

0 commit comments

Comments
 (0)