chore: add benchmarking of ScanOpts::Matches (#4511)

Also, improve robustness of StickyEviction that was failing for me.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
Roman Gershman 2025-01-27 18:14:55 +02:00 committed by GitHub
parent fbd785cbc7
commit 2d85f59a74
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -498,9 +498,11 @@ TEST_F(DflyEngineTest, StickyEviction) {
string tmp_val(100, '.'); string tmp_val(100, '.');
ssize_t failed = -1; ssize_t failed = -1;
for (ssize_t i = 0; i < 5000; ++i) {
for (ssize_t i = 0; i < 4500; ++i) {
string key = StrCat("volatile", i); string key = StrCat("volatile", i);
ASSERT_EQ("OK", Run({"set", key, tmp_val})); ASSERT_EQ("OK", Run({"set", key, tmp_val}));
usleep(1);
} }
bool done = false; bool done = false;
@ -829,6 +831,8 @@ TEST_F(DflyEngineTest, ReplicaofRejectOnLoad) {
ASSERT_THAT(res, ErrArg("LOADING Dragonfly is loading the dataset in memory")); ASSERT_THAT(res, ErrArg("LOADING Dragonfly is loading the dataset in memory"));
} }
using benchmark::DoNotOptimize;
// TODO: to test transactions with a single shard since then all transactions become local. // TODO: to test transactions with a single shard since then all transactions become local.
// To consider having a parameter in dragonfly engine controlling number of shards // To consider having a parameter in dragonfly engine controlling number of shards
// unconditionally from number of cpus. TO TEST BLPOP under multi for single/multi argument case. // unconditionally from number of cpus. TO TEST BLPOP under multi for single/multi argument case.
@ -866,4 +870,26 @@ static void BM_ParseDoubleAbsl(benchmark::State& state) {
} }
BENCHMARK(BM_ParseDoubleAbsl); BENCHMARK(BM_ParseDoubleAbsl);
static void BM_MatchPattern(benchmark::State& state) {
absl::InsecureBitGen eng;
string random_val = GetRandomHex(eng, state.range(0));
ScanOpts scan_opts;
scan_opts.pattern = "*foobar*";
while (state.KeepRunning()) {
DoNotOptimize(scan_opts.Matches(random_val));
}
}
BENCHMARK(BM_MatchPattern)->Arg(1000)->Arg(10000);
static void BM_MatchFindSubstr(benchmark::State& state) {
absl::InsecureBitGen eng;
string random_val = GetRandomHex(eng, state.range(0));
while (state.KeepRunning()) {
DoNotOptimize(random_val.find("foobar"));
}
}
BENCHMARK(BM_MatchFindSubstr)->Arg(1000)->Arg(10000);
} // namespace dfly } // namespace dfly