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
Garbage Collector does not trim files (causing unbounded space use) #310
After importing every CSV file for 2012 basball statistics into a seperate table per file in RethinkDB 1.3.2 (on OS X,) I have noticed that the on disk format seems extraordinarily large, for simple data.
I started up 6 servers with RethinkDB. All on one machine (high end Core i7, 16 GB of RAM,) two data centers ('main' and 'backup',) three servers a piece, with various sharding/backups. There were only shards on the few largest tables. Backups were all mostly configured to the backup datacenter systems, with shards pinned to the main datacenter for performance (this is really awesome and easy, by the way :)
The CSV files are a simple 30 megabytes, and there are only about 500k rows across all files - but across all 6 servers with only a few tables sharded, I see well over 10GB of on disk usage.
I looked at one of my 6 servers. I took the one with the smallest amount of used space and compressed it. Using bzip to compress all the data made it go from 1GB to 89mb.
Are there any plans to implement on disk compression, or something like that? In my personal experience working on high performance I/O software for fame and glory in a past life, compression is almost always a worthy tradeoff in terms of CPU spent for I/O in terms of time and space. There are plenty of freely usable and high-speed compressors that should be able to handle this, with a compatible license. I have personal experience with both QuickLZ and Snappy. In general, bzip almost always gives the best compression ratios, but it's slow as hell.
Those compressors should easily handle I/O-level speeds for about any workload on a decent CPU, in my experience. And clearly the data seems redundant to the point that anything should give pretty good results. And obviously for some loads, it can even be faster - just due to the tradeoff of writing less to disk (this is extremely helpful when you get to rotational disks IME.)
I can give exact setup details to reproduce this if you would like, but I think the CSV files should be all you need.
Thank you for reporting this! We've been thinking about compression for some time, but there have been no concrete plans to implement it yet. The real issue here isn't about compression though. What happens with RethinkDB is that the storage engine garbage collector cleans up old blocks, but doesn't reduce the file size. This is something that we're likely to fix in the next two - three months. One way to test if this is actually the issue is to try to insert some data, then stop and let the garbage collector catch up, then insert some more data. It's likely that with this workload RethinkDB will result in much better space utilization. (This is of course no excuse for the behavior you're observing, just an explanation of the current limitations of the system).
We're going to get to this soon, but it would be incredibly helpful if you described a little more precisely what you did and how you got to this space utilization. When Rethink hits production ready state in the next few months, space utilization issues will of course be worked out. A minimum example of poor space utilization would be very helpful for us to work this out ASAP.
I see; this makes much more sense. I was shooting in the dark because the data merely compressed so well. If it was so simple you probably would have done it earlier. :)
I'm a wee bit tired now but I'll attempt to fully replicate my environment again tomorrow and have a good bug report for you. I also noticed some performance characteristics on OS X I thought were odd. I also have a moderately beefy linux machine with 16GB of RAM, so I can try and replicate the issue there too.
Now, begin going to large tables (like Salaries and especially Fielding) and creating shards and replicas. Set the primary datacenter to hold master shards to be 'master' and send more replications to 'backup'. Do this for multiple tables.
I set about 6 shards for 'Fielding' and 'Salaries', both with 3 replicas. Once you start replicating big tables like those two, the disk usage starts to get high (+6GB) pretty quickly. Hope that helps!
@thoughtpolice, thanks so much for the detailed report on how to reproduce this! Phenomenally documented-- this makes our job that much easier.
Regarding the insert performance, we're in the midst of working on 1.5 (which is adding secondary indexes), but the following release (1.6) will target performance bottlenecks. You can also track #457, which is specifically about an insert performance regression introduced in 1.4.
We'll get to work on replicating this and tracking disk usage / space utilization. Assigning this to @Tryneus to replicate this when he gets a chance (@coffemug, please confirm).
Insert performance woes will be partially solved in 1.5. The import command has a separate problem with slow inserts that we'll also try to solve ASAP.
As for disk space utilization, unfortunately it will have to wait until 1.6 or 1.7. Rethink has a lot of performance issues and the next few releases will be all about that. I can assure you that disk space issues will be solved (in case you're wondering if that's on our radar), but it likely won't be done until mid-late summer.
I am looking forward to seeing this, as size-on-disk my biggest pain point with the handful of nosql datastores I've used. I recently ran a comparison of RethinkDB vs MySQL as a sort of logging server. Rethink's size on disk was consistently 32x what MySQL used for the same data in a non-normalized, single-index MyISAM table.
@codekoala -- could you describe more precisely what the test looks like? RethinkDB is a bit greedy with disk, but typically isn't 32x as greedy. Having a bit more info about the precise workload would help a lot. (FYI -- we'll be starting a lot of optimization work in the next week or so, so as much info as possible would help tremendously)
@coffeemug I seem to have misplaced the code I used to produce the data I saw, but I do still have some graphs that I generated using the data. I ran the tests a few different times. The first set of graphs started out with just a single table in RethinkDB with a single-indexed (PK) table with the same columns in MySQL. The blue line you see toward the right side of the graphs is when I decided to see how things would change with a slightly more normalized setup in MySQL in addition to the non-normalized table and the RethinkDB table. It's kinda hard to see because it's just a thumbnail of the original that was overwritten by a later test.
The second set of graphs is a bit easier to read and illustrates more information. However, the test started to fail toward the end due to dropped connections that I didn't properly reconnect.
The data for the test were simply messages that I received in weechat. I wrote a plugin that sent any messages I received in a slew of IRC channels to both RethinkDB and MySQL. I was able to get grow my datasets quickly by joining a bunch of channels at once. I wasn't storing a whole lot of information for each message. I think the columns were something like: channel name, sender name, message, timestamp, and maybe a few other columns to indicate whether or not the message should be highlighted or whatever.
I can try to dig up the code/schema I used if that would be of use to you.
I think there are two things going on here. The first, is that RethinkDB on-disk compactor was poorly tuned, which was fixed. I'm not sure if you ran the tests before or after that happened -- do you remember the version of Rethink you ran the tests on?
The second issue is that the GC currently doesn't ever lower the file size. So, if there is a sustained write-only workload, the file grows in an unbounded way while most of it is empty. This clearly needs to be fixed.
I'm moving this to 1.6 -- we'll deal with it as part of the optimization work (though compression still won't make it in, the size explosion issue will be fixed).
Hi @thoughtpolice. As a general policy we don't like to rename the issues in our issue tracker because it breaks email threads. Even it cases like this where the new name better reflects what the issues is about we've found it's just better to stick with the old name and avoid the confusion for people following via email. Thanks in advance for your cooperation and hopefully we can get this issue resolved ASAP.
@coffeemug I performed my tests using the latest version of RethinkDB in the middle of February 2013. The graph images were produced on the 19th of February, after I had been running different variations of the test for a few days. Based on that, it seems that I would have been running either 1.3.1 or 1.3.2.
I look forward to seeing how this turns out! Thanks!
The real issue here isn't about compression though. What happens with RethinkDB is that the storage engine garbage collector cleans up old blocks, but doesn't reduce the file size.
This is untrue. If I import all of Pitching.csv (a 3,145,728 byte file) into a table, the table's file size becomes 220,725,248. Garbage blocks account for 18.9% of all data blocks, and there are approximately no free extents, so garbage can't account for more than that proportion of the file size.
There are 42740 non-garbage blocks. That means there's a block for every 84.3 bytes of CSV file data.
This makes sense if you consider that Pitching.csv has lines about 80-90 characters long -- and when converted into a JSON document with all the quoted column names and values, they grow to over 300 characters -- so there's a large value being stored per document, i.e. one data block per document.
What's weird though is that we get the same sort of measurement for AllstarFull. 40-byte lines in the CSV file, and about 1 active data block for every 40 bytes in the CSV file. I don't yet know how the JSON document could have ballooned to more than 170 bytes.
The threshold for using blob storage is 170 bytes?! That's awful. How does that make any sense?
(unless you assume that the distribution of data sizes is extremely uneven over the key range, and below 170 bytes for the majority of documents ... then you could sometimes save one level in the btree for those small values)
It turns out the things I was expected to be serialized to 170 bytes were getting serialized to 300-something. Because strings get serialized with a fixed 8-byte prefix.
@srh -- since you're really working on #939, I'm moving this issue back to backlog and moving #939 into 1.6. Once #939 is done, we can revisit garbage collector settings, truncating file sizes, and doing compression.
#939 is done. Garbage collector settings are generally equivalent, we still don't do compression, and file sizes are truncated, but our garbage collection code does not yet aggressively collect extents near the end of a largely empty file. An extent that's completely used which sits at the end of the file, or perhaps a long-lived LBA extent, will sit by uncollected for quite some time, keeping the file size artificially high. It remains to be seen whether that happens "in practice".
@srh -- do you mind if I close this issue? It seems that the issue originally outlined here is fixed and we can open a new issue later if non-aggressive end-of-file extent collection becomes a problem.
@srh -- I know there has been a fix put in so data uses 8x less space (which is awesome!) However, for workloads where data is temporary in nature, does the closure of this bug mean that data files no longer have unbounded growth?
This is important to me because I will often load a whole database, temporarily process it and drop it. It'd be nice if I wasn't continually ratcheting up my disk usage.
@jhstatewide -- all known bugs related to this have been fixed. (I just tested inserting a bunch of data into a table and deleting it in 1.8.0, and the file grows and shrinks as expected). If you run into any other issues on this, please open a new github issue and we'll fix it! (there aren't any issues I can think of, but this is always a good disclaimer, I think :))
Activity
coffeemug commentedon Feb 9, 2013
Thank you for reporting this! We've been thinking about compression for some time, but there have been no concrete plans to implement it yet. The real issue here isn't about compression though. What happens with RethinkDB is that the storage engine garbage collector cleans up old blocks, but doesn't reduce the file size. This is something that we're likely to fix in the next two - three months. One way to test if this is actually the issue is to try to insert some data, then stop and let the garbage collector catch up, then insert some more data. It's likely that with this workload RethinkDB will result in much better space utilization. (This is of course no excuse for the behavior you're observing, just an explanation of the current limitations of the system).
We're going to get to this soon, but it would be incredibly helpful if you described a little more precisely what you did and how you got to this space utilization. When Rethink hits production ready state in the next few months, space utilization issues will of course be worked out. A minimum example of poor space utilization would be very helpful for us to work this out ASAP.
thoughtpolice commentedon Feb 9, 2013
I see; this makes much more sense. I was shooting in the dark because the data merely compressed so well. If it was so simple you probably would have done it earlier. :)
I'm a wee bit tired now but I'll attempt to fully replicate my environment again tomorrow and have a good bug report for you. I also noticed some performance characteristics on OS X I thought were odd. I also have a moderately beefy linux machine with 16GB of RAM, so I can try and replicate the issue there too.
coffeemug commentedon Feb 12, 2013
Thanks, would love to see more details if you get the chance. For now, moving to backlog, this will likely be addressed in 1.6.
mping commentedon Mar 19, 2013
+1
thoughtpolice commentedon Apr 9, 2013
Alright. Sorry it took me so long to get back to you. Here's the rundown of how to reproduce all this:
Specifications of my machine:
Create 6 directories for your working databases, and download the baseball statistics:
Create 3 servers with data directories in
s0,s1,s2and put them in a datacenter called 'Master'.Now, separately, import the baseball stats:
This took a very long time on my machine which has an SSD. Anyway, now connect the next 3 servers:
Assign them to a 'backup' datacenter.
Now, begin going to large tables (like
Salariesand especiallyFielding) and creating shards and replicas. Set the primary datacenter to hold master shards to be 'master' and send more replications to 'backup'. Do this for multiple tables.I set about 6 shards for 'Fielding' and 'Salaries', both with 3 replicas. Once you start replicating big tables like those two, the disk usage starts to get high (+6GB) pretty quickly. Hope that helps!
mglukhovsky commentedon Apr 9, 2013
@thoughtpolice, thanks so much for the detailed report on how to reproduce this! Phenomenally documented-- this makes our job that much easier.
Regarding the insert performance, we're in the midst of working on 1.5 (which is adding secondary indexes), but the following release (1.6) will target performance bottlenecks. You can also track #457, which is specifically about an insert performance regression introduced in 1.4.
We'll get to work on replicating this and tracking disk usage / space utilization. Assigning this to @Tryneus to replicate this when he gets a chance (@coffemug, please confirm).
coffeemug commentedon Apr 9, 2013
Insert performance woes will be partially solved in 1.5. The import command has a separate problem with slow inserts that we'll also try to solve ASAP.
As for disk space utilization, unfortunately it will have to wait until 1.6 or 1.7. Rethink has a lot of performance issues and the next few releases will be all about that. I can assure you that disk space issues will be solved (in case you're wondering if that's on our radar), but it likely won't be done until mid-late summer.
codekoala commentedon May 6, 2013
I am looking forward to seeing this, as size-on-disk my biggest pain point with the handful of nosql datastores I've used. I recently ran a comparison of RethinkDB vs MySQL as a sort of logging server. Rethink's size on disk was consistently 32x what MySQL used for the same data in a non-normalized, single-index MyISAM table.
coffeemug commentedon May 6, 2013
@codekoala -- could you describe more precisely what the test looks like? RethinkDB is a bit greedy with disk, but typically isn't 32x as greedy. Having a bit more info about the precise workload would help a lot. (FYI -- we'll be starting a lot of optimization work in the next week or so, so as much info as possible would help tremendously)
codekoala commentedon May 6, 2013
@coffeemug I seem to have misplaced the code I used to produce the data I saw, but I do still have some graphs that I generated using the data. I ran the tests a few different times. The first set of graphs started out with just a single table in RethinkDB with a single-indexed (PK) table with the same columns in MySQL. The blue line you see toward the right side of the graphs is when I decided to see how things would change with a slightly more normalized setup in MySQL in addition to the non-normalized table and the RethinkDB table. It's kinda hard to see because it's just a thumbnail of the original that was overwritten by a later test.
The second set of graphs is a bit easier to read and illustrates more information. However, the test started to fail toward the end due to dropped connections that I didn't properly reconnect.
The data for the test were simply messages that I received in weechat. I wrote a plugin that sent any messages I received in a slew of IRC channels to both RethinkDB and MySQL. I was able to get grow my datasets quickly by joining a bunch of channels at once. I wasn't storing a whole lot of information for each message. I think the columns were something like: channel name, sender name, message, timestamp, and maybe a few other columns to indicate whether or not the message should be highlighted or whatever.
I can try to dig up the code/schema I used if that would be of use to you.
coffeemug commentedon May 6, 2013
Ah, I see, so this was an insert-only workload.
I think there are two things going on here. The first, is that RethinkDB on-disk compactor was poorly tuned, which was fixed. I'm not sure if you ran the tests before or after that happened -- do you remember the version of Rethink you ran the tests on?
The second issue is that the GC currently doesn't ever lower the file size. So, if there is a sustained write-only workload, the file grows in an unbounded way while most of it is empty. This clearly needs to be fixed.
I'm moving this to 1.6 -- we'll deal with it as part of the optimization work (though compression still won't make it in, the size explosion issue will be fixed).
thoughtpolice commentedon May 6, 2013
I have renamed this ticket to reflect what the actual problem is since it's now assigned.
I've opened #759 to deal with the issue of disk/network compression and whatnot.
jdoliner commentedon May 6, 2013
Hi @thoughtpolice. As a general policy we don't like to rename the issues in our issue tracker because it breaks email threads. Even it cases like this where the new name better reflects what the issues is about we've found it's just better to stick with the old name and avoid the confusion for people following via email. Thanks in advance for your cooperation and hopefully we can get this issue resolved ASAP.
codekoala commentedon May 7, 2013
@coffeemug I performed my tests using the latest version of RethinkDB in the middle of February 2013. The graph images were produced on the 19th of February, after I had been running different variations of the test for a few days. Based on that, it seems that I would have been running either 1.3.1 or 1.3.2.
I look forward to seeing how this turns out! Thanks!
coffeemug commentedon May 24, 2013
For those who are following, this is now slated for 1.6 and assigned to @srh.
coffeemug commentedon May 31, 2013
@srh -- procrastinating on pain-in-the-butt issues won't make them go away! :)
srh commentedon Jun 3, 2013
This is untrue. If I import all of Pitching.csv (a 3,145,728 byte file) into a table, the table's file size becomes 220,725,248. Garbage blocks account for 18.9% of all data blocks, and there are approximately no free extents, so garbage can't account for more than that proportion of the file size.
There are 42740 non-garbage blocks. That means there's a block for every 84.3 bytes of CSV file data.
This makes sense if you consider that Pitching.csv has lines about 80-90 characters long -- and when converted into a JSON document with all the quoted column names and values, they grow to over 300 characters -- so there's a large value being stored per document, i.e. one data block per document.
What's weird though is that we get the same sort of measurement for AllstarFull. 40-byte lines in the CSV file, and about 1 active data block for every 40 bytes in the CSV file. I don't yet know how the JSON document could have ballooned to more than 170 bytes.
danielmewes commentedon Jun 3, 2013
The threshold for using blob storage is 170 bytes?! That's awful. How does that make any sense?
(unless you assume that the distribution of data sizes is extremely uneven over the key range, and below 170 bytes for the majority of documents ... then you could sometimes save one level in the btree for those small values)
srh commentedon Jun 3, 2013
No, the threshold of blob storage is 250 bytes.
It turns out the things I was expected to be serialized to 170 bytes were getting serialized to 300-something. Because strings get serialized with a fixed 8-byte prefix.
srh commentedon Jun 5, 2013
I suspect this issue (that is, #939) will take at least to the end of the week.
coffeemug commentedon Jun 7, 2013
@srh -- since you're really working on #939, I'm moving this issue back to backlog and moving #939 into 1.6. Once #939 is done, we can revisit garbage collector settings, truncating file sizes, and doing compression.
srh commentedon Jul 31, 2013
#939 is done. Garbage collector settings are generally equivalent, we still don't do compression, and file sizes are truncated, but our garbage collection code does not yet aggressively collect extents near the end of a largely empty file. An extent that's completely used which sits at the end of the file, or perhaps a long-lived LBA extent, will sit by uncollected for quite some time, keeping the file size artificially high. It remains to be seen whether that happens "in practice".
coffeemug commentedon Aug 6, 2013
@srh -- do you mind if I close this issue? It seems that the issue originally outlined here is fixed and we can open a new issue later if non-aggressive end-of-file extent collection becomes a problem.
srh commentedon Aug 6, 2013
No.
jhstatewide commentedon Aug 16, 2013
@srh -- I know there has been a fix put in so data uses 8x less space (which is awesome!) However, for workloads where data is temporary in nature, does the closure of this bug mean that data files no longer have unbounded growth?
This is important to me because I will often load a whole database, temporarily process it and drop it. It'd be nice if I wasn't continually ratcheting up my disk usage.
coffeemug commentedon Aug 16, 2013
@jhstatewide -- all known bugs related to this have been fixed. (I just tested inserting a bunch of data into a table and deleting it in 1.8.0, and the file grows and shrinks as expected). If you run into any other issues on this, please open a new github issue and we'll fix it! (there aren't any issues I can think of, but this is always a good disclaimer, I think :))
srh commentedon Aug 19, 2013
@jhstatewide - There was an unrelated issue that caused this problem. It is also fixed in 1.8.