优化 Berkeley DB 中的 Put 性能

发布于 2024-09-26 02:38:52 字数 457 浏览 4 评论 0原文

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

以下是有关数据的一些信息: - 它有 512 字节块 - 块按顺序排列 - 块将按照 FIFO 顺序删除 - 如果我由于电源故障而丢失了一些数据,只要整个数据库没有损坏就可以了

在阅读了一堆文档之后,似乎队列数据库正是我想要的。

然而,在尝试了一些测试代码后,我最快的结果约为每秒 1MByte,只需循环使用 DB_APPEND 设置的 DB-> put 即可。我还尝试过使用交易和批量看跌期权,但这两种方式都会大大减慢速度,所以我没有花太多时间追求它们。我正在将其插入在 Freescale i.MX35 开发板上的 NANDFlash 芯片上创建的新数据库中。

由于我们希望获得至少 2MBytes 每秒的写入速度,我想知道是否有一些我错过的东西可以提高我的速度,因为我知道我的硬件可以比这更快地写入。

I just started playing with Berkeley DB a few days ago so I'm trying to see if there's something I've been missing when it comes to storing data as fast as possible.

Here's some info about the data:
- it comes in 512 byte chunks
- chunks come in order
- chunks will be deleted in FIFO order
- if i lose some data off the end because of power failure that's ok as long as the whole db isn't broken

After reading the a bunch of the documentation it seemed like a Queue db was exactly what I wanted.

However, after trying some test code my fastest results were about 1MByte per second just looping through a DB->put with DB_APPEND set. I also tried using transactions and bulk puts but both of these slowed things down considerably so I didn't pursue them for much time. I was inserting into a fresh db created on a NANDFlash chip on my Freescale i.MX35 dev board.

Since we're looking to get at least 2MBytes per second write speeds, I was wondering if there's something I missed that can improve my speeds since I know that my hardware can write faster than this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

放赐 2024-10-03 02:38:52

尝试将其放入您的 DB_CONFIG 中:

set_flags DB_TXN_WRITE_NOSYNC
set_flags DB_TXN_NOSYNC

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


DB_TXN_NOSYNC
如果设置,Berkeley DB 将不会在事务提交或准备时写入或同步刷新日志。这意味着事务表现出 ACI(原子性、一致性和隔离性)属性,但不表现出 D(持久性)属性;也就是说,将保持数据库完整性,但如果应用程序或系统发生故障,则可能会在恢复期间撤消某些最近提交的事务。面临风险的事务数量取决于日志缓冲区可以容纳的日志更新数量、操作系统将脏缓冲区刷新到磁盘的频率以及日志设置检查点的频率
使用 DB_TXN_NOSYNC 标志调用 DB_EN​​V->set_flags 仅影响指定的 DB_EN​​V 句柄(以及在该句柄范围内打开的任何其他 Berkeley DB 句柄)。为了在整个环境中保持一致的行为,在环境中打开的所有 DB_EN​​V 句柄必须设置 DB_TXN_NOSYNC 标志,或者应在 DB_CONFIG 配置文件中指定该标志。

DB_TXN_NOSYNC 标志可用于在应用程序生命周期内的任何时间配置 Berkeley DB。


DB_TXN_WRITE_NOSYNC
如果设置,Berkeley DB 将在事务提交或准备时写入日志,但不会同步刷新。这意味着事务表现出 ACI(原子性、一致性和隔离性)属性,但不表现出 D(持久性)属性;也就是说,将保持数据库完整性,但如果系统发生故障,则在恢复期间可能会撤消某些最近提交的事务。面临风险的事务数量取决于系统将脏缓冲区刷新到磁盘的频率以及日志检查点的频率。
使用 DB_TXN_WRITE_NOSYNC 标志调用 DB_EN​​V->set_flags 仅影响指定的 DB_EN​​V 句柄(以及在该句柄范围内打开的任何其他 Berkeley DB 句柄)。为了在整个环境中保持一致的行为,在环境中打开的所有 DB_EN​​V 句柄必须设置 DB_TXN_WRITE_NOSYNC 标志,或者应在 DB_CONFIG 配置文件中指定该标志。

DB_TXN_WRITE_NOSYNC 标志可用于在应用程序生命周期内的任何时间配置 Berkeley DB。

请参阅http://www.mathematik.uni-ulm.de/ help/BerkeleyDB/api_c/env_set_flags.html 了解更多详细信息。

Try putting this into your DB_CONFIG:

set_flags DB_TXN_WRITE_NOSYNC
set_flags DB_TXN_NOSYNC

From my experience, these increase write performance a lot.


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.

See http://www.mathematik.uni-ulm.de/help/BerkeleyDB/api_c/env_set_flags.html for more details.

奢望 2024-10-03 02:38:52

如果正如您提到的,如果数据库损坏而无法重新创建数据库(即它不仅仅是本地缓存),我建议您必须使用事务/TDS 数据存储。如果您不关心在崩溃/断电时丢失一些项目,那么 DB_TXN_WRITE_NOSYNC 将提高 TDS 性能,您的数据库仍然是完整且可恢复的。
如果您使用 BTREE 和数字索引(如果没有自然键)进行存储,并注意字节顺序问题,以便获得良好的键局部性和高页面利用率,那么您应该能够每秒获得超过 2000 次插入,尤其是对于SSD,特别是当您使用 DbMultileKeyDataBuilder 进行批量插入时。

I suggest you must use transactions / TDS datastore if as you mention you cannot recreate a database (i.e. it isnt just a local cache) if it gets corrupted. If you dont care about loosing a few items in event of a crash/power outage then DB_TXN_WRITE_NOSYNC will improve TDS performance, you database will still be integral and recoverable.
If you store using BTREE and a numeric index (if you have no natural key) and watch out for endian issues so you get good key locality and high page utilization then you should be able to get way more than 2000 inserts a second, especially to SSD, especially if you Use DbMultileKeyDataBuilder to do bulk inserts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文