Skip to content

We should consider gzipping datum_t objects when we serialize them #1396

Open

Description

@mlucy

This results in space savings for even smallish documents, for several reasons:

  • Englishy language compresses by a factor of 4.
  • We use a whole double to store every number, so arrays of small numbers compress by a factor of 10 (counting protobuf overhead).
  • Our protobuf format has to use multiple type tags for every datum term -- we have a type for the term, then a type for the datum. Compressing away protobuf overhead alone gives pretty good savings (although this is harder to quantify).

Activity

  1. coffeemug commented on Aug 30, 2013

    @coffeemug
    Contributor

    That would be awesome! (Unless we saturate the CPU, in which case that would not be awesome).

  2. srh commented on Sep 2, 2013

    @srh
    Contributor

    Before that we should add variable length encoding for string lengths (edit: that was done btw) and find some way to avoid writing keys in all the places.

  3. srh commented on Sep 2, 2013

    @srh
    Contributor

    We don't use protocol buffers to serialize datum_t objects.

  4. srh commented on Sep 2, 2013

    @srh
    Contributor

    Gzipping datum_t's and other forms of wanton compression could also expose some systems to BREACH-style attacks.

  5. mlucy commented on Sep 2, 2013

    @mlucy
    MemberAuthor

    Before that we should add variable length encoding for string lengths and find some way to avoid writing keys in all the places.

    The string length thing would be good. What do you mean by "avoid writing keys in all the places"?

    We don't use protocol buffers to serialize datum_t objects.

    We may want to consider offering gzip compression to/from the clients, too. (Also, our own serialization function isn't that much better; we still serialize a whole double for every number, for example.)

    Gzipping datum_t's and other forms of wanton compression could also expose some systems to BREACH-style attacks.

    Duly noted; we should document that we do this. (This isn't as high on my list of concerns as our performance problems.)

  6. coffeemug commented on Sep 3, 2013

    @coffeemug
    Contributor

    What do you mean by "avoid writing keys in all the places"?

    I think he means that if you have a billion documents, each with a field "first_name", we'll end up writing the string "first_name" a billion times.

  7. underrun commented on Sep 3, 2013

    @underrun

    please don't use gz as it is a CPU drain and slow (relatively speaking).

    compression can gain you both space and speed performance if you choose an algorithm that has a higher bandwidth than the device from/to which you are reading/writing (either network or storage), and luckily these algorithms are typically very easy on the CPU as well.

    look at lzo if you want something commonly available and well suited to high speed / low cpu. maybe take a peak at google's snappy as well.

  8. mlucy commented on Sep 9, 2013

    @mlucy
    MemberAuthor

    I'd like to do this sooner rather than later, because I think it will help with Benchmark X (both speed and actually fitting the goddamn thing on disk).

    @jdoliner also recommended snappy, so I'm going to look into that.

    @AtnNn -- snappy doesn't seem to have pre-precise packages, so we'd probably have to include it like with re2. Would that be plausible?

  9. AtnNn commented on Sep 9, 2013

    @AtnNn
    Member

    If snappy is as portable and as easy to build as re2, it is plausible.

  10. mlucy commented on Sep 12, 2013

    @mlucy
    MemberAuthor

    I've looked into this more.

    Snappy is really fast (4-5x zlib on zlib's fastest compression speed), but it has really poor compression on some workloads. It can barely compress English text at all (it takes the size down by about 20%, compared to about 50% for zlib). My hypothesis is that zlib is getting good compression on english text by compressing more common characters (like e) to fewer than 8 bits; snappy doesn't do entropy encoding, so it can't do very well on those inputs (about all it can do is eliminate common subsequences of letters).

    Snappy does much better on more redundant data; it takes the size of a random github issue I picked through the JSON API down by about 50%, probably because of all the repeated URLs and stuff.

  11. mlucy commented on Sep 12, 2013

    @mlucy
    MemberAuthor

    I think we should just use snappy for now. Our original test data for benchmark X was highly redundant because it wasn't written expecting to be compressed; we'll have to revise it with a target snappy compression ration of about .5 (GitHub seems like as good a standard as anything for how well JSON documents will compress).

  12. mlucy commented on Sep 12, 2013

    @mlucy
    MemberAuthor

    Also, snappy would perform much better if it were compressing multiple rows at a time, since it could then de-dup field names.

  13. srh commented on Sep 12, 2013

    @srh
    Contributor

    Duly noted; we should document that we do this. (This isn't as high on my list of concerns as our performance problems.)

    We should document that our database shouldn't be used for web applications?

  14. jdoliner commented on Sep 12, 2013

    @jdoliner
    Contributor

    Maybe I don't understand breach style attacks but all the data we'd be compressing is data we've previously been passing around as clear text. How is this going to make things less secure?

  15. srh commented on Sep 12, 2013

    @srh
    Contributor

    A BREACH style attack is what you get when you compress secret data together with attacker-supplied data. The attacker can then figure out the contents of the secret data by measuring how well his data compresses together with the secret data.

    For example, suppose a dating website stores users' information in the following format { username: ..., email_address: ..., inbox: [...]}. A stalker could then figure out a user's email address by sending/deleting messages to the user and measuring how long it takes the server to respond to requests involving the user. You can do this with relatively low timing resolution if you first figure out how much padding the message needs to be to make the document size reach the threshold of a block boundary.

  16. 34 remaining items

  17. tkodw commented on Feb 6, 2017

    @tkodw

    Zstd has a non-optional entropy encoder stage, which causes it to require ~3-4 times the CPU resources of LZ4 or Snappy. Zstd's extra compression ratio comes at a much higher risk of creating a CPU bottleneck.

    I think Zstd makes a good choice for an optional higher compression setting, considering that it beats zlib in both compression and decompression speed by a wide margin.

  18. robertjpayne commented on Jul 31, 2017

    @robertjpayne
    Contributor

    @mlucy @coffeemug I'm looking at implementing this (as it'd be key to our usage of RethinkDB) can you elaborate on:

    Talked to @mlucy -- we did some experiments, and there is no quick fix we can merge yet. Moving to backlog.

    Was the only issue the CPU usage or were there other discoveries that made this unworkable?

  19. danielmewes commented on Sep 9, 2017

    @danielmewes
    Member

    @robertjpayne I unfortunately don't remember any details about this. I think that comment was probably based on some kind of implementational complexity assessment, not CPU usage concerns though. But I have no clue anymore what those complexities might have been.

  20. mlucy commented on Sep 9, 2017

    @mlucy
    MemberAuthor

    @robertjpayne -- my memory is that:

    1. gzip was too CPU intensive.
    2. snappy didn't give good enough space savings to be worthwhile.
    3. The largest benefits came from compressing multiple documents with a single symbol table (because often they all share the same keys), but this was more complicated than compressing individual documents.

    If all you need is single-document compression, and there's a compression algorithm that has the right CPU/space tradeoff on your data, then I don't see any problem with adding it.

  21. ml31415 commented on Sep 13, 2017

    @ml31415

    Glad to see that there is still some activity on this topic. Compression is really a must have for document based databases in order to get rid of the millions of redundant keys within the data. I'd like to draw your attention to this benchmark comparison, including most recent compression algorithms, also from a DB developer point of view. LZ4 is the clear winner there.

    https://www.percona.com/blog/2016/04/13/evaluating-database-compression-methods-update/

  22. robertjpayne commented on Sep 13, 2017

    @robertjpayne
    Contributor

    @ml31415 there's still no clear path forward on this -- it's a massive undertaking because not only does it need to happen on the log serialiser it also needs to be able to upgrade existing tables.

    I almost reckon it's more worth while to officially support running on ZFS, if ZFS is configured with the right block sizes it can do the compression on the fly with minimal overhead.

  23. ml31415 commented on Sep 13, 2017

    @ml31415

    Sounds interesting. I'd love to use rethinkdb for a redesign of our trading engine, due to the amazing streaming features and the great syntax, but I can't have it bloat the majority of the used disk space with endless copies of key data. It's a pity that there is no DB combining the rethink API and streaming features with a more structured way of storing data and ideally columnwise compression.

  24. robertjpayne commented on Sep 13, 2017

    @robertjpayne
    Contributor

    @ml31415 there's good reasons not to use compression too (CPU overhead, crypto attacks etc…) I'd recommend you look at ZFSOnLinux and particularly how to set it up for MySQL as RethinkDB would benefit from a similar setup.

    Though I believe RethinkDB pages data in 4KB blocks where as MySQL uses 16KB blocks

  25. Extarys commented on Sep 13, 2017

    @Extarys

    Dropping by to say I'm pro compression. It could be as a connection option or a query option.
    It would save bandwidth/time/memory for large query like "all product of company X". Although for querying individual documents I don't see any direct benefit.

    On the same issue, any idea if the overhead would be too high storing the data of rethinkdb in a mounted swift container?

  26. robertjpayne commented on Sep 13, 2017

    @robertjpayne
    Contributor

    @Extarys compression on the wire protocol is a totally different issue ( much easier ), storage compression is what is being discussed here and is much harder.

  27. Extarys commented on Sep 13, 2017

    @Extarys

    Oh I wasn't quite sure so I took my chance. I prefer performance vs disk space. What does similar db engine do? Does the "competition" compress?

  28. ml31415 commented on Sep 13, 2017

    @ml31415

    Yes, most document oriented DBs feature compression in some way. Storing documents as JSON strings just cries for proper compression. E.g. imagine billions of strings like "{timestamp: 123123123, bid: 123, ask: 124, bvol: 100, avol: 200}". It has let's say 12 bytes usable info in there. The record would use 64 bytes on disk without compression. That's a bloat by a factor of 5, and it could go worse, if you have longer key strings.

  29. Extarys commented on Sep 13, 2017

    @Extarys

    I'm currently working with multiple big objects so I can imagine how fast this can grow in disk space.

    I know for files LZMA offer the best between cpu time and compression rate, though I think it requires more memory.

  30. ml31415 commented on Sep 18, 2017

    @ml31415

    Just stumbled across another possible candidate, which recently got introduced to the linux kernel: https://github.com/facebook/zstd

  31. robertjpayne commented on Sep 18, 2017

    @robertjpayne
    Contributor

    @ml31415 the reality is that single-document compression isn't going to be worth it for the CPU it costs. Have to get block level across the whole db.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions