From 65bbece7d0ee8bed9d12e6f9a5cfc11cd1b6690c Mon Sep 17 00:00:00 2001 From: augurier <14434658+augurier@user.noreply.gitee.com> Date: Sat, 28 Dec 2024 17:38:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9benchmark=E9=83=A8=E5=88=86=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benchmarks/db_bench_FieldDB.cc | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/benchmarks/db_bench_FieldDB.cc b/benchmarks/db_bench_FieldDB.cc index a0f9a21..3abf7c5 100644 --- a/benchmarks/db_bench_FieldDB.cc +++ b/benchmarks/db_bench_FieldDB.cc @@ -664,7 +664,7 @@ class Benchmark { } else { delete db_; db_ = nullptr; - DestroyDB(FLAGS_db, Options()); + //DestroyDB(FLAGS_db, Options()); Open(); } } @@ -821,6 +821,7 @@ class Benchmark { options.compression = FLAGS_compression ? kSnappyCompression : kNoCompression; // Status s = DB::Open(options, FLAGS_db, &db_); + fielddb::DestroyDB(FLAGS_db, options); db_ = new FieldDB(); Status s = FieldDB::OpenFieldDB(options, FLAGS_db, &db_); if (!s.ok()) { @@ -858,8 +859,20 @@ class Benchmark { for (int j = 0; j < entries_per_batch_; j++) { const int k = seq ? i + j : thread->rand.Uniform(FLAGS_num); key.Set(k); - batch.Put(key.slice(), gen.Generate(value_size_)); - bytes += value_size_ + key.slice().size(); + + std::string name = "customer#" + std::to_string(k); + //这个字段用来查找 + std::string age = std::to_string(thread->rand.Uniform(FLAGS_num) % 100); + //这个字段填充长度 + std::string tag = gen.Generate(value_size_).ToString(); + FieldArray fields = { + {"name", name}, + {"age", age}, + {"tag", tag} + }; + Slice value = SerializeValue(fields); + batch.Put(key.slice(), value); + bytes += value.size() + key.slice().size(); thread->stats.FinishedSingleOp(); } s = db_->Write(write_options_, &batch); @@ -899,13 +912,13 @@ class Benchmark { void ReadRandom(ThreadState* thread) { ReadOptions options; - std::string value; int found = 0; KeyBuffer key; for (int i = 0; i < reads_; i++) { const int k = thread->rand.Uniform(FLAGS_num); key.Set(k); - if (db_->Get(options, key.slice(), &value).ok()) { + FieldArray fields_ret; + if (db_->GetFields(options, key.slice(), &fields_ret).ok()) { found++; } thread->stats.FinishedSingleOp(); @@ -917,26 +930,26 @@ class Benchmark { void ReadMissing(ThreadState* thread) { ReadOptions options; - std::string value; + FieldArray fields_ret; KeyBuffer key; for (int i = 0; i < reads_; i++) { const int k = thread->rand.Uniform(FLAGS_num); key.Set(k); Slice s = Slice(key.slice().data(), key.slice().size() - 1); - db_->Get(options, s, &value); + db_->GetFields(options, s, &fields_ret); thread->stats.FinishedSingleOp(); } } void ReadHot(ThreadState* thread) { ReadOptions options; - std::string value; + FieldArray fields_ret; const int range = (FLAGS_num + 99) / 100; KeyBuffer key; for (int i = 0; i < reads_; i++) { const int k = thread->rand.Uniform(range); key.Set(k); - db_->Get(options, key.slice(), &value); + db_->GetFields(options, key.slice(), &fields_ret); thread->stats.FinishedSingleOp(); } }