You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
We should consider gzipping datum_t objects when we serialize them #1396
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).
Reacted by Samuel Williams, Jonas Budelmann, Thorsten von Eicken, on-chain and David Ernst
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.
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.)
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.
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?
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.
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).
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?
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.
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.
@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.
snappy didn't give good enough space savings to be worthwhile.
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.
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.
@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.
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.
@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
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?
@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.
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.
Activity
coffeemug commentedon Aug 30, 2013
That would be awesome! (Unless we saturate the CPU, in which case that would not be awesome).
srh commentedon Sep 2, 2013
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.
srh commentedon Sep 2, 2013
We don't use protocol buffers to serialize datum_t objects.
srh commentedon Sep 2, 2013
Gzipping datum_t's and other forms of wanton compression could also expose some systems to BREACH-style attacks.
mlucy commentedon Sep 2, 2013
The string length thing would be good. What do you mean by "avoid writing keys in all the places"?
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.)
Duly noted; we should document that we do this. (This isn't as high on my list of concerns as our performance problems.)
coffeemug commentedon Sep 3, 2013
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.
underrun commentedon Sep 3, 2013
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.
mlucy commentedon Sep 9, 2013
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?
AtnNn commentedon Sep 9, 2013
If snappy is as portable and as easy to build as re2, it is plausible.
mlucy commentedon Sep 12, 2013
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.
mlucy commentedon Sep 12, 2013
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).
mlucy commentedon Sep 12, 2013
Also, snappy would perform much better if it were compressing multiple rows at a time, since it could then de-dup field names.
srh commentedon Sep 12, 2013
We should document that our database shouldn't be used for web applications?
jdoliner commentedon Sep 12, 2013
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?
srh commentedon Sep 12, 2013
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.34 remaining items
tkodw commentedon Feb 6, 2017
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.
robertjpayne commentedon Jul 31, 2017
@mlucy @coffeemug I'm looking at implementing this (as it'd be key to our usage of RethinkDB) can you elaborate on:
Was the only issue the CPU usage or were there other discoveries that made this unworkable?
danielmewes commentedon Sep 9, 2017
@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.
mlucy commentedon Sep 9, 2017
@robertjpayne -- my memory is that:
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.
ml31415 commentedon Sep 13, 2017
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/
robertjpayne commentedon Sep 13, 2017
@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.
ml31415 commentedon Sep 13, 2017
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.
robertjpayne commentedon Sep 13, 2017
@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
Extarys commentedon Sep 13, 2017
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?
robertjpayne commentedon Sep 13, 2017
@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.
Extarys commentedon Sep 13, 2017
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?
ml31415 commentedon Sep 13, 2017
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.
Extarys commentedon Sep 13, 2017
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.
ml31415 commentedon Sep 18, 2017
Just stumbled across another possible candidate, which recently got introduced to the linux kernel: https://github.com/facebook/zstd
robertjpayne commentedon Sep 18, 2017
@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.