Skip to content

Investigate disk space usage #2457

Closed
Closed

Description

@coffeemug

Reported by a user on 1.12.5:

Sample documents:

{"a":"d0a3f01a","u":"332d4319","c":"204625db","cc":"MX","_c":"2014-03-01 00:01:52","r":"","ip":"201.132.177.186","e1":"L0E8TZZ51B-PWo.BN63HEJ","e2":""},
{"a":"9225a8d4","u":"4dcb4186","c":"82dd26ff","cc":"MX","_c":"2014-03-01 00:00:35","r":"","ip":"187.151.59.214","e1":"","e2":""},
{"a":"2d3d8f66","u":"e963d421","c":"984ba862","cc":"","_c":"2014-03-01 00:01:40","r":"","ip":"181.24.0.140","e1":"L0EA1ZZ52D-PW_JBOXkGwy","e2":""},
{"a":"67cd25ab","u":"75c5dd6c","c":"8f016fc1","cc":"IN","_c":"2014-03-01 00:01:14","r":"http:\/\/adserver.bigboxnet.com\/r\/id,cCjsNSIPg1H6ir-AGCYzvmuI0Zie_sIMw-P2cTZD_ovt15ah8Zwjlh-b35Ap2Ba-IcgGn1w3S-Y5s6GY9FW4OA==","ip":"125.62.209.207","e1":"","e2":""}

With 27M documents, the user reports on-disk size of 56GB.

Looking at the sample documents, they're between 100-256 bytes in size. Even if we assume 512 bytes, back of the napkin math suggests raw size should be about 12GB. Double that because the btree is half full or some such, and double it again because of GC (that sounds bad), and we get ~48GB. However, we're may be a factor of 4-8 off from raw data size.

We should look into what's going on here again, and do one (or more) of the following:

  • Fix what we can
  • Test other comparable systems
  • Publish data relative to other systems to assuage user fears (or instill fears into our own hearts)

Mildly related to #1831.

Activity

  1. added this to the subsequent milestone on May 23, 2014
  2. coffeemug commented on May 23, 2014

    @coffeemug
    ContributorAuthor

    Diego -- out of curiosity, what disk space utilization do you get if you insert the same documents into MongoDB?

  3. diegogub commented on May 23, 2014

    @diegogub

    I have :

    db.raw_clicks.count()
    28423060

    dev@mongodb-0:/var/lib$ du -ch mongodb/
    3.2M mongodb/journal
    15G mongodb/
    15G total

    I run this command last night :
    nohup rethinkdb import -c localhost:28015 --table pampa.raw_clicks -f qu_pap_rawclicksBK20140522.json --format json --force

    When I woke up, my dev server was with disk usage 100%. I run Digital Ocean 8GB instance.

    Regards

    Diego

  4. coffeemug commented on May 23, 2014

    @coffeemug
    ContributorAuthor

    So it's 48GB in RethinkDB vs 15GB in MongoDB for exact same dataset (a factor of 3)?

  5. diegogub commented on May 23, 2014

    @diegogub

    Yup, I think so. I was confident that would not happen, I was more worried about RAM for example.
    I can give you another example. I have just imported the same data into another DB that I'm testing: ArangoDB. and It usage is 6.7 GB.

  6. mlucy commented on May 23, 2014

    @mlucy
    Member

    @danielmewes -- I have a vague memory that we store documents < 256 bytes efficiently, but that between 256 bytes and 4096 bytes we use a full 4096. Is that still (or was it ever) true?

    If so, that last piece of click data looks like it serializes to just over 256 bytes. If some of the click objects are taking up 4k instead of 256b, that would explain the high disk usage.

  7. coffeemug commented on May 23, 2014

    @coffeemug
    ContributorAuthor

    Is that still (or was it ever) true?

    @mlucy -- At one point that was true but it's no longer the case. @srh made a number of changes and we're now at 512b chunks rather than 4096b. So, if the document is > 256 bytes (ignoring metadata and such), it will take 512b of disk space.

    @diegogub -- we'll investigate and make improvements (there are lots of things we can do), but unfortunately we can't do very much in the short term. If disk space utilization is important, you'd probably be better off with a different database. We do hope you come back and give RethinkDB a try again in a few months!

  8. danielmewes commented on May 23, 2014

    @danielmewes
    Member

    @diegogub Thank you for the report.
    An additional question: I saw that you used --force in the import command. Did you import into tables that were already existing?
    Had those tables been used before? If yes, have there previously been secondary indexes on those tables that you had since deleted?

    There is a known leak of disk space when deleting a secondary index (the space isn't freed). If you later re-create the same index, you'll end up with twice the space usage for the index.

    That being said, I've seen higher than expected space usage before. We'll definitely investigate it and can hopefully implement some improvements soon (though as @coffeemug says it will likely take a few months).

  9. diegogub commented on May 23, 2014

    @diegogub

    @danielmewes No, it was a new tables created for the migration. It was never used before. Thank you for your fast replies. I was considering rethinkDB mostly because easy replication and sharding. So anyway, I will evaluate if I can deal with a limited number of records per batch. And maybe start pre aggregating my data in smaller chunks and delete processed documents.

  10. wojons commented on May 26, 2014

    @wojons
    Contributor

    Just to drop my two cents i think the best way to look into this will be to run rethinkdb in nodirecio and then run strace dtrace or your favorte tool and see how large it says the writes its commiting to disk.

  11. avolochenko commented on May 29, 2014

    @avolochenko

    Having similar issue my sample document is:
    {"url":"http://someurl","status":"some_status"}
    which is average of 120bytes on disk, with 25million documents inserted my RethinkDb table is ~17GB , vs ~2.4GB on disk

  12. coffeemug commented on May 29, 2014

    @coffeemug
    ContributorAuthor

    Marking as high priority.

  13. danielmewes commented on May 29, 2014

    @danielmewes
    Member

    @diegogub I have one more question about your data: Is one of the fields in your documents the primary key or do you use auto-generated primary keys (i.e. did you specify a primary key different than id when creating the table)?

  14. danielmewes commented on May 29, 2014

    @danielmewes
    Member

    One problem is that the garbage collector doesn't keep up when inserting data as fast as possible:

    Excerpt from ajax/stat:

    "serializer_bytes_in_use": "1286602752"
    "serializer_old_garbage_block_bytes": "1020678144"
    

    That means that from the 1.2 GB data file, 973 MB are garbage.

    In this experiment, I had inserted a little more than 1 million documents of approximately 100 bytes each, resulting in a raw data size of roughly 100 MB.

  15. 20 remaining items

  16. coffeemug commented on Jun 5, 2014

    @coffeemug
    ContributorAuthor

    This used to be configurable via command line. Did we take that out?

    BTW, I think a ratio is a bad way to expose this because:

    • Everyone was always confused what the numerator and denominator were
    • The ratio becomes less useful as the amount of data in the file grows (because the insert speed stays constant)

    I think that if we expose this, we should expose a flat number in megabytes. That sounds much easier to understand (and more useful).

  17. danielmewes commented on Jun 5, 2014

    @danielmewes
    Member

    @coffeemug An absolute number would be tricky, because GC becomes incredibly inefficient if the absolute number is too small compared to the table size.

    What could work is to keep a fixed minimal garbage ratio internally, but allow the user to additionally specify an "acceptable amount of garbage" in absolute terms.
    We would take the maximum of both to determine whether to increase the GC's aggressiveness.

    Does that sound reasonable?

  18. coffeemug commented on Jun 5, 2014

    @coffeemug
    ContributorAuthor

    After thinking about this more, I don't really like either idea (I mean exposing anything about gc to the user in general). This sort of config option opens up a certain class of questions -- what should I set it to? what's a reasonable value here? why do I have to set this? etc. I think it's best not to expose anything at all, and pick a value we know to be reasonable. @danielmewes -- what do you think?

  19. danielmewes commented on Jun 5, 2014

    @danielmewes
    Member

    I think the expected behavior is to have tables not use excessive amounts of disk space, and that should work reliably on both SSDs and rotational drives.

    I will run some more experiments and see what impact the goal garbage rate actually has on performance. If it turns out that GC becomes a lot more efficient if we allow for a slightly higher garbage rate, I think it would be worth having it configurable (or some related parameter).
    We shouldn't be afraid of explaining how RethinkDB and its parameters work. We would make sure that "the reasonable value" would be the default, unless disk space is of little concern for a user.

  20. danielmewes commented on Jun 6, 2014

    @danielmewes
    Member

    More effective garbage collection is in next as of 67e772c and will ship with 1.13.

    Let's track the remaining part, improving the shrinking mechanism for table files, in #1830.

  21. danielmewes commented on Jun 7, 2014

    @danielmewes
    Member

    More experiments:

    Large documents
    On rotational drives, I repeated the insert 1M documents experiment, but this time with documents of ~1 KB size each.

    On v1.12.x, inserting those documents took 4m 5s, and the table size at the end was 5.6 GB.
    On daniel_concurrent_gc it took 14m 30s, with a table size of 1.6 GB at the end.

    That slow-down seems a bit extreme.

    Increasing the GC_HIGH_RATIO
    Increasing what's internally called the GC_HIGH_RATIO from 0.3 to 0.45 has the following effect:
    In the large value experiment, inserting 1M values now takes 10m 55s. The file size increases only marginally to 1.7 GB. Still significantly slower than in v1.12.x, but a much better compromise.

    With 1M small documents as before, the changes are as follows:
    On rotational disks, inserting 1M documents takes 6m 24s down from 8m 20s. The file size is now 504 MB instead of 400 MB.
    On SSD, the insert time is 52s. The file size is 442 MB (vs. 58s / 400 MB).

    I'm going to change the GC_HIGH_RATIO to 0.45 or even 0.5. That seems to provide the better overall compromise between small files and performance.

  22. danielmewes commented on Jun 7, 2014

    @danielmewes
    Member

    Changed GC_HIGH_RATIO in CR 1605 by @Tryneus

  23. modified the milestones: 1.13, on Jun 7, 2014
  24. danielmewes commented on Jun 7, 2014

    @danielmewes
    Member

    Parameter changed in next 4496039

  25. modified the milestones: , 1.13 on Jun 7, 2014
  26. modified the milestones: 1.13, on Jun 9, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions