优化 Berkeley DB 中的 Put 性能
几天前我刚刚开始使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将其放入您的 DB_CONFIG 中:
根据我的经验,这些可以大大提高写入性能。
请参阅http://www.mathematik.uni-ulm.de/ help/BerkeleyDB/api_c/env_set_flags.html 了解更多详细信息。
Try putting this into your DB_CONFIG:
From my experience, these increase write performance a lot.
See http://www.mathematik.uni-ulm.de/help/BerkeleyDB/api_c/env_set_flags.html for more details.
如果正如您提到的,如果数据库损坏而无法重新创建数据库(即它不仅仅是本地缓存),我建议您必须使用事务/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.