berkeley-db - 优化 Berkeley DB 中的 Put 性能

标签 berkeley-db okvs

几天前我刚刚开始使用 Berkeley DB,所以我想看看在尽可能快地存储数据方面是否遗漏了什么。

以下是有关数据的一些信息:
- 它有 512 字节的块
- 大块按顺序排列
- 块将按 FIFO 顺序删除
- 如果我最后因为断电而丢失了一些数据,只要整个数据库没有损坏就可以

在阅读了一堆文档后,似乎 Queue db 正是我想要的。

然而,在尝试了一些测试代码之后,我最快的结果是每秒大约 1MByte,只是循环通过 DB->put 设置 DB_APPEND。我也尝试过使用交易和批量看跌期权,但这两种方式都大大减慢了速度,所以我没有长时间追求它们。我正在插入一个在我的飞思卡尔 i.MX35 开发板上的 NANDFlash 芯片上创建的新数据库。

由于我们希望获得至少每秒 2MBytes 的写入速度,我想知道我是否遗漏了什么可以提高我的速度,因为我知道我的硬件可以比这更快地写入。

最佳答案

尝试将其放入您的 DB_CONFIG:

set_flags DB_TXN_WRITE_NOSYNC
set_flags DB_TXN_NOSYNC

根据我的经验,这些大大提高了写入性能。

DB_TXN_NOSYNC If set, Berkeley DB will not write or synchronously flush the log on transaction commit or prepare. This means that transactions exhibit the ACI (atomicity, consistency, and isolation) properties, but not D (durability); that is, database integrity will be maintained, but if the application or system fails, it is possible some number of the most recently committed transactions may be undone during recovery. The number of transactions at risk is governed by how many log updates can fit into the log buffer, how often the operating system flushes dirty buffers to disk, and how often the log is checkpointed Calling DB_ENV->set_flags with the DB_TXN_NOSYNC flag only affects the specified DB_ENV handle (and any other Berkeley DB handles opened within the scope of that handle). For consistent behavior across the environment, all DB_ENV handles opened in the environment must either set the DB_TXN_NOSYNC flag or the flag should be specified in the DB_CONFIG configuration file.

The DB_TXN_NOSYNC flag may be used to configure Berkeley DB at any time during the life of the application.



DB_TXN_WRITE_NOSYNC If set, Berkeley DB will write, but will not synchronously flush, the log on transaction commit or prepare. This means that transactions exhibit the ACI (atomicity, consistency, and isolation) properties, but not D (durability); that is, database integrity will be maintained, but if the system fails, it is possible some number of the most recently committed transactions may be undone during recovery. The number of transactions at risk is governed by how often the system flushes dirty buffers to disk and how often the log is checkpointed. Calling DB_ENV->set_flags with the DB_TXN_WRITE_NOSYNC flag only affects the specified DB_ENV handle (and any other Berkeley DB handles opened within the scope of that handle). For consistent behavior across the environment, all DB_ENV handles opened in the environment must either set the DB_TXN_WRITE_NOSYNC flag or the flag should be specified in the DB_CONFIG configuration file.

The DB_TXN_WRITE_NOSYNC flag may be used to configure Berkeley DB at any time during the life of the application.



http://www.mathematik.uni-ulm.de/help/BerkeleyDB/api_c/env_set_flags.html更多细节。

关于berkeley-db - 优化 Berkeley DB 中的 Put 性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3825022/

相关文章:

berkeley-db - 什么是 Berkeley DB 魔数(Magic Number)?

c - 如何让 DBCursor->get(...) 识别我为 key.data 和 data.data 分配的内存

file - 了解 KeyValue 嵌入式数据存储与文件系统

python - 在 python 中表达 berkeley db 中的多个列?

berkeley-db - BerkeleyDB 的替代品?

database - 用于大量条目的最佳 C 语言键/值数据库

jdbc - 如何使用 JDBC 连接到 Berkeley DB?