lmdb.open的参数

本文详细解释了LMDB库的四个关键参数:readahead影响随机读性能,create决定目录创建,readonly锁定写操作,lock控制并发。特别关注map_size对内存映射的影响和默认设置策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

lmdb.open的参数

readahead

`readahead`:
            If ``False``, LMDB will disable the OS filesystem readahead
            mechanism, which may improve random read performance when a
            database is larger than RAM.

如果为False,则LMDB将禁用OS文件系统预读机制,可以改善随机读取的性能数据库大于RAM。

create

`create`:
            If ``False``, do not create the directory `path` if it is missing.

readonly

`readonly`:
            If ``True``, disallow any write operations. Note the lock file is
            still modified. If specified, the ``write`` flag to
            :py:meth:`begin` or :py:class:`Transaction` is ignored.

如果为True,则禁止执行任何写操作。 注意锁文件是仍然修改。
如果指定,则将write标志:py:meth:begin或:py:class:Transaction被忽略。

lock

`lock`:
            If ``False``, don't do any locking. If concurrent access is
            anticipated, the caller must manage all concurrency itself. For
            proper operation the caller must enforce single-writer semantics,
            and must ensure that no readers are using old transactions while a
            writer is active. The simplest approach is to use an exclusive lock
            so that no readers may be active at all when a writer begins.

如果为False,请不要进行任何锁定。 如果并发访问是预期,调用者必须自己管理所有并发。
为了调用者必须执行正确的操作,才能强制执行单写者语义, 并且必须确保没有读者使用旧交易,而是活跃的。
最简单的方法是使用排他锁这样一来,当作家开始写作时,就不会有任何读者处于活跃状态。

map_size

`map_size`:
            Maximum size database may grow to; used to size the memory mapping.
            If database grows larger than ``map_size``, an exception will be
            raised and the user must close and reopen :py:class:`Environment`.
            On 64-bit there is no penalty for making this huge (say 1TB). Must
            be <2GB on 32-bit.

            .. note::

                **The default map size is set low to encourage a crash**, so
                users can figure out a good value before learning about this
                option too late.

数据库的最大大小可能会增加到; 如果数据库的大小大于map_size的大小,则会引发异常,用户必须关闭并重新打开环境。
在64位上,使它变大(例如1TB)不会受到任何惩罚。 在32位上必须小于2GB。
默认大小设置得太小会导致崩溃,因此用户在了解此选项之前为时已晚,可以找到一个好的价值。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值