Skip to content

Add persistence examples using shelve/dbm, lmdb #131

Closed

Description

@alimanfoo

As discovered in #129, the Python standard shelve module can be used for persistent storage as it provides the MutableMapping interface. This is a good alternative to using the file system directly as it avoids lots of files. It's also a good alternative to using a Zip file which needs care when writing to avoid duplicate entries. Similar benefits probably apply to LMDB which has a MutableMapping interface provided by zict.

It would be good to add some examples using shelve and LMDB to the tutorial.

Activity

  1. added this to the v2.2 milestone on Feb 24, 2017
  2. alimanfoo commented on Feb 27, 2017

    @alimanfoo
    MemberAuthor

    xref #133 - using dbm directly rather than shelve is probably a better example, as this would bypass the pickling/unpickling of values that shelve does, which in the case of Zarr is unnecessary as values are always bytes objects. However, dbm databases cannot currently be used directly as a store because they return keys as bytes objects.

  3. alimanfoo commented on Feb 27, 2017

    @alimanfoo
    MemberAuthor

    Btw just as a reminder, LMDB supports returning buffer objects which provide direct access to it's own memory-mapped data, which should reduce the number of memory copies required. It would be interesting to benchmark this against other key-value stores to see if this provides an noticeable performance improvement (it may not if compression/decompression is the bottleneck, although previously I have found reducing memory copies can make a difference). Would require some tweak to zict's LMDB wrapper to enable the buffer support.

  4. changed the title [-]Add persistence examples using shelve, lmdb[/-] [+]Add persistence examples using shelve/dbm, lmdb[/+] on Feb 27, 2017
  5. jakirkham commented on Feb 27, 2017

    @jakirkham
    Member

    LMDB is definitely pretty slick from what I have read. Another kind of similar database to look at that might be nice is UnQLite.

    Agree that pickling/unpickling done by shelve is unnecessary, but would be curious what the overhead is like. If it's not large, having something from the standard library that is easy to setup is nice.

  6. alimanfoo commented on Feb 27, 2017

    @alimanfoo
    MemberAuthor
  7. alimanfoo commented on Feb 27, 2017

    @alimanfoo
    MemberAuthor
  8. jakirkham commented on Feb 27, 2017

    @jakirkham
    Member

    How big were your data and chunks?

    ...pickling reduces portability of data across Python versions.

    As long as we stick to version 0, which is the default, we should be fine.

    Hence if it was possible to use the Python dbm module directly instead of shelve (which is a very thin wrapper around dbm) that would be preferable.

    Agreed. Though a potential downside is sometimes it is tricky to get a fully built dbm module. I think we (conda-forge) don't support the GNU stuff (gdbm). Perhaps we could try though. ( conda-forge/python-feedstock#125 )

  9. alimanfoo commented on Feb 27, 2017

    @alimanfoo
    MemberAuthor
  10. jakirkham commented on Feb 27, 2017

    @jakirkham
    Member

    I thought pickle version 3 was default on Python 3, which is not compatible with Python 2?

    Yep, sorry, I misspoke. So we could still force it to 0.

    Yeah, I wouldn't want to cause more work for you guys, you've got so much on already.

    If it's helpful, we can explore as time allows. The main thing to notice is these might be tricky things to get working on Windows.

    That said it would be nice to have a "recommended/preferred" key-value store for use with Zarr, which is reasonably performant and very easy to install (if not available in standard library)

    I would guess that LMDB is going to actually be a good mix of these. We already have a Python package for this for all platforms at conda-forge. They also build wheels for Windows that they have on PyPI. Building on Unix is straightforward.

    It might be worthwhile to have shelve if we want something that works with the standard library. While dbm might be more performant, getting a fully featured build of this for all platforms may be more work and still be less performant than LMDB.

  11. removed this from the v2.2 milestone on Oct 31, 2017
  12. added this to the v2.2 milestone on Nov 16, 2017
  13. added
    documentationImprovements to the documentation
    release notes doneAutomatically applied to PRs which have release notes.
    on Nov 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements to the documentationrelease notes doneAutomatically applied to PRs which have release notes.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions