leveldb之db_bench源码分析

// Comma-separated list of operations to run in the specified order
// Actual benchmarks:
// fillseq – write N values in sequential key order in async mode
// fillrandom – write N values in random key order in async mode
// overwrite – overwrite N values in random key order in async mode
// fillsync – write N/100 values in random key order in sync mode
// fill100K – write N/1000 100K values in random order in async mode
// deleteseq – delete N keys in sequential order
// deleterandom – delete N keys in random order
// readseq – read N times sequentially
// readreverse – read N times in reverse order
// readrandom – read N times in random order
// readmissing – read N missing keys in random order
// readhot – read N times in random order from 1% section of DB
// seekrandom – N random seeks
// seekordered – N ordered seeks
// open – cost of opening a DB
// crc32c – repeated crc32c of 4K of data
// Meta operations:
// compact – Compact the entire DB
// stats – Print DB stats
// sstables – Print sstable info
// heapprofile – Dump a heap profile (if supported by this port)

// 以指定顺序运行的以逗号分隔的操作列表
// 实际基准:
同步和异步的区别:
异步:写入到内存就反馈写入成功了,写入磁盘就不管了。
同步:必须写入磁盘才算写入成功。

异步写操作通常比同步写操作快一千倍。
合方案也是可能的,其中每第N次写入是同步的,并且在崩溃的情况下,批量加载刚好在由前一次运行完成的最后同步写入之后重新启动。 (同步写入可以更新描述崩溃时重新启动位置的标记。)
WriteBatch提供了异步写入的替代方法。 多个更新可以放置在同一WriteBatch中,并使用同步写入(即,write_options.sync设置为true)一起应用。 同步写入的额外成本将在批次中的所有写入之间摊销。

 leveldb::WriteOptions write_options;
  write_options.sync = true;
  db->Put(write_options, ...);

// fillseq – 在异步模式下按key的顺序,顺序写入 N 个V
—正常情况下,leveldb选择的是异步模式。(顺序写入,采用:writeSeq)
// fillrandom – 在异步模式下以随机键顺序写入 N 个值
----采用writerandom
// overwrite – 在异步模式下以随机键顺序覆盖 N 个值
// fillsync – 在同步模式下以随机键顺序写入 N/100 个值
// fill100K – 在异步模式下以随机顺序写入 N/1000 个 100K 值
// deleteseq – 按顺序删除N个键
// deleterandom – 以随机顺序删除N个键
// readeq – 顺序读取N次
// readreverse – 以相反的顺序读取 N 次
// readrandom – 以随机顺序读取N次

// readmissing – 以随机顺序读取 N 个缺失的键
// readhot – 从 DB 的 1% 部分以随机顺序读取 N 次
// seekrandom – N 个随机搜索

// seekordered – N 个有序搜索
// open – 打开数据库的成本
// crc32c – 4K数据的重复crc32c
// 元操作:
// compact – 压缩整个数据库
// stats – 打印数据库统计信息
// sstables – 打印sstable信息
// heapprofile – 转储堆配置文件(如果此端口支持)

使用方法

说明选自 https://github.com/facebook/rocksdb/wiki/Benchmarking-tools

./db_bench --benchmarks=“fillseq”

./db_bench --benchmarks=“fillseq,stats” --statistics

./db_bench --benchmarks=“readrandom” --use_existing_db

./db_bench --benchmarks=“fillseq,readrandom,readseq”

RocksDB Benchmarks List:

readwhilewriting – 1 writer, N threads doing random reads

  readwhilemerging      -- 1 merger, N threads doing random reads

  readrandomwriterandom -- N threads doing random-read, random-write

cache_bench

./cache_bench --help

cache_bench: Warning: SetUsageMessage() never called

猜你喜欢

转载自blog.csdn.net/weixin_41523437/article/details/121047609