GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Storage Efficiency Storage Efficiency
Ben Alex edited this page
We often receive questions about how LMDB stores data, especially when disk space consumption is being reported at higher levels than would be expected. This page tries to explain a little more about what is going on and how to optimise the storage efficiency. To help make this wiki page more informative, let’s use the To run the final File path = new File("lmdb"); final File copy = new File("lmdb-copy"); try (Env<ByteBuffer> env = create() .setMaxReaders(1) .setMaxDbs(Verifier.DBI_COUNT) .setMapSize(MEBIBYTES.toBytes(50)) .open(path, MDB_NOSUBDIR)) { final Verifier v = new Verifier(env); final long r = v.runFor(30, SECONDS); System.out.println("Records verified: " + r); System.out.println(env.info()); System.out.println(env.stat()); env.copy(copy, MDB_CP_COMPACT); } When run we receive the following output:
Let’s have a look at the size of the resulting database files, starting with $ ls -lh lmdb lmdb-copy -rw-r----- 1 bpa bpa 1.1M May 22 12:47 lmdb -rw-r----- 1 bpa bpa 80K May 22 12:47 lmdb-copy You will note our first surprise: the The Now we’ll look at Let’s change the way we create the database to use a memory-mapped file. This will result in LMDB allocating a sparse file to hold the data. This usually provides performance gains by reducing allocations (at the expense of some safety). To use a memory-mapped file we open the After deleting the old databases and running again with Here we see we only processed 2049 records, which was materially fewer than the earlier (non-memory-mapped) approach. But our goal here is to look at disk space – not benchmark the various It’s interesting to note that despite far few records being processed and correspondingly fewer transactions (37), the last page number is once again 276. Let’s take a look at $ ls -lh lmdb lmdb-copy -rw-r----- 1 bpa bpa 50M May 22 13:14 lmdb -rw-r----- 1 bpa bpa 80K May 22 13:14 lmdb-copy The If we use We can verify this further using There are some techniques available to reduce the size of LMDB databases. The starting point is to minimise the amount of data you are asking LMDB to store. This is discussed in detail on the Value Serialisation and Compression page. As discussed on the Concurrency page, due to MVCC it is important to minimise the duration of any write If your workload allows you to insert data in key order, you should always do this. LMDB has internal optimisations that detect sequential inserts and assume these will continue, meaning it biases page splits in a manner that is more space efficient. If you are inserting data in sequential order and will not be adding random data later on, use To recover space you can perform a copy with If you need to store larger values, it’s worth considering LMDB’s page allocation approach. A page is usually 4096 bytes and requires a 16 byte header. This leaves 4080 bytes for records. Each record consists of an 8 byte overhead plus the user data (ie length of the user-provided key and value). With a minimum of 2 records per page, the optimal value for the user-provided key and value is 2032 bytes (ie (4080 / 2) – 8). If records are larger than this, they spill to overflow pages. Larger records should provide user data in 4096 byte increments, less 16 bytes for the initial header. We have seen that LMDB storage consumption can be examined using several approaches, including There are always storage consumption benefits by reducing concurrent Clone this wiki locally |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |