From 2d85f59a74f1b1410e2fae295a102c26e18b58ec Mon Sep 17 00:00:00 2001 From: Roman Gershman Date: Mon, 27 Jan 2025 18:14:55 +0200 Subject: [PATCH] chore: add benchmarking of ScanOpts::Matches (#4511) Also, improve robustness of StickyEviction that was failing for me. Signed-off-by: Roman Gershman --- src/server/dragonfly_test.cc | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/server/dragonfly_test.cc b/src/server/dragonfly_test.cc index 14f3e2da1..4efaf4301 100644 --- a/src/server/dragonfly_test.cc +++ b/src/server/dragonfly_test.cc @@ -498,9 +498,11 @@ TEST_F(DflyEngineTest, StickyEviction) { string tmp_val(100, '.'); 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); ASSERT_EQ("OK", Run({"set", key, tmp_val})); + usleep(1); } bool done = false; @@ -829,6 +831,8 @@ TEST_F(DflyEngineTest, ReplicaofRejectOnLoad) { 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. // 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. @@ -866,4 +870,26 @@ static void BM_ParseDoubleAbsl(benchmark::State& state) { } 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