Ver código fonte

对benchmark部分修改

pull/2/head
augurier 8 meses atrás
pai
commit
65bbece7d0
1 arquivos alterados com 22 adições e 9 exclusões
  1. +22
    -9
      benchmarks/db_bench_FieldDB.cc

+ 22
- 9
benchmarks/db_bench_FieldDB.cc Ver arquivo

@ -664,7 +664,7 @@ class Benchmark {
} else { } else {
delete db_; delete db_;
db_ = nullptr; db_ = nullptr;
DestroyDB(FLAGS_db, Options());
//DestroyDB(FLAGS_db, Options());
Open(); Open();
} }
} }
@ -821,6 +821,7 @@ class Benchmark {
options.compression = options.compression =
FLAGS_compression ? kSnappyCompression : kNoCompression; FLAGS_compression ? kSnappyCompression : kNoCompression;
// Status s = DB::Open(options, FLAGS_db, &db_); // Status s = DB::Open(options, FLAGS_db, &db_);
fielddb::DestroyDB(FLAGS_db, options);
db_ = new FieldDB(); db_ = new FieldDB();
Status s = FieldDB::OpenFieldDB(options, FLAGS_db, &db_); Status s = FieldDB::OpenFieldDB(options, FLAGS_db, &db_);
if (!s.ok()) { if (!s.ok()) {
@ -858,8 +859,20 @@ class Benchmark {
for (int j = 0; j < entries_per_batch_; j++) { for (int j = 0; j < entries_per_batch_; j++) {
const int k = seq ? i + j : thread->rand.Uniform(FLAGS_num); const int k = seq ? i + j : thread->rand.Uniform(FLAGS_num);
key.Set(k); 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(); thread->stats.FinishedSingleOp();
} }
s = db_->Write(write_options_, &batch); s = db_->Write(write_options_, &batch);
@ -899,13 +912,13 @@ class Benchmark {
void ReadRandom(ThreadState* thread) { void ReadRandom(ThreadState* thread) {
ReadOptions options; ReadOptions options;
std::string value;
int found = 0; int found = 0;
KeyBuffer key; KeyBuffer key;
for (int i = 0; i < reads_; i++) { for (int i = 0; i < reads_; i++) {
const int k = thread->rand.Uniform(FLAGS_num); const int k = thread->rand.Uniform(FLAGS_num);
key.Set(k); key.Set(k);
if (db_->Get(options, key.slice(), &value).ok()) {
FieldArray fields_ret;
if (db_->GetFields(options, key.slice(), &fields_ret).ok()) {
found++; found++;
} }
thread->stats.FinishedSingleOp(); thread->stats.FinishedSingleOp();
@ -917,26 +930,26 @@ class Benchmark {
void ReadMissing(ThreadState* thread) { void ReadMissing(ThreadState* thread) {
ReadOptions options; ReadOptions options;
std::string value;
FieldArray fields_ret;
KeyBuffer key; KeyBuffer key;
for (int i = 0; i < reads_; i++) { for (int i = 0; i < reads_; i++) {
const int k = thread->rand.Uniform(FLAGS_num); const int k = thread->rand.Uniform(FLAGS_num);
key.Set(k); key.Set(k);
Slice s = Slice(key.slice().data(), key.slice().size() - 1); Slice s = Slice(key.slice().data(), key.slice().size() - 1);
db_->Get(options, s, &value);
db_->GetFields(options, s, &fields_ret);
thread->stats.FinishedSingleOp(); thread->stats.FinishedSingleOp();
} }
} }
void ReadHot(ThreadState* thread) { void ReadHot(ThreadState* thread) {
ReadOptions options; ReadOptions options;
std::string value;
FieldArray fields_ret;
const int range = (FLAGS_num + 99) / 100; const int range = (FLAGS_num + 99) / 100;
KeyBuffer key; KeyBuffer key;
for (int i = 0; i < reads_; i++) { for (int i = 0; i < reads_; i++) {
const int k = thread->rand.Uniform(range); const int k = thread->rand.Uniform(range);
key.Set(k); key.Set(k);
db_->Get(options, key.slice(), &value);
db_->GetFields(options, key.slice(), &fields_ret);
thread->stats.FinishedSingleOp(); thread->stats.FinishedSingleOp();
} }
} }

Carregando…
Cancelar
Salvar