Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a limit of sub-databases in LMDB?

Tags:

lmdb

Posting here as I could not find any forums for lmdb key-value store.

Is there a limit for sub-databases? What is a reasonable number of sub-databases concurrently open?

I would like to have ~200 databases which seems like a lot and clearly indicates my model is wrong. I suppose could remodel and embed id of each db in key itself and keep one db only but then I have longer keys and also I cannot drop database if needed.

I'm interested though if LMDB uses some sort of internal prefixes for keys already. Any suggestions how to address that problem appreciated.

like image 562
ivenhov Avatar asked Mar 09 '15 01:03

ivenhov


People also ask

How does LMDB work?

LMDB has an API similar to Berkeley DB and dbm. LMDB treats the computer's memory as a single address space, shared across multiple processes or threads using shared memory with copy-on-write semantics (known historically as a single-level store).

What happens in transaction Lmdb?

The transaction provides a consistent view of the data. Once a transaction has been created, a database can be opened within it using mdb_dbi_open(). If only one database will ever be used in the environment, a NULL can be passed as the database name.

What is Lmdb in Python?

python-lmdb or py-lmdb is a Python binding for the Lightning Memory-Mapped Database (LMDB), a high-performance key-value store. Website: https://github.com/dw/py-lmdb. License: OpenLDAPv2.8, Modified BSD. Package source: databases.scm.


2 Answers

Instead of calling mdb_dbi_open each time, keep your own map with database names to database handles returned from mdb_dbi_open. Reuse these handles for the lifetime of your program. This will allow you to have multiple databases within an environment and prevent the overhead with mdb_dbi_open.

like image 96
Kanti Varanasi Avatar answered Jan 03 '23 22:01

Kanti Varanasi


If you read the documentation for mdb_env_set_maxdbs.

Currently a moderate number of slots are cheap but a huge number gets expensive: 7-120 words per transaction, and every mdb_dbi_open() does a linear search of the opened slots.

http://www.lmdb.tech/doc/group__mdb.html#gaa2fc2f1f37cb1115e733b62cab2fcdbc

The best way to know is to test the function call mdb_dbi_open performance to see if it is acceptable.

like image 21
rouzier Avatar answered Jan 03 '23 23:01

rouzier