Compare commits

..

No commits in common. "9f6434dba12b3e180e0f2641a54dca9d8bd46f56" and "07baaae51edc94d7fcf294ea020e3e9d66947aba" have entirely different histories.

12 changed files with 27 additions and 78 deletions

1
.gitignore vendored
View File

@ -5,6 +5,7 @@
/scripts/lib64
/scripts/share/
/scripts/.gitignore
*.png
*.csv
pyvenv.cfg
Cargo.lock

View File

@ -1,22 +0,0 @@
# mace 0.0.17
## insert performance
![mace_insert](./scripts/mace_insert.png)
![rocksdb_insert](./scripts/rocksdb_insert.png)
---
## get performance (cold get)
![mace_get](./scripts/mace_get.png)
![rocksdb_get](./scripts/rocksdb_get.png)
---
# mixed perfomance
![mace_mixed](./scripts/mace_mixed.png)
![rockdb_mixed](./scripts/rocksdb_mixed.png)

View File

@ -1,14 +1,10 @@
#include <algorithm>
#include <atomic>
#include <cstdint>
#include <fmt/format.h>
#include <memory>
#include <random>
#include <rocksdb/cache.h>
#include <rocksdb/db.h>
#include <rocksdb/env.h>
#include <rocksdb/options.h>
#include <rocksdb/table.h>
#include <rocksdb/utilities/optimistic_transaction_db.h>
#include <rocksdb/utilities/transaction.h>
#include <rocksdb/utilities/transaction_db.h>
@ -80,31 +76,17 @@ int main(int argc, char *argv[]) {
return 1;
}
rocksdb::ColumnFamilyOptions cfo{};
cfo.enable_blob_files = true;
cfo.min_blob_size = 8192;
// use 1GB block cache
auto cache = rocksdb::NewLRUCache(1 << 30);
rocksdb::BlockBasedTableOptions table_options{};
table_options.block_cache = cache;
cfo.table_factory.reset(NewBlockBasedTableFactory(table_options));
// the following three options makes it not trigger GC in test
cfo.level0_file_num_compaction_trigger = 10000;
cfo.write_buffer_size = 64 << 20;
cfo.max_write_buffer_number = 16;
std::vector<rocksdb::ColumnFamilyDescriptor> cfd{};
cfd.push_back(rocksdb::ColumnFamilyDescriptor("default", cfo));
rocksdb::DBOptions options;
rocksdb::Options options;
options.create_if_missing = true;
options.allow_concurrent_memtable_write = true;
options.enable_pipelined_write = true;
options.env->SetBackgroundThreads(4, rocksdb::Env::Priority::HIGH);
// the following three options makes it not trigger GC in test
options.level0_file_num_compaction_trigger = 1000;
options.write_buffer_size = 1 << 30;
options.max_write_buffer_number = 5;
auto ropt = rocksdb::ReadOptions();
auto wopt = rocksdb::WriteOptions();
wopt.no_slowdown = true;
// wopt.disableWAL = true;
std::vector<std::thread> wg;
std::vector<std::vector<std::string>> keys{};
@ -112,8 +94,7 @@ int main(int argc, char *argv[]) {
rocksdb::OptimisticTransactionDB *db;
auto b = nm::Instant::now();
std::mutex mtx{};
std::vector<rocksdb::ColumnFamilyHandle *> handles{};
auto s = rocksdb::OptimisticTransactionDB::Open(options, args.path, cfd, &handles, &db);
auto s = rocksdb::OptimisticTransactionDB::Open(options, args.path, &db);
assert(s.ok());
std::barrier barrier{static_cast<ptrdiff_t>(args.threads)};
@ -136,27 +117,23 @@ int main(int argc, char *argv[]) {
keys.emplace_back(std::move(key));
}
auto *handle = handles[0];
if (args.mode == "get") {
auto *kv = db->BeginTransaction(wopt);
for (size_t tid = 0; tid < args.threads; ++tid) {
auto *tk = &keys[tid];
for (auto &key: *tk) {
kv->Put(handle, key, val);
kv->Put(key, val);
}
}
kv->Commit();
delete kv;
delete handle;
delete db;
handles.clear();
// re-open db
s = rocksdb::OptimisticTransactionDB::Open(options, args.path, cfd, &handles, &db);
s = rocksdb::OptimisticTransactionDB::Open(options, args.path, &db);
assert(s.ok());
}
handle = handles[0];
for (size_t tid = 0; tid < args.threads; ++tid) {
auto *tk = &keys[tid];
wg.emplace_back([&] {
@ -170,7 +147,7 @@ int main(int argc, char *argv[]) {
if (args.mode == "insert") {
for (auto &key: *tk) {
auto *kv = db->BeginTransaction(wopt);
kv->Put(handle, key, val);
kv->Put(key, val);
kv->Commit();
delete kv;
}
@ -178,7 +155,7 @@ int main(int argc, char *argv[]) {
} else if (args.mode == "get") {
for (auto &key: *tk) {
auto *kv = db->BeginTransaction(wopt);
kv->Get(ropt, handle, key, &rval);
kv->Get(ropt, key, &rval);
kv->Commit();
delete kv;
}
@ -187,9 +164,9 @@ int main(int argc, char *argv[]) {
auto is_insert = dist(gen) < args.insert_ratio;
auto *kv = db->BeginTransaction(wopt);
if (is_insert) {
kv->Put(handle, key, val);
kv->Put(key, val);
} else {
kv->Get(ropt, handle, key, &rval); // not found
kv->Get(ropt, key, &rval); // not found
}
kv->Commit();
delete kv;
@ -207,10 +184,9 @@ int main(int argc, char *argv[]) {
return args.insert_ratio;
return args.mode == "insert" ? 100 : 0;
}();
uint64_t ops = total_op.load(std::memory_order_relaxed) / b.elapse_sec();
fmt::println("{},{},{},{},{},{},{}", args.mode, args.threads, args.key_size, args.value_size, ratio, (uint64_t) ops,
(uint64_t) b.elapse_ms());
delete handle;
double ops = static_cast<double>(total_op.load(std::memory_order_relaxed)) / b.elapse_sec();
fmt::println("{},{},{},{},{},{:.2f},{}", args.mode, args.threads, args.key_size, args.value_size, ratio, ops,
b.elapse_ms());
delete db;
std::filesystem::remove_all(args.path);
}

View File

@ -5,28 +5,26 @@ cd ..
cargo build --release 1>/dev/null 2> /dev/null
function samples() {
export RUST_BACKTRACE=full
kv_sz=(16 16 100 1024 1024 1024 16 10240)
kv_sz=(16 16 100 1024 1024 1024)
# set -x
cnt=10000
for ((i = 1; i <= $(nproc); i *= 2))
do
for ((j = 0; j < ${#kv_sz[@]}; j += 2))
do
./target/release/kv_bench --path /home/abby/mace_bench --threads $i --iterations $cnt --mode insert --key-size ${kv_sz[j]} --value-size ${kv_sz[j+1]}
./target/release/kv_bench --path /home/abby/mace_bench --threads $i --iterations 100000 --mode insert --key-size ${kv_sz[j]} --value-size ${kv_sz[j+1]}
if test $? -ne 0
then
echo "insert threads $i ksz ${kv_sz[j]} vsz ${kv_sz[j+1]} fail"
exit 1
fi
./target/release/kv_bench --path /home/abby/mace_bench --threads $i --iterations $cnt --mode get --key-size ${kv_sz[j]} --value-size ${kv_sz[j+1]}
./target/release/kv_bench --path /home/abby/mace_bench --threads $i --iterations 100000 --mode get --key-size ${kv_sz[j]} --value-size ${kv_sz[j+1]}
if test $? -ne 0
then
echo "get threads $i ksz ${kv_sz[j]} vsz ${kv_sz[j+1]} fail"
exit 1
fi
./target/release/kv_bench --path /home/abby/mace_bench --threads $i --iterations $cnt --mode mixed --key-size ${kv_sz[j]} --value-size ${kv_sz[j+1]} --insert-ratio 30
./target/release/kv_bench --path /home/abby/mace_bench --threads $i --iterations 100000 --mode mixed --key-size ${kv_sz[j]} --value-size ${kv_sz[j+1]} --insert-ratio 30
if test $? -ne 0
then
echo "mixed threads $i ksz ${kv_sz[j]} vsz ${kv_sz[j+1]} fail"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 127 KiB

View File

@ -6,26 +6,26 @@ cmake --preset release 1>/dev/null 2>/dev/null
cmake --build --preset release 1>/dev/null 2>/dev/null
function samples() {
kv_sz=(16 16 100 1024 1024 1024 16 10240)
kv_sz=(16 16 100 1024 1024 1024)
# set -x
cnt=10000
for ((i = 1; i <= $(nproc); i *= 2))
do
for ((j = 0; j < ${#kv_sz[@]}; j += 2))
do
./build/release/rocksdb_bench --path /home/abby/rocksdb_tmp --threads $i --iterations $cnt --mode insert --key-size ${kv_sz[j]} --value-size ${kv_sz[j+1]}
./build/release/rocksdb_bench --path /home/abby/rocksdb_tmp --threads $i --iterations 100000 --mode insert --key-size ${kv_sz[j]} --value-size ${kv_sz[j+1]}
if test $? -ne 0
then
echo "insert threads $i ksz ${kv_sz[j]} vsz ${kv_sz[j+1]} fail"
exit 1
fi
./build/release/rocksdb_bench --path /home/abby/rocksdb_tmp --threads $i --iterations $cnt --mode get --key-size ${kv_sz[j]} --value-size ${kv_sz[j+1]}
./build/release/rocksdb_bench --path /home/abby/rocksdb_tmp --threads $i --iterations 100000 --mode get --key-size ${kv_sz[j]} --value-size ${kv_sz[j+1]}
if test $? -ne 0
then
echo "get threads $i ksz ${kv_sz[j]} vsz ${kv_sz[j+1]} fail"
exit 1
fi
./build/release/rocksdb_bench --path /home/abby/rocksdb_tmp --threads $i --iterations $cnt --mode mixed --key-size ${kv_sz[j]} --value-size ${kv_sz[j+1]} --insert-ratio 30
./build/release/rocksdb_bench --path /home/abby/rocksdb_tmp --threads $i --iterations 100000 --mode mixed --key-size ${kv_sz[j]} --value-size ${kv_sz[j+1]} --insert-ratio 30
if test $? -ne 0
then
echo "mixed threads $i ksz ${kv_sz[j]} vsz ${kv_sz[j+1]} fail"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 144 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 117 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 128 KiB

View File

@ -41,9 +41,6 @@ struct Args {
#[arg(long, default_value = "false")]
random: bool,
#[arg(long, default_value = "8192")]
blob_size: usize,
}
fn main() {
@ -79,11 +76,10 @@ fn main() {
let mut keys: Vec<Vec<Vec<u8>>> = Vec::with_capacity(args.threads);
let mut opt = Options::new(path);
opt.sync_on_write = false;
opt.over_provision = true; // large value will use lots of memeory
opt.inline_size = args.blob_size;
opt.tmp_store = args.mode != "get";
let mut saved = opt.clone();
saved.tmp_store = false;
// opt.cache_capacity = 3 << 30; // this is very important for large key-value store
let mut db = Mace::new(opt.validate().unwrap()).unwrap();
db.disable_gc();
@ -184,7 +180,7 @@ fn main() {
let test_start = start_time.lock().unwrap();
let duration = test_start.elapsed();
let total = total_ops.load(std::sync::atomic::Ordering::Relaxed);
let ops = (total as f64 / duration.as_secs_f64()) as usize;
let ops = total as f64 / duration.as_secs_f64();
// println!("{:<20} {}", "Test Mode:", args.mode);
// println!("{:<20} {}", "Threads:", args.threads);